@@ -, +, @@ appropriately --- C4/Context.pm | 1 + Koha/Cron.pm | 55 +++++++++++++++++++ misc/cronjobs/advance_notices.pl | 2 +- .../automatic_item_modification_by_age.pl | 1 + misc/cronjobs/automatic_renewals.pl | 2 +- misc/cronjobs/batch_anonymise.pl | 1 + misc/cronjobs/build_browser_and_cloud.pl | 1 + misc/cronjobs/cart_to_shelf.pl | 1 + misc/cronjobs/check-url-quick.pl | 2 + misc/cronjobs/check-url.pl | 2 + misc/cronjobs/cleanup_database.pl | 1 + misc/cronjobs/cloud-kw.pl | 4 +- misc/cronjobs/create_koc_db.pl | 3 +- .../delete_expired_opac_registrations.pl | 1 + misc/cronjobs/delete_items.pl | 2 + misc/cronjobs/delete_patrons.pl | 1 + misc/cronjobs/delete_records_via_leader.pl | 1 + misc/cronjobs/edi_cron.pl | 1 + misc/cronjobs/fines.pl | 1 + misc/cronjobs/gather_print_notices.pl | 1 + misc/cronjobs/holds/auto_unsuspend_holds.pl | 1 + misc/cronjobs/holds/build_holds_queue.pl | 1 + misc/cronjobs/holds/cancel_expired_holds.pl | 1 + misc/cronjobs/holds/cancel_unfilled_holds.pl | 1 + misc/cronjobs/import_webservice_batch.pl | 1 + misc/cronjobs/j2a.pl | 1 + misc/cronjobs/longoverdue.pl | 2 + misc/cronjobs/membership_expiry.pl | 1 + misc/cronjobs/merge_authorities.pl | 5 +- .../notice_unprocessed_suggestions.pl | 1 + 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 | 1 + misc/cronjobs/rss/rss.pl | 2 + misc/cronjobs/runreport.pl | 1 + misc/cronjobs/serialsUpdate.pl | 1 + .../share_usage_with_koha_community.pl | 1 + misc/cronjobs/sitemap.pl | 2 + .../social_data/get_report_social_data.pl | 2 + .../social_data/update_social_data.pl | 2 + misc/cronjobs/staticfines.pl | 1 + misc/cronjobs/stockrotation.pl | 2 + .../thirdparty/TalkingTech_itiva_inbound.pl | 1 + .../thirdparty/TalkingTech_itiva_outbound.pl | 1 + misc/cronjobs/update_totalissues.pl | 2 + t/Context.t | 3 +- t/Koha/Cron.t | 48 ++++++++++++++++ 49 files changed, 168 insertions(+), 9 deletions(-) create mode 100644 Koha/Cron.pm create mode 100644 t/Koha/Cron.t --- a/C4/Context.pm +++ a/C4/Context.pm @@ -1032,6 +1032,7 @@ sub interface { || $interface eq 'opac' || $interface eq 'intranet' || $interface eq 'sip' + || $interface eq 'cron' || $interface eq 'commandline' ) { $context->{interface} = $interface; --- a/Koha/Cron.pm +++ a/Koha/Cron.pm @@ -0,0 +1,55 @@ +package Koha::Cron; + +# Copyright PTFS Europe 2019 +# Copyright 2019 Koha Development Team +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +=head1 NAME + +Koha::Cron - Koha Cron scripts base class + +=head1 SYNOPSIS + + use Koha::Cron; + +=head1 DESCRIPTION + +This class should be used in all cronscripts. 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'); + +=head1 AUTHOR + +Martin Renvoize + +=cut + +1; --- a/misc/cronjobs/advance_notices.pl +++ a/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,7 +224,6 @@ END_WARN unless ($confirm) { pod2usage(1); } - cronlogaction(); # The fields that will be substituted into <> --- a/misc/cronjobs/automatic_item_modification_by_age.pl +++ a/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; --- a/misc/cronjobs/automatic_renewals.pl +++ a/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,7 +68,6 @@ GetOptions( ) || pod2usage(1); pod2usage(0) if $help; - cronlogaction(); my $auto_renews = Koha::Checkouts->search({ auto_renew => 1 }); --- a/misc/cronjobs/batch_anonymise.pl +++ a/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( --- a/misc/cronjobs/build_browser_and_cloud.pl +++ a/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; --- a/misc/cronjobs/cart_to_shelf.pl +++ a/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; --- a/misc/cronjobs/check-url-quick.pl +++ a/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; --- a/misc/cronjobs/check-url.pl +++ a/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; --- a/misc/cronjobs/cleanup_database.pl +++ a/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; --- a/misc/cronjobs/cloud-kw.pl +++ a/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; @@ -42,7 +44,7 @@ sub usage { exit; } -usage() if $help || !$conf; +usage() if $help || !$conf; cronlogaction(); --- a/misc/cronjobs/create_koc_db.pl +++ a/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,7 +120,6 @@ GetOptions( pod2usage(1) if $help; pod2usage( -verbose => 2 ) if $man; - 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/; --- a/misc/cronjobs/delete_expired_opac_registrations.pl +++ a/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; --- a/misc/cronjobs/delete_items.pl +++ a/misc/cronjobs/delete_items.pl @@ -1,6 +1,8 @@ #! /usr/bin/perl use Getopt::Long; + +use Koha::Cron; use C4::Context; use C4::Items; use C4::Circulation; --- a/misc/cronjobs/delete_patrons.pl +++ a/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; --- a/misc/cronjobs/delete_records_via_leader.pl +++ a/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; --- a/misc/cronjobs/edi_cron.pl +++ a/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; --- a/misc/cronjobs/fines.pl +++ a/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; --- a/misc/cronjobs/gather_print_notices.pl +++ a/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; --- a/misc/cronjobs/holds/auto_unsuspend_holds.pl +++ a/misc/cronjobs/holds/auto_unsuspend_holds.pl @@ -29,6 +29,7 @@ BEGIN { # cancel all expired hold requests +use Koha::Cron; use C4::Reserves; use C4::Log; --- a/misc/cronjobs/holds/build_holds_queue.pl +++ a/misc/cronjobs/holds/build_holds_queue.pl @@ -15,6 +15,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } +use Koha::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,6 +29,7 @@ BEGIN { # cancel all expired hold requests +use Koha::Cron; use C4::Reserves; use C4::Log; --- a/misc/cronjobs/holds/cancel_unfilled_holds.pl +++ a/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; --- a/misc/cronjobs/import_webservice_batch.pl +++ a/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); --- a/misc/cronjobs/j2a.pl +++ a/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; --- a/misc/cronjobs/longoverdue.pl +++ a/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/; --- a/misc/cronjobs/membership_expiry.pl +++ a/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; --- a/misc/cronjobs/merge_authorities.pl +++ a/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; @@ -19,8 +20,8 @@ GetOptions( ); $|=1; # flushes output -if( $params->{batch} ) { - handle_batch( $params ); +if ( $params->{batch} ) { + handle_batch($params); } else { pod2usage(1); } --- a/misc/cronjobs/notice_unprocessed_suggestions.pl +++ a/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; --- a/misc/cronjobs/overdue_notices.pl +++ a/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,7 +326,6 @@ GetOptions( ) or pod2usage(2); pod2usage(1) if $help; pod2usage( -verbose => 2 ) if $man; - cronlogaction() unless $test_mode; if ( defined $csvfilename && $csvfilename =~ /^-/ ) { --- a/misc/cronjobs/process_message_queue.pl +++ a/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; --- a/misc/cronjobs/purge_suggestions.pl +++ a/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; --- a/misc/cronjobs/reconcile_balances.pl +++ a/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,7 +77,6 @@ GetOptions( ) or pod2usage(2); pod2usage(1) if $help; - cronlogaction(); my @patron_ids = map { $_->borrowernumber } Koha::Account::Lines->search( --- a/misc/cronjobs/remove_temporary_edifiles.pl +++ a/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 --- a/misc/cronjobs/rss/rss.pl +++ a/misc/cronjobs/rss/rss.pl @@ -28,6 +28,8 @@ use Modern::Perl; use Template; + +use Koha::Cron; use C4::Context; use Time::Local; use POSIX; --- a/misc/cronjobs/runreport.pl +++ a/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; --- a/misc/cronjobs/serialsUpdate.pl +++ a/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; --- a/misc/cronjobs/share_usage_with_koha_community.pl +++ a/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; --- a/misc/cronjobs/sitemap.pl +++ a/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; --- a/misc/cronjobs/social_data/get_report_social_data.pl +++ a/misc/cronjobs/social_data/get_report_social_data.pl @@ -1,6 +1,8 @@ #!/usr/bin/perl use Modern::Perl; + +use Koha::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 @@ -1,6 +1,8 @@ #!/usr/bin/perl use Modern::Perl; + +use Koha::Cron; use C4::Context; use C4::SocialData; --- a/misc/cronjobs/staticfines.pl +++ a/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; --- a/misc/cronjobs/stockrotation.pl +++ a/misc/cronjobs/stockrotation.pl @@ -109,6 +109,8 @@ 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; --- a/misc/cronjobs/thirdparty/TalkingTech_itiva_inbound.pl +++ a/misc/cronjobs/thirdparty/TalkingTech_itiva_inbound.pl @@ -31,6 +31,7 @@ BEGIN { use Getopt::Long; use Pod::Usage; +use Koha::Cron; use C4::Context; sub usage { --- a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl +++ a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl @@ -31,6 +31,7 @@ BEGIN { use Getopt::Long; use Pod::Usage; +use Koha::Cron; use C4::Context; use C4::Items; use C4::Letters; --- a/misc/cronjobs/update_totalissues.pl +++ a/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; --- a/t/Context.t +++ a/t/Context.t @@ -2,7 +2,7 @@ use Modern::Perl; use DBI; -use Test::More tests => 26; +use Test::More tests => 27; use Test::MockModule; BEGIN { @@ -62,3 +62,4 @@ is(C4::Context->interface, 'opac', 'interface still opac'); #Bug 14751 is( C4::Context->interface( 'SiP' ), 'sip', 'interface SiP' ); is( C4::Context->interface( 'COMMANDLINE' ), 'commandline', 'interface commandline uc' ); +is( C4::Context->interface( 'CRON' ), 'cron', 'interface cron uc' ); --- a/t/Koha/Cron.t +++ a/t/Koha/Cron.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::Cron') } + +use C4::Context; + +my $userenv = C4::Context->userenv; +is_deeply( + $userenv, + { + 'surname' => 'CRON', + 'id' => undef, + 'flags' => undef, + 'cardnumber' => undef, + 'firstname' => 'CRON', + 'branchname' => undef, + 'branchprinter' => undef, + 'emailaddress' => undef, + 'number' => undef, + 'shibboleth' => undef, + 'branch' => undef + }, + "Context userenv set correctly" +); + +my $interface = C4::Context->interface; +is($interface, 'cron', "Context interface set correctly"); + +1; --