From ce1dcb1791ecfdbf2e2f000277186f8a25f3b24f Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 26 Mar 2019 12:38:40 +0000 Subject: [PATCH] Bug 22577: Less typing is good! --- Koha/Cron.pm | 16 ++++++++++++++++ misc/cronjobs/advance_notices.pl | 5 +---- .../automatic_item_modification_by_age.pl | 6 +----- misc/cronjobs/automatic_renewals.pl | 6 +----- misc/cronjobs/batch_anonymise.pl | 5 +---- misc/cronjobs/build_browser_and_cloud.pl | 5 +---- misc/cronjobs/cart_to_shelf.pl | 5 +---- misc/cronjobs/check-url-quick.pl | 7 ++----- misc/cronjobs/check-url.pl | 2 ++ misc/cronjobs/cleanup_database.pl | 5 +---- misc/cronjobs/cloud-kw.pl | 6 ++---- misc/cronjobs/create_koc_db.pl | 7 ++----- .../delete_expired_opac_registrations.pl | 1 + misc/cronjobs/delete_items.pl | 7 ++----- misc/cronjobs/delete_patrons.pl | 5 +---- misc/cronjobs/delete_records_via_leader.pl | 6 +----- misc/cronjobs/edi_cron.pl | 6 +----- misc/cronjobs/fines.pl | 5 +---- misc/cronjobs/gather_print_notices.pl | 5 +---- misc/cronjobs/holds/auto_unsuspend_holds.pl | 5 +---- misc/cronjobs/holds/build_holds_queue.pl | 5 +---- misc/cronjobs/holds/cancel_expired_holds.pl | 5 +---- misc/cronjobs/holds/cancel_unfilled_holds.pl | 5 +---- misc/cronjobs/import_webservice_batch.pl | 5 +---- misc/cronjobs/j2a.pl | 5 +---- misc/cronjobs/longoverdue.pl | 6 ++---- misc/cronjobs/membership_expiry.pl | 5 +---- misc/cronjobs/merge_authorities.pl | 5 +---- misc/cronjobs/notice_unprocessed_suggestions.pl | 6 +----- misc/cronjobs/overdue_notices.pl | 6 +----- misc/cronjobs/process_message_queue.pl | 6 ++---- misc/cronjobs/purge_suggestions.pl | 6 ++---- misc/cronjobs/reconcile_balances.pl | 5 +---- misc/cronjobs/remove_temporary_edifiles.pl | 1 + misc/cronjobs/runreport.pl | 5 +---- misc/cronjobs/serialsUpdate.pl | 5 +---- misc/cronjobs/share_usage_with_koha_community.pl | 5 +---- misc/cronjobs/sitemap.pl | 2 ++ misc/cronjobs/staticfines.pl | 5 +---- misc/cronjobs/stockrotation.pl | 7 ++----- misc/cronjobs/update_totalissues.pl | 6 ++---- 41 files changed, 67 insertions(+), 154 deletions(-) create mode 100644 Koha/Cron.pm diff --git a/Koha/Cron.pm b/Koha/Cron.pm new file mode 100644 index 0000000000..5cafe54083 --- /dev/null +++ b/Koha/Cron.pm @@ -0,0 +1,16 @@ +package Koha::Cron; + +use strict; +use warnings; +use utf8; +use feature ':5.10'; + +use C4::Context; + +C4::Context->_new_userenv(1); +C4::Context->set_userenv( + '-1', '-1', undef, 'CRON', 'CRON', undef, + undef, undef, undef, undef, undef +); + +1; diff --git a/misc/cronjobs/advance_notices.pl b/misc/cronjobs/advance_notices.pl index 829d96bc51..eeb0d7e0a8 100755 --- a/misc/cronjobs/advance_notices.pl +++ b/misc/cronjobs/advance_notices.pl @@ -49,6 +49,7 @@ BEGIN { use FindBin; eval { require "$FindBin::Bin/../kohalib.pl" }; } +use Koha::Cron; use C4::Biblio; use C4::Context; use C4::Letters; @@ -223,10 +224,6 @@ END_WARN unless ($confirm) { pod2usage(1); } -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); # The fields that will be substituted into <> diff --git a/misc/cronjobs/automatic_item_modification_by_age.pl b/misc/cronjobs/automatic_item_modification_by_age.pl index 57ec035c05..6f04e5418e 100755 --- a/misc/cronjobs/automatic_item_modification_by_age.pl +++ b/misc/cronjobs/automatic_item_modification_by_age.pl @@ -6,6 +6,7 @@ use Getopt::Long; use Pod::Usage; use JSON; +use Koha::Cron; use C4::Context; use C4::Items; @@ -20,11 +21,6 @@ my $result = GetOptions( pod2usage(1) if $help; $verbose = 1 unless $confirm; -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); - # Load configuration from the syspref my $syspref_content = C4::Context->preference('automatic_item_modification_by_age_configuration'); my $rules = eval { JSON::from_json( $syspref_content ) }; diff --git a/misc/cronjobs/automatic_renewals.pl b/misc/cronjobs/automatic_renewals.pl index 98883e5db6..32017c9895 100755 --- a/misc/cronjobs/automatic_renewals.pl +++ b/misc/cronjobs/automatic_renewals.pl @@ -52,6 +52,7 @@ use Modern::Perl; use Pod::Usage; use Getopt::Long; +use Koha::Cron; use C4::Circulation; use C4::Context; use C4::Log; @@ -67,11 +68,6 @@ GetOptions( ) || pod2usage(1); pod2usage(0) if $help; - -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); my $auto_renews = Koha::Checkouts->search({ auto_renew => 1 }); diff --git a/misc/cronjobs/batch_anonymise.pl b/misc/cronjobs/batch_anonymise.pl index 328ae29110..654f61cabf 100755 --- a/misc/cronjobs/batch_anonymise.pl +++ b/misc/cronjobs/batch_anonymise.pl @@ -29,6 +29,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } +use Koha::Cron; use C4::Context; use Koha::Patrons; use Date::Calc qw( @@ -67,10 +68,6 @@ if ( !$days ) { usage(1); } -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); my ($year,$month,$day) = Today(); diff --git a/misc/cronjobs/build_browser_and_cloud.pl b/misc/cronjobs/build_browser_and_cloud.pl index 280b1e47a4..a72c1f95e2 100755 --- a/misc/cronjobs/build_browser_and_cloud.pl +++ b/misc/cronjobs/build_browser_and_cloud.pl @@ -10,6 +10,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } +use Koha::Cron; use C4::Koha; use C4::Context; use C4::Biblio; @@ -62,10 +63,6 @@ my $browser_subfield = $2; warn "browser : $browser_tag / $browser_subfield" unless $batch; die "no cloud or browser field/subfield defined : nothing to do !" unless $browser_tag or $cloud_tag; -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); my $dbh = C4::Context->dbh; diff --git a/misc/cronjobs/cart_to_shelf.pl b/misc/cronjobs/cart_to_shelf.pl index dfa3aff5f6..0e35c96b44 100755 --- a/misc/cronjobs/cart_to_shelf.pl +++ b/misc/cronjobs/cart_to_shelf.pl @@ -28,6 +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 C4::Items qw/ CartToShelf /; use C4::Log; @@ -64,10 +65,6 @@ unless ($hours) { die "ERROR: No --hours (-h) option defined"; } -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); my $query = "SELECT itemnumber FROM items WHERE location = 'CART' AND TIMESTAMPDIFF(HOUR, items.timestamp, NOW() ) > ?"; diff --git a/misc/cronjobs/check-url-quick.pl b/misc/cronjobs/check-url-quick.pl index ff62c55d9d..5b596f09df 100755 --- a/misc/cronjobs/check-url-quick.pl +++ b/misc/cronjobs/check-url-quick.pl @@ -20,6 +20,8 @@ use Modern::Perl; use Pod::Usage; use Getopt::Long; + +use Koha::Cron; use C4::Context; use C4::Biblio; use AnyEvent; @@ -43,11 +45,6 @@ GetOptions( 'tags=s{,}' => \@tags, ); -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); - # Validate tags to check { my %h = map { $_ => undef } @tags; diff --git a/misc/cronjobs/check-url.pl b/misc/cronjobs/check-url.pl index 5c0957b060..dc916c4857 100755 --- a/misc/cronjobs/check-url.pl +++ b/misc/cronjobs/check-url.pl @@ -78,6 +78,7 @@ use strict; use warnings; use LWP::UserAgent; use HTTP::Request; +use Koha::Cron; use C4::Biblio; @@ -147,6 +148,7 @@ use Carp; use Pod::Usage; use Getopt::Long; +use Koha::Cron; use C4::Context; diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index fa176f3f91..bc2404fb90 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -34,6 +34,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } +use Koha::Cron; use C4::Context; use C4::Search; use C4::Search::History; @@ -176,10 +177,6 @@ if ($pDebarments && $allDebarments) { usage(1); } -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); my $dbh = C4::Context->dbh(); diff --git a/misc/cronjobs/cloud-kw.pl b/misc/cronjobs/cloud-kw.pl index a748153e58..443218387b 100755 --- a/misc/cronjobs/cloud-kw.pl +++ b/misc/cronjobs/cloud-kw.pl @@ -25,6 +25,8 @@ use Carp; use YAML::Syck; use Pod::Usage; use Getopt::Long; + +use Koha::Cron; use C4::Context; use C4::Log; @@ -44,10 +46,6 @@ sub usage { usage() if $help || !$conf; -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); my @clouds; diff --git a/misc/cronjobs/create_koc_db.pl b/misc/cronjobs/create_koc_db.pl index 89922d44d7..d6d158e9c8 100755 --- a/misc/cronjobs/create_koc_db.pl +++ b/misc/cronjobs/create_koc_db.pl @@ -94,6 +94,8 @@ $|++; use DBI; use Getopt::Long; use Pod::Usage; + +use Koha::Cron; use C4::Context; use English qw(-no_match_vars); @@ -118,11 +120,6 @@ GetOptions( pod2usage(1) if $help; pod2usage( -verbose => 2 ) if $man; -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); - my %wanted_borrowers_columns = map { $_ => 1 } qw/borrowernumber cardnumber surname firstname address city phone dateofbirth/; my %wanted_issues_columns = map { $_ => 1 } qw/borrowernumber date_due itemcallnumber title itemtype/; diff --git a/misc/cronjobs/delete_expired_opac_registrations.pl b/misc/cronjobs/delete_expired_opac_registrations.pl index 66f9e165e8..47950b4335 100755 --- a/misc/cronjobs/delete_expired_opac_registrations.pl +++ b/misc/cronjobs/delete_expired_opac_registrations.pl @@ -28,6 +28,7 @@ BEGIN { eval { my $lib = "$FindBin::Bin/../kohalib.pl"; require $lib }; } +use Koha::Cron; use C4::Context; my $help; diff --git a/misc/cronjobs/delete_items.pl b/misc/cronjobs/delete_items.pl index 073632cbb4..bccc0e02ef 100755 --- a/misc/cronjobs/delete_items.pl +++ b/misc/cronjobs/delete_items.pl @@ -1,17 +1,14 @@ #! /usr/bin/perl use Getopt::Long; + +use Koha::Cron; use C4::Context; use C4::Items; use C4::Circulation; use Modern::Perl; use Pod::Usage; -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); - my $dbh = C4::Context->dbh(); my $query = { diff --git a/misc/cronjobs/delete_patrons.pl b/misc/cronjobs/delete_patrons.pl index fd5a3eeb87..5f672133be 100755 --- a/misc/cronjobs/delete_patrons.pl +++ b/misc/cronjobs/delete_patrons.pl @@ -5,6 +5,7 @@ use Modern::Perl; use Pod::Usage; use Getopt::Long; +use Koha::Cron; use C4::Members; use Koha::DateUtils; use Koha::Patrons; @@ -41,10 +42,6 @@ unless ( $not_borrowed_since or $expired_before or $last_seen or $category_code pod2usage(q{At least one filter is mandatory}); } -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); my $members = GetBorrowersToExpunge( diff --git a/misc/cronjobs/delete_records_via_leader.pl b/misc/cronjobs/delete_records_via_leader.pl index c511774e7e..11dc33d4e5 100755 --- a/misc/cronjobs/delete_records_via_leader.pl +++ b/misc/cronjobs/delete_records_via_leader.pl @@ -33,6 +33,7 @@ BEGIN { use Getopt::Long; use Pod::Usage; +use Koha::Cron; use C4::Biblio; use C4::Items; use Koha::Database; @@ -77,11 +78,6 @@ This script has the following parameters : exit(); } -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); - my @metadatas = # Should be replaced by a call to C4::Search on zebra index # Record-status when bug 15537 will be pushed Koha::Biblio::Metadatas->search( { format => 'marcxml', schema => C4::Context->preference('marcflavour'), metadata => { LIKE => '%_____d%' } } ); diff --git a/misc/cronjobs/edi_cron.pl b/misc/cronjobs/edi_cron.pl index 02c6fdcc19..dfc1a2e11e 100755 --- a/misc/cronjobs/edi_cron.pl +++ b/misc/cronjobs/edi_cron.pl @@ -29,6 +29,7 @@ use utf8; # can be run as frequently as required # log messages are appended to logdir/editrace.log +use Koha::Cron; use C4::Context; use Log::Log4perl qw(:easy); use Koha::Database; @@ -36,11 +37,6 @@ use Koha::EDI qw( process_quote process_invoice process_ordrsp); use Koha::Edifact::Transport; use Fcntl qw( :DEFAULT :flock :seek ); -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); - my $logdir = C4::Context->config('logdir'); # logging set to trace as this may be what you diff --git a/misc/cronjobs/fines.pl b/misc/cronjobs/fines.pl index 4ee9f403fe..ac74adc75b 100755 --- a/misc/cronjobs/fines.pl +++ b/misc/cronjobs/fines.pl @@ -30,6 +30,7 @@ use strict; use warnings; use 5.010; +use Koha::Cron; use C4::Context; use C4::Overdues; use Getopt::Long; @@ -71,10 +72,6 @@ if ($help) { exit; } -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); my @borrower_fields = diff --git a/misc/cronjobs/gather_print_notices.pl b/misc/cronjobs/gather_print_notices.pl index 873c430bec..a0c85c894a 100755 --- a/misc/cronjobs/gather_print_notices.pl +++ b/misc/cronjobs/gather_print_notices.pl @@ -10,6 +10,7 @@ BEGIN { } use CGI qw( utf8 ); # NOT a CGI script, this is just to keep C4::Templates::gettemplate happy +use Koha::Cron; use C4::Context; use C4::Debug; use C4::Letters; @@ -79,10 +80,6 @@ if ( $ods and @letter_codes != 1 ) { $delimiter ||= q|,|; -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); my $today_iso = output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' } ) ; diff --git a/misc/cronjobs/holds/auto_unsuspend_holds.pl b/misc/cronjobs/holds/auto_unsuspend_holds.pl index 8d977da990..83d5d60012 100755 --- a/misc/cronjobs/holds/auto_unsuspend_holds.pl +++ b/misc/cronjobs/holds/auto_unsuspend_holds.pl @@ -29,13 +29,10 @@ BEGIN { # cancel all expired hold requests +use Koha::Cron; use C4::Reserves; use C4::Log; -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); AutoUnsuspendReserves(); diff --git a/misc/cronjobs/holds/build_holds_queue.pl b/misc/cronjobs/holds/build_holds_queue.pl index de00b801b3..370a9da49a 100755 --- a/misc/cronjobs/holds/build_holds_queue.pl +++ b/misc/cronjobs/holds/build_holds_queue.pl @@ -15,13 +15,10 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } +use Koha::Cron; use C4::HoldsQueue qw(CreateQueue); use C4::Log; -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); CreateQueue(); diff --git a/misc/cronjobs/holds/cancel_expired_holds.pl b/misc/cronjobs/holds/cancel_expired_holds.pl index 2cb5820618..6de289b844 100755 --- a/misc/cronjobs/holds/cancel_expired_holds.pl +++ b/misc/cronjobs/holds/cancel_expired_holds.pl @@ -29,13 +29,10 @@ BEGIN { # cancel all expired hold requests +use Koha::Cron; use C4::Reserves; use C4::Log; -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); CancelExpiredReserves(); diff --git a/misc/cronjobs/holds/cancel_unfilled_holds.pl b/misc/cronjobs/holds/cancel_unfilled_holds.pl index a3bab3426e..0cae7fb029 100755 --- a/misc/cronjobs/holds/cancel_unfilled_holds.pl +++ b/misc/cronjobs/holds/cancel_unfilled_holds.pl @@ -28,6 +28,7 @@ BEGIN { use Getopt::Long; use Pod::Usage; +use Koha::Cron; use C4::Reserves; use C4::Log; use Koha::Holds; @@ -35,10 +36,6 @@ use Koha::Calendar; use Koha::DateUtils; use Koha::Libraries; -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); =head1 NAME diff --git a/misc/cronjobs/import_webservice_batch.pl b/misc/cronjobs/import_webservice_batch.pl index 2942ddf103..55de9be2bb 100755 --- a/misc/cronjobs/import_webservice_batch.pl +++ b/misc/cronjobs/import_webservice_batch.pl @@ -31,6 +31,7 @@ BEGIN { use Getopt::Long; use Pod::Usage; +use Koha::Cron; use C4::ImportBatch; my ($help, $framework); @@ -50,10 +51,6 @@ EOF ; exit; } -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); my $batch_ids = GetStagedWebserviceBatches() or exit; diff --git a/misc/cronjobs/j2a.pl b/misc/cronjobs/j2a.pl index 73dc7a4f1a..4fb22fa05d 100755 --- a/misc/cronjobs/j2a.pl +++ b/misc/cronjobs/j2a.pl @@ -26,6 +26,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } +use Koha::Cron; use C4::Context; use C4::Members; use Getopt::Long; @@ -125,10 +126,6 @@ if ( not $fromcat && $tocat ) { #make sure we've specified the info we need. exit; } -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); my $dbh = C4::Context->dbh; diff --git a/misc/cronjobs/longoverdue.pl b/misc/cronjobs/longoverdue.pl index b16b0c80ca..82d13b1509 100755 --- a/misc/cronjobs/longoverdue.pl +++ b/misc/cronjobs/longoverdue.pl @@ -33,6 +33,8 @@ BEGIN { use FindBin; eval { require "$FindBin::Bin/../kohalib.pl" }; } + +use Koha::Cron; use C4::Context; use C4::Items; use C4::Circulation qw/LostItem MarkIssueReturned/; @@ -228,10 +230,6 @@ unless ($confirm) { print "### TEST MODE -- NO ACTIONS TAKEN ###\n"; } -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); # In my opinion, this line is safe SQL to have outside the API. --atz diff --git a/misc/cronjobs/membership_expiry.pl b/misc/cronjobs/membership_expiry.pl index d172d552d3..3ce0537016 100755 --- a/misc/cronjobs/membership_expiry.pl +++ b/misc/cronjobs/membership_expiry.pl @@ -126,6 +126,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } +use Koha::Cron; use C4::Context; use C4::Letters; use C4::Log; @@ -157,10 +158,6 @@ GetOptions( pod2usage( -verbose => 2 ) if $man; pod2usage(1) if $help || !$confirm; -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); my $expdays = C4::Context->preference('MembershipExpiryDaysNotice'); diff --git a/misc/cronjobs/merge_authorities.pl b/misc/cronjobs/merge_authorities.pl index 2db41de955..105b1eff9c 100755 --- a/misc/cronjobs/merge_authorities.pl +++ b/misc/cronjobs/merge_authorities.pl @@ -5,6 +5,7 @@ use Getopt::Long; use Pod::Usage; use Time::HiRes qw(gettimeofday); +use Koha::Cron; use C4::AuthoritiesMarc; use Koha::Authority::MergeRequests; @@ -20,10 +21,6 @@ GetOptions( $|=1; # flushes output if ( $params->{batch} ) { - C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef - ); handle_batch($params); } else { diff --git a/misc/cronjobs/notice_unprocessed_suggestions.pl b/misc/cronjobs/notice_unprocessed_suggestions.pl index e2a970d9a3..fa79e8999a 100755 --- a/misc/cronjobs/notice_unprocessed_suggestions.pl +++ b/misc/cronjobs/notice_unprocessed_suggestions.pl @@ -5,6 +5,7 @@ use Modern::Perl; use Pod::Usage; use Getopt::Long; +use Koha::Cron; use C4::Budgets qw( GetBudget ); use C4::Suggestions qw( GetUnprocessedSuggestions ); use Koha::Libraries; @@ -22,11 +23,6 @@ if ($help) { pod2usage( verbose => 2 ); } -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); - unless (@days) { pod2usage(q{At least one day parameter should be given}); exit; diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index b249f2aeb0..8c8f6a03ce 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -34,6 +34,7 @@ use Text::CSV_XS; use DateTime; use DateTime::Duration; +use Koha::Cron; use C4::Context; use C4::Letters; use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes parse_overdues_letter); @@ -325,11 +326,6 @@ GetOptions( ) or pod2usage(2); pod2usage(1) if $help; pod2usage( -verbose => 2 ) if $man; - -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction() unless $test_mode; if ( defined $csvfilename && $csvfilename =~ /^-/ ) { diff --git a/misc/cronjobs/process_message_queue.pl b/misc/cronjobs/process_message_queue.pl index 93e355b207..c78d4c0892 100755 --- a/misc/cronjobs/process_message_queue.pl +++ b/misc/cronjobs/process_message_queue.pl @@ -25,6 +25,8 @@ BEGIN { use FindBin; eval { require "$FindBin::Bin/../kohalib.pl" }; } + +use Koha::Cron; use C4::Letters; use C4::Log; use Getopt::Long; @@ -66,10 +68,6 @@ ENDUSAGE die $usage if $help; -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); C4::Letters::SendQueuedMessages( diff --git a/misc/cronjobs/purge_suggestions.pl b/misc/cronjobs/purge_suggestions.pl index 7a1575a36d..55536577da 100755 --- a/misc/cronjobs/purge_suggestions.pl +++ b/misc/cronjobs/purge_suggestions.pl @@ -28,6 +28,8 @@ BEGIN { use Getopt::Long; use Pod::Usage; + +use Koha::Cron; use C4::Suggestions; use C4::Log; use C4::Context; @@ -63,10 +65,6 @@ if( !$confirm || $help || !defined($days) ) { print "No confirm parameter passed!\n\n" if !$confirm && !$help; print $usage; } elsif( $days and $days > 0 ) { - C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef - ); cronlogaction( " ( days: $days )"); DelSuggestionsOlderThan($days); } else { diff --git a/misc/cronjobs/reconcile_balances.pl b/misc/cronjobs/reconcile_balances.pl index 4913fddd67..8ff7e8597a 100755 --- a/misc/cronjobs/reconcile_balances.pl +++ b/misc/cronjobs/reconcile_balances.pl @@ -62,6 +62,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } +use Koha::Cron; use C4::Log; use Koha::Account::Lines; @@ -76,10 +77,6 @@ GetOptions( ) or pod2usage(2); pod2usage(1) if $help; -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); my @patron_ids = map { $_->borrowernumber } Koha::Account::Lines->search( diff --git a/misc/cronjobs/remove_temporary_edifiles.pl b/misc/cronjobs/remove_temporary_edifiles.pl index e799ee5b2e..a38c911285 100755 --- a/misc/cronjobs/remove_temporary_edifiles.pl +++ b/misc/cronjobs/remove_temporary_edifiles.pl @@ -2,6 +2,7 @@ use strict; use warnings; +use Koha::Cron; use C4::Context; # this script will remove those older than 5 days diff --git a/misc/cronjobs/runreport.pl b/misc/cronjobs/runreport.pl index 549bf26cdb..a673a5bcb0 100755 --- a/misc/cronjobs/runreport.pl +++ b/misc/cronjobs/runreport.pl @@ -20,6 +20,7 @@ use Modern::Perl; +use Koha::Cron; use C4::Reports::Guided; # 0.12 use Koha::Reports; use C4::Context; @@ -204,10 +205,6 @@ pod2usage( -verbose => 2 ) if ($man); pod2usage( -verbose => 2 ) if ($help and $verbose); pod2usage(1) if $help; -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); unless ($format) { diff --git a/misc/cronjobs/serialsUpdate.pl b/misc/cronjobs/serialsUpdate.pl index b1ede3c355..6bf40c1f47 100755 --- a/misc/cronjobs/serialsUpdate.pl +++ b/misc/cronjobs/serialsUpdate.pl @@ -28,6 +28,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } +use Koha::Cron; use C4::Context; use C4::Debug; use C4::Serials; @@ -79,10 +80,6 @@ GetOptions( pod2usage(1) if $help; pod2usage( -verbose => 2 ) if $man; -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); $verbose and !$confirm and print "### Database will not be modified ###\n"; diff --git a/misc/cronjobs/share_usage_with_koha_community.pl b/misc/cronjobs/share_usage_with_koha_community.pl index c8cc83b3f7..3173ab40a8 100755 --- a/misc/cronjobs/share_usage_with_koha_community.pl +++ b/misc/cronjobs/share_usage_with_koha_community.pl @@ -5,6 +5,7 @@ use Modern::Perl; use Pod::Usage; use Getopt::Long; +use Koha::Cron; use C4::Context; use C4::UsageStats; use C4::Log; @@ -35,10 +36,6 @@ Setting the quiet flag will silence this message. exit 1; } -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); my $need_update = ($force ? 1 : C4::UsageStats::NeedUpdate() ); diff --git a/misc/cronjobs/sitemap.pl b/misc/cronjobs/sitemap.pl index 80c01fdd03..909ad6fed2 100755 --- a/misc/cronjobs/sitemap.pl +++ b/misc/cronjobs/sitemap.pl @@ -23,6 +23,8 @@ use Modern::Perl; use utf8; use Pod::Usage; use Getopt::Long; + +use Koha::Cron; use C4::Biblio; use Koha::Sitemapper; diff --git a/misc/cronjobs/staticfines.pl b/misc/cronjobs/staticfines.pl index a14abbc31f..e947eb105d 100755 --- a/misc/cronjobs/staticfines.pl +++ b/misc/cronjobs/staticfines.pl @@ -37,6 +37,7 @@ BEGIN { use Date::Calc qw/Date_to_Days/; +use Koha::Cron; use C4::Context; use C4::Circulation; use C4::Overdues; @@ -91,10 +92,6 @@ This script has the following parameters : ENDUSAGE die $usage if $help; -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); my $dbh = C4::Context->dbh; diff --git a/misc/cronjobs/stockrotation.pl b/misc/cronjobs/stockrotation.pl index 8cb43f0e44..d178ed8204 100755 --- a/misc/cronjobs/stockrotation.pl +++ b/misc/cronjobs/stockrotation.pl @@ -109,15 +109,12 @@ database updates have been performed."). use Modern::Perl; use Getopt::Long qw/HelpMessage :config gnu_getopt/; + +use Koha::Cron; use C4::Context; use C4::Letters; use Koha::StockRotationRotas; -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); - my $admin_email = ''; my $branch = 0; my $execute = 0; diff --git a/misc/cronjobs/update_totalissues.pl b/misc/cronjobs/update_totalissues.pl index c155052525..667b5ac8e0 100755 --- a/misc/cronjobs/update_totalissues.pl +++ b/misc/cronjobs/update_totalissues.pl @@ -30,6 +30,8 @@ BEGIN { use Getopt::Long; use Pod::Usage; + +use Koha::Cron; use C4::Context; use C4::Biblio; use C4::Log; @@ -95,10 +97,6 @@ if ( not $result or $want_help ) { usage(); } -C4::Context->set_userenv( - '-1', '-1', undef, 'CRON', 'CRON', undef, - undef, undef, undef, undef, undef -); cronlogaction(); my $dbh = C4::Context->dbh; -- 2.20.1