@@ -, +, @@ --- Koha/{Cron.pm => Script.pm} | 47 +++++++++++++----- misc/admin/koha-preferences | 1 + misc/batchCompareMARCvsFrameworks.pl | 1 + misc/batchDeleteUnusedSubfields.pl | 1 + misc/batchImportMARCWithBiblionumbers.pl | 1 + misc/batchRebuildBiblioTables.pl | 1 + misc/batchRebuildItemsTables.pl | 1 + misc/batchRepairMissingBiblionumbers.pl | 2 +- misc/batchdeletebiblios.pl | 1 + misc/check_sysprefs.pl | 1 + misc/commit_file.pl | 1 + misc/cronjobs/advance_notices.pl | 2 +- .../automatic_item_modification_by_age.pl | 2 +- misc/cronjobs/automatic_renewals.pl | 2 +- misc/cronjobs/batch_anonymise.pl | 2 +- misc/cronjobs/build_browser_and_cloud.pl | 2 +- misc/cronjobs/cart_to_shelf.pl | 2 +- misc/cronjobs/check-url-quick.pl | 2 +- misc/cronjobs/check-url.pl | 4 +- misc/cronjobs/cleanup_database.pl | 2 +- misc/cronjobs/cloud-kw.pl | 2 +- misc/cronjobs/create_koc_db.pl | 2 +- .../delete_expired_opac_registrations.pl | 2 +- misc/cronjobs/delete_items.pl | 2 +- misc/cronjobs/delete_patrons.pl | 2 +- misc/cronjobs/delete_records_via_leader.pl | 2 +- misc/cronjobs/edi_cron.pl | 2 +- misc/cronjobs/fines.pl | 2 +- misc/cronjobs/gather_print_notices.pl | 2 +- misc/cronjobs/holds/auto_unsuspend_holds.pl | 2 +- misc/cronjobs/holds/build_holds_queue.pl | 2 +- misc/cronjobs/holds/cancel_expired_holds.pl | 2 +- misc/cronjobs/holds/cancel_unfilled_holds.pl | 2 +- misc/cronjobs/import_webservice_batch.pl | 2 +- misc/cronjobs/j2a.pl | 2 +- misc/cronjobs/longoverdue.pl | 2 +- misc/cronjobs/membership_expiry.pl | 2 +- misc/cronjobs/merge_authorities.pl | 2 +- .../notice_unprocessed_suggestions.pl | 2 +- misc/cronjobs/overdue_notices.pl | 2 +- misc/cronjobs/process_message_queue.pl | 2 +- misc/cronjobs/purge_suggestions.pl | 2 +- misc/cronjobs/reconcile_balances.pl | 2 +- misc/cronjobs/remove_temporary_edifiles.pl | 2 +- misc/cronjobs/rss/rss.pl | 2 +- misc/cronjobs/runreport.pl | 2 +- misc/cronjobs/serialsUpdate.pl | 2 +- .../share_usage_with_koha_community.pl | 2 +- misc/cronjobs/sitemap.pl | 2 +- .../social_data/get_report_social_data.pl | 2 +- .../social_data/update_social_data.pl | 2 +- misc/cronjobs/staticfines.pl | 2 +- misc/cronjobs/stockrotation.pl | 2 +- .../thirdparty/TalkingTech_itiva_inbound.pl | 2 +- .../thirdparty/TalkingTech_itiva_outbound.pl | 2 +- misc/cronjobs/update_totalissues.pl | 2 +- misc/devel/create_superlibrarian.pl | 1 + misc/devel/populate_db.pl | 1 + misc/export_borrowers.pl | 1 + misc/export_records.pl | 1 + misc/exportauth.pl | 1 + misc/import_patrons.pl | 1 + misc/link_bibs_to_authorities.pl | 1 + .../UNIMARC_fix_collectiontitle.pl | 1 + ...MARC_sync_date_created_with_marc_biblio.pl | 1 + misc/maintenance/auth_show_hidden_data.pl | 1 + .../borrowers-force-messaging-defaults.pl | 1 + misc/maintenance/cmp_sysprefs.pl | 1 + misc/maintenance/fix_accountlines_date.pl | 1 + .../fix_accountlines_rmdupfines_bug8253.pl | 1 + misc/maintenance/fix_mysql_constraints.pl | 1 + misc/maintenance/fix_tags_weight.pl | 1 + .../make_zebra_dom_cfg_from_record_abs | 1 + .../process_record_through_filter.pl | 2 + .../remove_items_from_biblioitems.pl | 1 + misc/maintenance/sanitize_records.pl | 2 + .../search_for_data_inconsistencies.pl | 1 + misc/maintenance/touch_all_biblios.pl | 2 + misc/maintenance/touch_all_items.pl | 2 + misc/maintenance/update_authorities.pl | 1 + misc/migration_tools/buildCOUNTRY.pl | 1 + misc/migration_tools/buildEDITORS.pl | 1 + misc/migration_tools/buildLANG.pl | 1 + misc/migration_tools/build_oai_sets.pl | 1 + misc/migration_tools/bulkmarcimport.pl | 1 + .../migration_tools/checkNonIndexedBiblios.pl | 1 + misc/migration_tools/create_analytical_rel.pl | 1 + misc/migration_tools/fix_onloan.pl | 4 +- misc/migration_tools/import_lexile.pl | 1 + misc/migration_tools/rebuild_zebra.pl | 1 + .../remove_unused_authorities.pl | 1 + .../switch_marc21_series_info.pl | 1 + misc/migration_tools/upgradeitems.pl | 4 +- misc/mod_zebraqueue.pl | 1 + misc/recreateIssueStatistics.pl | 2 + misc/search_tools/rebuild_elastic_search.pl | 1 + misc/stage_file.pl | 1 + t/Koha/Script.t | 48 +++++++++++++++++++ t/Koha/{Cron.t => Script_cron.t} | 6 +-- 99 files changed, 191 insertions(+), 65 deletions(-) rename Koha/{Cron.pm => Script.pm} (52%) create mode 100644 t/Koha/Script.t rename t/Koha/{Cron.t => Script_cron.t} (88%) --- a/Koha/Cron.pm +++ a/Koha/Cron.pm @@ -1,4 +1,4 @@ -package Koha::Cron; +package Koha::Script; # Copyright PTFS Europe 2019 # Copyright 2019 Koha Development Team @@ -22,29 +22,50 @@ use Modern::Perl; =head1 NAME -Koha::Cron - Koha Cron scripts base class +Koha::Script - Koha scripts base class =head1 SYNOPSIS - use Koha::Cron; + use Koha::Script + use Koha::Script -cron; =head1 DESCRIPTION -This class should be used in all cronscripts. It sets the interface and userenv appropriately. +This class should be used in all scripts. It sets the interface and userenv appropriately. =cut use C4::Context; -# Set userenv -C4::Context->_new_userenv(1); -C4::Context->set_userenv( - undef, undef, undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); - -# Set interface -C4::Context->interface('cron'); +sub import { + my $class = shift; + my @flags = @_; + + C4::Context->_new_userenv(1); + if ( ( $flags[0] || '' ) eq '-cron' ) { + + # Set userenv + C4::Context->_new_userenv(1); + C4::Context->set_userenv( + undef, undef, undef, 'CRON', 'CRON', undef, + undef, undef, undef, undef, undef + ); + + # Set interface + C4::Context->interface('cron'); + + } + else { + # Set userenv + C4::Context->set_userenv( + undef, undef, undef, 'CLI', 'CLI', undef, + undef, undef, undef, undef, undef + ); + + # Set interface + C4::Context->interface('commandline'); + } +} =head1 AUTHOR --- a/misc/admin/koha-preferences +++ a/misc/admin/koha-preferences @@ -18,6 +18,7 @@ # along with Koha; if not, see . # +use Koha::Script; use C4::Boolean; use C4::Context; use C4::Debug; --- a/misc/batchCompareMARCvsFrameworks.pl +++ a/misc/batchCompareMARCvsFrameworks.pl @@ -12,6 +12,7 @@ BEGIN { } # Koha modules used +use Koha::Script; use C4::Context; use MARC::File::USMARC; use MARC::Record; --- a/misc/batchDeleteUnusedSubfields.pl +++ a/misc/batchDeleteUnusedSubfields.pl @@ -11,6 +11,7 @@ BEGIN { } # Koha modules used +use Koha::Script; use MARC::Record; use C4::Context; use C4::Biblio; --- a/misc/batchImportMARCWithBiblionumbers.pl +++ a/misc/batchImportMARCWithBiblionumbers.pl @@ -12,6 +12,7 @@ BEGIN { # Koha modules used +use Koha::Script; use C4::Context; use C4::Biblio; use MARC::Record; --- a/misc/batchRebuildBiblioTables.pl +++ a/misc/batchRebuildBiblioTables.pl @@ -13,6 +13,7 @@ BEGIN { } # Koha modules used +use Koha::Script; use MARC::Record; use C4::Context; use C4::Biblio; --- a/misc/batchRebuildItemsTables.pl +++ a/misc/batchRebuildItemsTables.pl @@ -8,6 +8,7 @@ use MARC::Record; use Pod::Usage; use Time::HiRes qw(gettimeofday); +use Koha::Script; use C4::Context; use C4::Biblio; use C4::Items; --- a/misc/batchRepairMissingBiblionumbers.pl +++ a/misc/batchRepairMissingBiblionumbers.pl @@ -12,7 +12,7 @@ BEGIN { } # Koha modules used - +use Koha::Script; use C4::Context; use C4::Biblio; --- a/misc/batchdeletebiblios.pl +++ a/misc/batchdeletebiblios.pl @@ -5,6 +5,7 @@ use Getopt::Long; use Pod::Usage; use IO::File; +use Koha::Script; use C4::Biblio; my ($help, $files); --- a/misc/check_sysprefs.pl +++ a/misc/check_sysprefs.pl @@ -10,6 +10,7 @@ use warnings; use File::Find; +use Koha::Script; use C4::Context; @ARGV = qw(.) unless @ARGV; --- a/misc/commit_file.pl +++ a/misc/commit_file.pl @@ -9,6 +9,7 @@ BEGIN { eval { require "$FindBin::Bin/kohalib.pl" }; } +use Koha::Script; use C4::Context; use C4::ImportBatch; use Getopt::Long; --- a/misc/cronjobs/advance_notices.pl +++ a/misc/cronjobs/advance_notices.pl @@ -49,7 +49,7 @@ BEGIN { use FindBin; eval { require "$FindBin::Bin/../kohalib.pl" }; } -use Koha::Cron; +use Koha::Script -cron; use C4::Biblio; use C4::Context; use C4::Letters; --- a/misc/cronjobs/automatic_item_modification_by_age.pl +++ a/misc/cronjobs/automatic_item_modification_by_age.pl @@ -6,7 +6,7 @@ use Getopt::Long; use Pod::Usage; use JSON; -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use C4::Items; --- a/misc/cronjobs/automatic_renewals.pl +++ a/misc/cronjobs/automatic_renewals.pl @@ -52,7 +52,7 @@ use Modern::Perl; use Pod::Usage; use Getopt::Long; -use Koha::Cron; +use Koha::Script -cron; use C4::Circulation; use C4::Context; use C4::Log; --- a/misc/cronjobs/batch_anonymise.pl +++ a/misc/cronjobs/batch_anonymise.pl @@ -29,7 +29,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use Koha::Patrons; use Date::Calc qw( --- a/misc/cronjobs/build_browser_and_cloud.pl +++ a/misc/cronjobs/build_browser_and_cloud.pl @@ -10,7 +10,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } -use Koha::Cron; +use Koha::Script -cron; use C4::Koha; use C4::Context; use C4::Biblio; --- a/misc/cronjobs/cart_to_shelf.pl +++ a/misc/cronjobs/cart_to_shelf.pl @@ -28,7 +28,7 @@ cart_to_shelf.pl cron script to set items with location of CART to original she use strict; use warnings; -use Koha::Cron; +use Koha::Script -cron; use C4::Items qw/ CartToShelf /; use C4::Log; --- a/misc/cronjobs/check-url-quick.pl +++ a/misc/cronjobs/check-url-quick.pl @@ -21,7 +21,7 @@ use Modern::Perl; use Pod::Usage; use Getopt::Long; -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use C4::Biblio; use AnyEvent; --- a/misc/cronjobs/check-url.pl +++ a/misc/cronjobs/check-url.pl @@ -78,7 +78,7 @@ use strict; use warnings; use LWP::UserAgent; use HTTP::Request; -use Koha::Cron; +use Koha::Script -cron; use C4::Biblio; @@ -148,7 +148,7 @@ use Carp; use Pod::Usage; use Getopt::Long; -use Koha::Cron; +use Koha::Script -cron; use C4::Context; --- a/misc/cronjobs/cleanup_database.pl +++ a/misc/cronjobs/cleanup_database.pl @@ -34,7 +34,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use C4::Search; use C4::Search::History; --- a/misc/cronjobs/cloud-kw.pl +++ a/misc/cronjobs/cloud-kw.pl @@ -26,7 +26,7 @@ use YAML::Syck; use Pod::Usage; use Getopt::Long; -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use C4::Log; --- a/misc/cronjobs/create_koc_db.pl +++ a/misc/cronjobs/create_koc_db.pl @@ -95,7 +95,7 @@ use DBI; use Getopt::Long; use Pod::Usage; -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use English qw(-no_match_vars); --- a/misc/cronjobs/delete_expired_opac_registrations.pl +++ a/misc/cronjobs/delete_expired_opac_registrations.pl @@ -28,7 +28,7 @@ BEGIN { eval { my $lib = "$FindBin::Bin/../kohalib.pl"; require $lib }; } -use Koha::Cron; +use Koha::Script -cron; use C4::Context; my $help; --- a/misc/cronjobs/delete_items.pl +++ a/misc/cronjobs/delete_items.pl @@ -2,7 +2,7 @@ use Getopt::Long; -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use C4::Items; use C4::Circulation; --- a/misc/cronjobs/delete_patrons.pl +++ a/misc/cronjobs/delete_patrons.pl @@ -5,7 +5,7 @@ use Modern::Perl; use Pod::Usage; use Getopt::Long; -use Koha::Cron; +use Koha::Script -cron; use C4::Members; use Koha::DateUtils; use Koha::Patrons; --- a/misc/cronjobs/delete_records_via_leader.pl +++ a/misc/cronjobs/delete_records_via_leader.pl @@ -33,7 +33,7 @@ BEGIN { use Getopt::Long; use Pod::Usage; -use Koha::Cron; +use Koha::Script -cron; use C4::Biblio; use C4::Items; use Koha::Database; --- a/misc/cronjobs/edi_cron.pl +++ a/misc/cronjobs/edi_cron.pl @@ -29,7 +29,7 @@ use utf8; # can be run as frequently as required # log messages are appended to logdir/editrace.log -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use Log::Log4perl qw(:easy); use Koha::Database; --- a/misc/cronjobs/fines.pl +++ a/misc/cronjobs/fines.pl @@ -30,7 +30,7 @@ use strict; use warnings; use 5.010; -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use C4::Overdues; use Getopt::Long; --- a/misc/cronjobs/gather_print_notices.pl +++ a/misc/cronjobs/gather_print_notices.pl @@ -10,7 +10,7 @@ BEGIN { } use CGI qw( utf8 ); # NOT a CGI script, this is just to keep C4::Templates::gettemplate happy -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use C4::Debug; use C4::Letters; --- a/misc/cronjobs/holds/auto_unsuspend_holds.pl +++ a/misc/cronjobs/holds/auto_unsuspend_holds.pl @@ -29,7 +29,7 @@ BEGIN { # cancel all expired hold requests -use Koha::Cron; +use Koha::Script -cron; use C4::Reserves; use C4::Log; --- a/misc/cronjobs/holds/build_holds_queue.pl +++ a/misc/cronjobs/holds/build_holds_queue.pl @@ -15,7 +15,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } -use Koha::Cron; +use Koha::Script -cron; use C4::HoldsQueue qw(CreateQueue); use C4::Log; --- a/misc/cronjobs/holds/cancel_expired_holds.pl +++ a/misc/cronjobs/holds/cancel_expired_holds.pl @@ -29,7 +29,7 @@ BEGIN { # cancel all expired hold requests -use Koha::Cron; +use Koha::Script -cron; use C4::Reserves; use C4::Log; --- a/misc/cronjobs/holds/cancel_unfilled_holds.pl +++ a/misc/cronjobs/holds/cancel_unfilled_holds.pl @@ -28,7 +28,7 @@ BEGIN { use Getopt::Long; use Pod::Usage; -use Koha::Cron; +use Koha::Script -cron; use C4::Reserves; use C4::Log; use Koha::Holds; --- a/misc/cronjobs/import_webservice_batch.pl +++ a/misc/cronjobs/import_webservice_batch.pl @@ -31,7 +31,7 @@ BEGIN { use Getopt::Long; use Pod::Usage; -use Koha::Cron; +use Koha::Script -cron; use C4::ImportBatch; my ($help, $framework); --- a/misc/cronjobs/j2a.pl +++ a/misc/cronjobs/j2a.pl @@ -26,7 +26,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use C4::Members; use Getopt::Long; --- a/misc/cronjobs/longoverdue.pl +++ a/misc/cronjobs/longoverdue.pl @@ -34,7 +34,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use C4::Items; use C4::Circulation qw/LostItem MarkIssueReturned/; --- a/misc/cronjobs/membership_expiry.pl +++ a/misc/cronjobs/membership_expiry.pl @@ -126,7 +126,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use C4::Letters; use C4::Log; --- a/misc/cronjobs/merge_authorities.pl +++ a/misc/cronjobs/merge_authorities.pl @@ -5,7 +5,7 @@ use Getopt::Long; use Pod::Usage; use Time::HiRes qw(gettimeofday); -use Koha::Cron; +use Koha::Script -cron; use C4::AuthoritiesMarc; use Koha::Authority::MergeRequests; --- a/misc/cronjobs/notice_unprocessed_suggestions.pl +++ a/misc/cronjobs/notice_unprocessed_suggestions.pl @@ -5,7 +5,7 @@ use Modern::Perl; use Pod::Usage; use Getopt::Long; -use Koha::Cron; +use Koha::Script -cron; use C4::Budgets qw( GetBudget ); use C4::Suggestions qw( GetUnprocessedSuggestions ); use Koha::Libraries; --- a/misc/cronjobs/overdue_notices.pl +++ a/misc/cronjobs/overdue_notices.pl @@ -34,7 +34,7 @@ use Text::CSV_XS; use DateTime; use DateTime::Duration; -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use C4::Letters; use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes parse_overdues_letter); --- a/misc/cronjobs/process_message_queue.pl +++ a/misc/cronjobs/process_message_queue.pl @@ -26,7 +26,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } -use Koha::Cron; +use Koha::Script -cron; use C4::Letters; use C4::Log; use Getopt::Long; --- a/misc/cronjobs/purge_suggestions.pl +++ a/misc/cronjobs/purge_suggestions.pl @@ -29,7 +29,7 @@ BEGIN { use Getopt::Long; use Pod::Usage; -use Koha::Cron; +use Koha::Script -cron; use C4::Suggestions; use C4::Log; use C4::Context; --- a/misc/cronjobs/reconcile_balances.pl +++ a/misc/cronjobs/reconcile_balances.pl @@ -62,7 +62,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } -use Koha::Cron; +use Koha::Script -cron; use C4::Log; use Koha::Account::Lines; --- a/misc/cronjobs/remove_temporary_edifiles.pl +++ a/misc/cronjobs/remove_temporary_edifiles.pl @@ -2,7 +2,7 @@ use strict; use warnings; -use Koha::Cron; +use Koha::Script -cron; use C4::Context; # this script will remove those older than 5 days --- a/misc/cronjobs/rss/rss.pl +++ a/misc/cronjobs/rss/rss.pl @@ -29,7 +29,7 @@ use Modern::Perl; use Template; -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use Time::Local; use POSIX; --- a/misc/cronjobs/runreport.pl +++ a/misc/cronjobs/runreport.pl @@ -20,7 +20,7 @@ use Modern::Perl; -use Koha::Cron; +use Koha::Script -cron; use C4::Reports::Guided; # 0.12 use Koha::Reports; use C4::Context; --- a/misc/cronjobs/serialsUpdate.pl +++ a/misc/cronjobs/serialsUpdate.pl @@ -28,7 +28,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use C4::Debug; use C4::Serials; --- a/misc/cronjobs/share_usage_with_koha_community.pl +++ a/misc/cronjobs/share_usage_with_koha_community.pl @@ -5,7 +5,7 @@ use Modern::Perl; use Pod::Usage; use Getopt::Long; -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use C4::UsageStats; use C4::Log; --- a/misc/cronjobs/sitemap.pl +++ a/misc/cronjobs/sitemap.pl @@ -24,7 +24,7 @@ use utf8; use Pod::Usage; use Getopt::Long; -use Koha::Cron; +use Koha::Script -cron; use C4::Biblio; use Koha::Sitemapper; --- a/misc/cronjobs/social_data/get_report_social_data.pl +++ a/misc/cronjobs/social_data/get_report_social_data.pl @@ -2,7 +2,7 @@ use Modern::Perl; -use Koha::Cron; +use Koha::Script -cron; use C4::SocialData; my $results = C4::SocialData::get_report; --- a/misc/cronjobs/social_data/update_social_data.pl +++ a/misc/cronjobs/social_data/update_social_data.pl @@ -2,7 +2,7 @@ use Modern::Perl; -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use C4::SocialData; --- a/misc/cronjobs/staticfines.pl +++ a/misc/cronjobs/staticfines.pl @@ -37,7 +37,7 @@ BEGIN { use Date::Calc qw/Date_to_Days/; -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use C4::Circulation; use C4::Overdues; --- a/misc/cronjobs/stockrotation.pl +++ a/misc/cronjobs/stockrotation.pl @@ -110,7 +110,7 @@ database updates have been performed."). use Modern::Perl; use Getopt::Long qw/HelpMessage :config gnu_getopt/; -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use C4::Letters; use Koha::StockRotationRotas; --- a/misc/cronjobs/thirdparty/TalkingTech_itiva_inbound.pl +++ a/misc/cronjobs/thirdparty/TalkingTech_itiva_inbound.pl @@ -31,7 +31,7 @@ BEGIN { use Getopt::Long; use Pod::Usage; -use Koha::Cron; +use Koha::Script -cron; use C4::Context; sub usage { --- a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl +++ a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl @@ -31,7 +31,7 @@ BEGIN { use Getopt::Long; use Pod::Usage; -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use C4::Items; use C4::Letters; --- a/misc/cronjobs/update_totalissues.pl +++ a/misc/cronjobs/update_totalissues.pl @@ -31,7 +31,7 @@ BEGIN { use Getopt::Long; use Pod::Usage; -use Koha::Cron; +use Koha::Script -cron; use C4::Context; use C4::Biblio; use C4::Log; --- a/misc/devel/create_superlibrarian.pl +++ a/misc/devel/create_superlibrarian.pl @@ -21,6 +21,7 @@ use Modern::Perl; use Getopt::Long; use Pod::Usage; +use Koha::Script; use Koha::Patrons; my ( $help, $surname, $userid, $password, $branchcode, $categorycode, $cardnumber ); --- a/misc/devel/populate_db.pl +++ a/misc/devel/populate_db.pl @@ -22,6 +22,7 @@ use Modern::Perl; use Getopt::Long; use Pod::Usage; +use Koha::Script; use C4::Installer; use C4::Context; --- a/misc/export_borrowers.pl +++ a/misc/export_borrowers.pl @@ -23,6 +23,7 @@ use Modern::Perl; use Text::CSV; use Getopt::Long qw(:config no_ignore_case); +use Koha::Script; use C4::Context; use Koha::Patrons; --- a/misc/export_records.pl +++ a/misc/export_records.pl @@ -22,6 +22,7 @@ use List::MoreUtils qw(uniq); use Getopt::Long; use Pod::Usage; +use Koha::Script; use C4::Auth; use C4::Context; use C4::Record; --- a/misc/exportauth.pl +++ a/misc/exportauth.pl @@ -12,6 +12,7 @@ BEGIN { eval { require "$FindBin::Bin/kohalib.pl" }; } +use Koha::Script; use C4::Context; use C4::Biblio; use C4::Auth; --- a/misc/import_patrons.pl +++ a/misc/import_patrons.pl @@ -22,6 +22,7 @@ use Modern::Perl; use Getopt::Long; use Pod::Usage; +use Koha::Script; use Koha::Patrons::Import; my $Import = Koha::Patrons::Import->new(); --- a/misc/link_bibs_to_authorities.pl +++ a/misc/link_bibs_to_authorities.pl @@ -11,6 +11,7 @@ BEGIN { eval { require "$FindBin::Bin/kohalib.pl" }; } +use Koha::Script; use C4::Context; use C4::Biblio; use Getopt::Long; --- a/misc/maintenance/UNIMARC_fix_collectiontitle.pl +++ a/misc/maintenance/UNIMARC_fix_collectiontitle.pl @@ -12,6 +12,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } +use Koha::Script; use C4::Biblio; sub process { --- a/misc/maintenance/UNIMARC_sync_date_created_with_marc_biblio.pl +++ a/misc/maintenance/UNIMARC_sync_date_created_with_marc_biblio.pl @@ -12,6 +12,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } +use Koha::Script; use C4::Biblio; use Getopt::Long; --- a/misc/maintenance/auth_show_hidden_data.pl +++ a/misc/maintenance/auth_show_hidden_data.pl @@ -25,6 +25,7 @@ use Modern::Perl; use Getopt::Long; use Pod::Usage; +use Koha::Script; use Koha::Authorities; use Koha::Authority::Subfields; use Koha::MetadataRecord::Authority; --- a/misc/maintenance/borrowers-force-messaging-defaults.pl +++ a/misc/maintenance/borrowers-force-messaging-defaults.pl @@ -26,6 +26,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } +use Koha::Script; use C4::Context; use C4::Members::Messaging; use Getopt::Long; --- a/misc/maintenance/cmp_sysprefs.pl +++ a/misc/maintenance/cmp_sysprefs.pl @@ -30,6 +30,7 @@ use open OUT => ':encoding(UTF-8)', ':std'; use Getopt::Long; use Pod::Usage; +use Koha::Script; use C4::Context; my $dbh = C4::Context->dbh; --- a/misc/maintenance/fix_accountlines_date.pl +++ a/misc/maintenance/fix_accountlines_date.pl @@ -26,6 +26,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } +use Koha::Script; use C4::Context; use Getopt::Long; use Pod::Usage; --- a/misc/maintenance/fix_accountlines_rmdupfines_bug8253.pl +++ a/misc/maintenance/fix_accountlines_rmdupfines_bug8253.pl @@ -27,6 +27,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } +use Koha::Script; use C4::Context; use C4::Installer; --- a/misc/maintenance/fix_mysql_constraints.pl +++ a/misc/maintenance/fix_mysql_constraints.pl @@ -30,6 +30,7 @@ use Getopt::Long; use Pod::Usage; use YAML; use Try::Tiny; +use Koha::Script; use C4::Context; --- a/misc/maintenance/fix_tags_weight.pl +++ a/misc/maintenance/fix_tags_weight.pl @@ -22,6 +22,7 @@ use Modern::Perl; use C4::Context; use C4::Tags; +use Koha::Script; use Koha::Database; use Koha::Tags; use Koha::Tags::Approvals; --- a/misc/maintenance/make_zebra_dom_cfg_from_record_abs +++ a/misc/maintenance/make_zebra_dom_cfg_from_record_abs @@ -20,6 +20,7 @@ use strict; use warnings; use 5.010; +use Koha::Script; use Koha::Indexer::Utils; use Getopt::Long; --- a/misc/maintenance/process_record_through_filter.pl +++ a/misc/maintenance/process_record_through_filter.pl @@ -6,6 +6,8 @@ use strict; use warnings; + +use Koha::Script; use Koha::RecordProcessor; use Data::Dumper; use C4::Biblio; --- a/misc/maintenance/remove_items_from_biblioitems.pl +++ a/misc/maintenance/remove_items_from_biblioitems.pl @@ -22,6 +22,7 @@ use strict; use warnings; $|=1; +use Koha::Script; use C4::Context; use C4::Biblio; use Getopt::Long; --- a/misc/maintenance/sanitize_records.pl +++ a/misc/maintenance/sanitize_records.pl @@ -18,6 +18,8 @@ # along with Koha; if not, see . use Modern::Perl; + +use Koha::Script; use C4::Charset qw( SanitizeRecord ); use C4::Context; use DBI; --- a/misc/maintenance/search_for_data_inconsistencies.pl +++ a/misc/maintenance/search_for_data_inconsistencies.pl @@ -17,6 +17,7 @@ use Modern::Perl; +use Koha::Script; use Koha::Items; use Koha::Biblioitems; use Koha::ItemTypes; --- a/misc/maintenance/touch_all_biblios.pl +++ a/misc/maintenance/touch_all_biblios.pl @@ -28,6 +28,8 @@ BEGIN { # possible modules to use use Getopt::Long; + +use Koha::Script; use C4::Context; use C4::Biblio; use Pod::Usage; --- a/misc/maintenance/touch_all_items.pl +++ a/misc/maintenance/touch_all_items.pl @@ -28,6 +28,8 @@ BEGIN { # possible modules to use use Getopt::Long; + +use Koha::Script; use C4::Context; use C4::Items; use Pod::Usage; --- a/misc/maintenance/update_authorities.pl +++ a/misc/maintenance/update_authorities.pl @@ -23,6 +23,7 @@ use Getopt::Long; use List::MoreUtils qw/uniq/; use Pod::Usage; +use Koha::Script; use C4::AuthoritiesMarc qw/AddAuthority DelAuthority GetAuthority merge/; my ( @authid, $confirm, $delete, $help, $merge, $reference, $renumber, $verbose ); --- a/misc/migration_tools/buildCOUNTRY.pl +++ a/misc/migration_tools/buildCOUNTRY.pl @@ -6,6 +6,7 @@ use strict; #use warnings; FIXME - Bug 2505 # Koha modules used +use Koha::Script; use C4::Context; use C4::Biblio; use C4::AuthoritiesMarc; --- a/misc/migration_tools/buildEDITORS.pl +++ a/misc/migration_tools/buildEDITORS.pl @@ -8,6 +8,7 @@ use strict; use MARC::File::USMARC; use MARC::Record; use MARC::Batch; +use Koha::Script; use C4::Context; use C4::Biblio; use C4::AuthoritiesMarc; --- a/misc/migration_tools/buildLANG.pl +++ a/misc/migration_tools/buildLANG.pl @@ -6,6 +6,7 @@ use strict; #use warnings; FIXME - Bug 2505 # Koha modules used +use Koha::Script; use C4::Context; use C4::Biblio; use C4::AuthoritiesMarc; --- a/misc/migration_tools/build_oai_sets.pl +++ a/misc/migration_tools/build_oai_sets.pl @@ -42,6 +42,7 @@ use MARC::File::XML; use List::MoreUtils qw/uniq/; use Getopt::Std; +use Koha::Script; use C4::Context; use C4::Charset qw/StripNonXmlChars/; use C4::Biblio; --- a/misc/migration_tools/bulkmarcimport.pl +++ a/misc/migration_tools/bulkmarcimport.pl @@ -17,6 +17,7 @@ use MARC::Record; use MARC::Batch; use MARC::Charset; +use Koha::Script; use C4::Context; use C4::Biblio; use C4::Koha; --- a/misc/migration_tools/checkNonIndexedBiblios.pl +++ a/misc/migration_tools/checkNonIndexedBiblios.pl @@ -33,6 +33,7 @@ BEGIN { # Koha modules used use MARC::Record; +use Koha::Script; use C4::Context; use Getopt::Long; --- a/misc/migration_tools/create_analytical_rel.pl +++ a/misc/migration_tools/create_analytical_rel.pl @@ -9,6 +9,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } +use Koha::Script; use C4::Context; use C4::Biblio; use C4::Items; --- a/misc/migration_tools/fix_onloan.pl +++ a/misc/migration_tools/fix_onloan.pl @@ -2,7 +2,9 @@ use strict; #use warnings; FIXME - Bug 2505 -use C4::Context; + +use Koha::Script; +use C4::Context; use C4::Items; use C4::Biblio; --- a/misc/migration_tools/import_lexile.pl +++ a/misc/migration_tools/import_lexile.pl @@ -31,6 +31,7 @@ use Modern::Perl; use Getopt::Long; use Text::CSV; +use Koha::Script; use C4::Context; use C4::Biblio; use C4::Koha qw( GetVariationsOfISBN ); --- a/misc/migration_tools/rebuild_zebra.pl +++ a/misc/migration_tools/rebuild_zebra.pl @@ -17,6 +17,7 @@ use Modern::Perl; +use Koha::Script; use C4::Context; use Getopt::Long; use Fcntl qw(:flock); --- a/misc/migration_tools/remove_unused_authorities.pl +++ a/misc/migration_tools/remove_unused_authorities.pl @@ -23,6 +23,7 @@ use strict; use warnings; +use Koha::Script; use C4::Context; use C4::AuthoritiesMarc; use Getopt::Long; --- a/misc/migration_tools/switch_marc21_series_info.pl +++ a/misc/migration_tools/switch_marc21_series_info.pl @@ -29,6 +29,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } +use Koha::Script; use C4::Biblio; use C4::Context; use Getopt::Long; --- a/misc/migration_tools/upgradeitems.pl +++ a/misc/migration_tools/upgradeitems.pl @@ -2,7 +2,9 @@ use strict; #use warnings; FIXME - Bug 2505 -use C4::Context; + +use Koha::Script; +use C4::Context; use C4::Items; use C4::Biblio; --- a/misc/mod_zebraqueue.pl +++ a/misc/mod_zebraqueue.pl @@ -23,6 +23,7 @@ use Modern::Perl; use Getopt::Long; use Pod::Usage; +use Koha::Script; use C4::Biblio; my @biblios; --- a/misc/recreateIssueStatistics.pl +++ a/misc/recreateIssueStatistics.pl @@ -22,6 +22,8 @@ use strict; use warnings; + +use Koha::Script; use C4::Context; use C4::Items; use Data::Dumper; --- a/misc/search_tools/rebuild_elastic_search.pl +++ a/misc/search_tools/rebuild_elastic_search.pl @@ -83,6 +83,7 @@ Full documentation. use autodie; use Getopt::Long; +use Koha::Script; use C4::Context; use Koha::MetadataRecord::Authority; use Koha::BiblioUtils; --- a/misc/stage_file.pl +++ a/misc/stage_file.pl @@ -27,6 +27,7 @@ BEGIN { eval { require "$FindBin::Bin/kohalib.pl" }; } +use Koha::Script; use C4::Context; use C4::ImportBatch; use C4::Matcher; --- a/t/Koha/Script.t +++ a/t/Koha/Script.t @@ -0,0 +1,48 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Test::More tests => 3; + +BEGIN { use_ok('Koha::Script') } + +use C4::Context; + +my $userenv = C4::Context->userenv; +is_deeply( + $userenv, + { + 'surname' => 'CLI', + 'id' => undef, + 'flags' => undef, + 'cardnumber' => undef, + 'firstname' => 'CLI', + 'branchname' => undef, + 'branchprinter' => undef, + 'emailaddress' => undef, + 'number' => undef, + 'shibboleth' => undef, + 'branch' => undef + }, + "Context userenv set correctly with no flags" +); + +my $interface = C4::Context->interface; +is( $interface, 'commandline', "Context interface set correctly with no flags" ); + +1; --- a/t/Koha/Cron.t +++ a/t/Koha/Cron.t @@ -19,7 +19,7 @@ use Modern::Perl; use Test::More tests => 3; -BEGIN { use_ok('Koha::Cron') } +BEGIN { use_ok( "Koha::Script", '-cron' ) } use C4::Context; @@ -39,10 +39,10 @@ is_deeply( 'shibboleth' => undef, 'branch' => undef }, - "Context userenv set correctly" + "Context userenv set correctly with -cron" ); my $interface = C4::Context->interface; -is($interface, 'cron', "Context interface set correctly"); +is( $interface, 'cron', "Context interface set correctly with -cron" ); 1; --