From 125de75517b64a95b93dead4b1fa5c2326f007eb Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 25 Mar 2019 19:04:58 +0000 Subject: [PATCH] Bug 22600: Add 'cron' to interface types and set appropriately This patch adds 'cron' as a valid interface and sets it appropriately for existing cron scripts. Signed-off-by: Martin Renvoize Signed-off-by: Josef Moravec Signed-off-by: Tomas Cohen Arazi Signed-off-by: Nick Clemens --- 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 diff --git a/C4/Context.pm b/C4/Context.pm index 319a11b59e..fa612472f7 100644 --- a/C4/Context.pm +++ b/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; diff --git a/Koha/Cron.pm b/Koha/Cron.pm new file mode 100644 index 0000000000..95bd3a9504 --- /dev/null +++ b/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; diff --git a/misc/cronjobs/advance_notices.pl b/misc/cronjobs/advance_notices.pl index 91bf352b89..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,7 +224,6 @@ END_WARN unless ($confirm) { pod2usage(1); } - 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 51effd32b1..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; diff --git a/misc/cronjobs/automatic_renewals.pl b/misc/cronjobs/automatic_renewals.pl index b50a6d565a..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,7 +68,6 @@ GetOptions( ) || pod2usage(1); pod2usage(0) if $help; - 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 013f7d1179..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( diff --git a/misc/cronjobs/build_browser_and_cloud.pl b/misc/cronjobs/build_browser_and_cloud.pl index d5e0d1a8f5..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; diff --git a/misc/cronjobs/cart_to_shelf.pl b/misc/cronjobs/cart_to_shelf.pl index 965f7dd0d4..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; diff --git a/misc/cronjobs/check-url-quick.pl b/misc/cronjobs/check-url-quick.pl index 22d2dfe461..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; 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 3e6c504532..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; diff --git a/misc/cronjobs/cloud-kw.pl b/misc/cronjobs/cloud-kw.pl index 96864156ef..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; @@ -42,7 +44,7 @@ sub usage { exit; } -usage() if $help || !$conf; +usage() if $help || !$conf; cronlogaction(); diff --git a/misc/cronjobs/create_koc_db.pl b/misc/cronjobs/create_koc_db.pl index 2b5b33aab9..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,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/; 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 78a9b35b8d..bccc0e02ef 100755 --- a/misc/cronjobs/delete_items.pl +++ b/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; diff --git a/misc/cronjobs/delete_patrons.pl b/misc/cronjobs/delete_patrons.pl index cb59465df4..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; diff --git a/misc/cronjobs/delete_records_via_leader.pl b/misc/cronjobs/delete_records_via_leader.pl index 41b22bb7cb..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; diff --git a/misc/cronjobs/edi_cron.pl b/misc/cronjobs/edi_cron.pl index c23341ad26..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; diff --git a/misc/cronjobs/fines.pl b/misc/cronjobs/fines.pl index 89ad4a2d3c..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; diff --git a/misc/cronjobs/gather_print_notices.pl b/misc/cronjobs/gather_print_notices.pl index ca99635346..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; diff --git a/misc/cronjobs/holds/auto_unsuspend_holds.pl b/misc/cronjobs/holds/auto_unsuspend_holds.pl index d17dfb55b0..83d5d60012 100755 --- a/misc/cronjobs/holds/auto_unsuspend_holds.pl +++ b/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; diff --git a/misc/cronjobs/holds/build_holds_queue.pl b/misc/cronjobs/holds/build_holds_queue.pl index be50de705e..370a9da49a 100755 --- a/misc/cronjobs/holds/build_holds_queue.pl +++ b/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; diff --git a/misc/cronjobs/holds/cancel_expired_holds.pl b/misc/cronjobs/holds/cancel_expired_holds.pl index f721553bb5..6de289b844 100755 --- a/misc/cronjobs/holds/cancel_expired_holds.pl +++ b/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; diff --git a/misc/cronjobs/holds/cancel_unfilled_holds.pl b/misc/cronjobs/holds/cancel_unfilled_holds.pl index 8c7f928ae0..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; diff --git a/misc/cronjobs/import_webservice_batch.pl b/misc/cronjobs/import_webservice_batch.pl index 0e1384f827..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); diff --git a/misc/cronjobs/j2a.pl b/misc/cronjobs/j2a.pl index ba90ad0ccd..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; diff --git a/misc/cronjobs/longoverdue.pl b/misc/cronjobs/longoverdue.pl index f895f6d451..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/; diff --git a/misc/cronjobs/membership_expiry.pl b/misc/cronjobs/membership_expiry.pl index 1b6ea81d43..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; diff --git a/misc/cronjobs/merge_authorities.pl b/misc/cronjobs/merge_authorities.pl index 4682694433..c2ef91413b 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; @@ -19,8 +20,8 @@ GetOptions( ); $|=1; # flushes output -if( $params->{batch} ) { - handle_batch( $params ); +if ( $params->{batch} ) { + handle_batch($params); } else { pod2usage(1); } diff --git a/misc/cronjobs/notice_unprocessed_suggestions.pl b/misc/cronjobs/notice_unprocessed_suggestions.pl index 598ef5a4b4..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; diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index 8c42335c2c..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,7 +326,6 @@ GetOptions( ) or pod2usage(2); pod2usage(1) if $help; pod2usage( -verbose => 2 ) if $man; - 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 3e0ef5173a..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; diff --git a/misc/cronjobs/purge_suggestions.pl b/misc/cronjobs/purge_suggestions.pl index 58a9a1dc12..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; diff --git a/misc/cronjobs/reconcile_balances.pl b/misc/cronjobs/reconcile_balances.pl index 1bd9dc277e..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,7 +77,6 @@ GetOptions( ) or pod2usage(2); pod2usage(1) if $help; - 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/rss/rss.pl b/misc/cronjobs/rss/rss.pl index 60e34fb04d..f9c512543b 100755 --- a/misc/cronjobs/rss/rss.pl +++ b/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; diff --git a/misc/cronjobs/runreport.pl b/misc/cronjobs/runreport.pl index c89a6d4844..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; diff --git a/misc/cronjobs/serialsUpdate.pl b/misc/cronjobs/serialsUpdate.pl index a478476981..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; diff --git a/misc/cronjobs/share_usage_with_koha_community.pl b/misc/cronjobs/share_usage_with_koha_community.pl index 9039558302..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; 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/social_data/get_report_social_data.pl b/misc/cronjobs/social_data/get_report_social_data.pl index 89d6b35061..5bb9867485 100755 --- a/misc/cronjobs/social_data/get_report_social_data.pl +++ b/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; diff --git a/misc/cronjobs/social_data/update_social_data.pl b/misc/cronjobs/social_data/update_social_data.pl index 53058a75b2..81bc1d006d 100755 --- a/misc/cronjobs/social_data/update_social_data.pl +++ b/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; diff --git a/misc/cronjobs/staticfines.pl b/misc/cronjobs/staticfines.pl index 5fee7f4909..1d4c2dc1d6 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; diff --git a/misc/cronjobs/stockrotation.pl b/misc/cronjobs/stockrotation.pl index 083c14766a..d178ed8204 100755 --- a/misc/cronjobs/stockrotation.pl +++ b/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; diff --git a/misc/cronjobs/thirdparty/TalkingTech_itiva_inbound.pl b/misc/cronjobs/thirdparty/TalkingTech_itiva_inbound.pl index 1a70c4ae90..abf81cb8c5 100755 --- a/misc/cronjobs/thirdparty/TalkingTech_itiva_inbound.pl +++ b/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 { diff --git a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl b/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl index d1ff3925fd..216f39d543 100755 --- a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl +++ b/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; diff --git a/misc/cronjobs/update_totalissues.pl b/misc/cronjobs/update_totalissues.pl index affa2a7e34..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; diff --git a/t/Context.t b/t/Context.t index e2c1825270..70d9ac637b 100755 --- a/t/Context.t +++ b/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' ); diff --git a/t/Koha/Cron.t b/t/Koha/Cron.t new file mode 100644 index 0000000000..05ecd25cee --- /dev/null +++ b/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; -- 2.39.5