Bug 22600: Add 'cron' to interface types and set appropriately
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 25 Mar 2019 19:04:58 +0000 (19:04 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Wed, 10 Apr 2019 19:43:11 +0000 (19:43 +0000)
This patch adds 'cron' as a valid interface and sets it appropriately for
existing cron scripts.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

49 files changed:
C4/Context.pm
Koha/Cron.pm [new file with mode: 0644]
misc/cronjobs/advance_notices.pl
misc/cronjobs/automatic_item_modification_by_age.pl
misc/cronjobs/automatic_renewals.pl
misc/cronjobs/batch_anonymise.pl
misc/cronjobs/build_browser_and_cloud.pl
misc/cronjobs/cart_to_shelf.pl
misc/cronjobs/check-url-quick.pl
misc/cronjobs/check-url.pl
misc/cronjobs/cleanup_database.pl
misc/cronjobs/cloud-kw.pl
misc/cronjobs/create_koc_db.pl
misc/cronjobs/delete_expired_opac_registrations.pl
misc/cronjobs/delete_items.pl
misc/cronjobs/delete_patrons.pl
misc/cronjobs/delete_records_via_leader.pl
misc/cronjobs/edi_cron.pl
misc/cronjobs/fines.pl
misc/cronjobs/gather_print_notices.pl
misc/cronjobs/holds/auto_unsuspend_holds.pl
misc/cronjobs/holds/build_holds_queue.pl
misc/cronjobs/holds/cancel_expired_holds.pl
misc/cronjobs/holds/cancel_unfilled_holds.pl
misc/cronjobs/import_webservice_batch.pl
misc/cronjobs/j2a.pl
misc/cronjobs/longoverdue.pl
misc/cronjobs/membership_expiry.pl
misc/cronjobs/merge_authorities.pl
misc/cronjobs/notice_unprocessed_suggestions.pl
misc/cronjobs/overdue_notices.pl
misc/cronjobs/process_message_queue.pl
misc/cronjobs/purge_suggestions.pl
misc/cronjobs/reconcile_balances.pl
misc/cronjobs/remove_temporary_edifiles.pl
misc/cronjobs/rss/rss.pl
misc/cronjobs/runreport.pl
misc/cronjobs/serialsUpdate.pl
misc/cronjobs/share_usage_with_koha_community.pl
misc/cronjobs/sitemap.pl
misc/cronjobs/social_data/get_report_social_data.pl
misc/cronjobs/social_data/update_social_data.pl
misc/cronjobs/staticfines.pl
misc/cronjobs/stockrotation.pl
misc/cronjobs/thirdparty/TalkingTech_itiva_inbound.pl
misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl
misc/cronjobs/update_totalissues.pl
t/Context.t
t/Koha/Cron.t [new file with mode: 0644]

index 319a11b..fa61247 100644 (file)
@@ -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 (file)
index 0000000..95bd3a9
--- /dev/null
@@ -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 <martin.renvoize@ptfs-europe.com>
+
+=cut
+
+1;
index 91bf352..eeb0d7e 100755 (executable)
@@ -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 <<items.content>>
index 51effd3..6f04e54 100755 (executable)
@@ -6,6 +6,7 @@ use Getopt::Long;
 use Pod::Usage;
 use JSON;
 
+use Koha::Cron;
 use C4::Context;
 use C4::Items;
 
index b50a6d5..32017c9 100755 (executable)
@@ -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 });
index 013f7d1..654f61c 100755 (executable)
@@ -29,6 +29,7 @@ BEGIN {
     eval { require "$FindBin::Bin/../kohalib.pl" };
 }
 
+use Koha::Cron;
 use C4::Context;
 use Koha::Patrons;
 use Date::Calc qw(
index d5e0d1a..a72c1f9 100755 (executable)
@@ -10,6 +10,7 @@ BEGIN {
     eval { require "$FindBin::Bin/../kohalib.pl" };
 }
 
+use Koha::Cron;
 use C4::Koha;
 use C4::Context;
 use C4::Biblio;
index 965f7dd..0e35c96 100755 (executable)
@@ -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;
 
index 22d2dfe..5b596f0 100755 (executable)
@@ -20,6 +20,8 @@
 use Modern::Perl;
 use Pod::Usage;
 use Getopt::Long;
+
+use Koha::Cron;
 use C4::Context;
 use C4::Biblio;
 use AnyEvent;
index 5c0957b..dc916c4 100755 (executable)
@@ -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;
 
 
index 3e6c504..bc2404f 100755 (executable)
@@ -34,6 +34,7 @@ BEGIN {
     eval { require "$FindBin::Bin/../kohalib.pl" };
 }
 
+use Koha::Cron;
 use C4::Context;
 use C4::Search;
 use C4::Search::History;
index 9686415..4432183 100755 (executable)
@@ -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();
 
index 2b5b33a..d6d158e 100755 (executable)
@@ -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/;
 
index 66f9e16..47950b4 100755 (executable)
@@ -28,6 +28,7 @@ BEGIN {
     eval { my $lib = "$FindBin::Bin/../kohalib.pl"; require $lib };
 }
 
+use Koha::Cron;
 use C4::Context;
 
 my $help;
index 78a9b35..bccc0e0 100755 (executable)
@@ -1,6 +1,8 @@
 #! /usr/bin/perl
 
 use Getopt::Long;
+
+use Koha::Cron;
 use C4::Context;
 use C4::Items;
 use C4::Circulation;
index cb59465..5f67213 100755 (executable)
@@ -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;
index 41b22bb..11dc33d 100755 (executable)
@@ -33,6 +33,7 @@ BEGIN {
 
 use Getopt::Long;
 use Pod::Usage;
+use Koha::Cron;
 use C4::Biblio;
 use C4::Items;
 use Koha::Database;
index c23341a..dfc1a2e 100755 (executable)
@@ -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;
index 89ad4a2..ac74adc 100755 (executable)
@@ -30,6 +30,7 @@ use strict;
 use warnings;
 use 5.010;
 
+use Koha::Cron;
 use C4::Context;
 use C4::Overdues;
 use Getopt::Long;
index ca99635..a0c85c8 100755 (executable)
@@ -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;
index d17dfb5..83d5d60 100755 (executable)
@@ -29,6 +29,7 @@ BEGIN {
 
 # cancel all expired hold requests
 
+use Koha::Cron;
 use C4::Reserves;
 use C4::Log;
 
index be50de7..370a9da 100755 (executable)
@@ -15,6 +15,7 @@ BEGIN {
     eval { require "$FindBin::Bin/../kohalib.pl" };
 }
 
+use Koha::Cron;
 use C4::HoldsQueue qw(CreateQueue);
 use C4::Log;
 
index f721553..6de289b 100755 (executable)
@@ -29,6 +29,7 @@ BEGIN {
 
 # cancel all expired hold requests
 
+use Koha::Cron;
 use C4::Reserves;
 use C4::Log;
 
index 8c7f928..0cae7fb 100755 (executable)
@@ -28,6 +28,7 @@ BEGIN {
 use Getopt::Long;
 use Pod::Usage;
 
+use Koha::Cron;
 use C4::Reserves;
 use C4::Log;
 use Koha::Holds;
index 0e1384f..55de9be 100755 (executable)
@@ -31,6 +31,7 @@ BEGIN {
 
 use Getopt::Long;
 use Pod::Usage;
+use Koha::Cron;
 use C4::ImportBatch;
 
 my ($help, $framework);
index ba90ad0..4fb22fa 100755 (executable)
@@ -26,6 +26,7 @@ BEGIN {
     eval { require "$FindBin::Bin/../kohalib.pl" };
 }
 
+use Koha::Cron;
 use C4::Context;
 use C4::Members;
 use Getopt::Long;
index f895f6d..82d13b1 100755 (executable)
@@ -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/;
index 1b6ea81..3ce0537 100755 (executable)
@@ -126,6 +126,7 @@ BEGIN {
     eval { require "$FindBin::Bin/../kohalib.pl" };
 }
 
+use Koha::Cron;
 use C4::Context;
 use C4::Letters;
 use C4::Log;
index 4682694..c2ef914 100755 (executable)
@@ -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);
 }
index 598ef5a..fa79e89 100755 (executable)
@@ -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;
index 8c42335..8c8f6a0 100755 (executable)
@@ -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 =~ /^-/ ) {
index 3e0ef51..c78d4c0 100755 (executable)
@@ -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;
index 58a9a1d..5553657 100755 (executable)
@@ -28,6 +28,8 @@ BEGIN {
 
 use Getopt::Long;
 use Pod::Usage;
+
+use Koha::Cron;
 use C4::Suggestions;
 use C4::Log;
 use C4::Context;
index 1bd9dc2..8ff7e85 100755 (executable)
@@ -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(
index e799ee5..a38c911 100755 (executable)
@@ -2,6 +2,7 @@
 use strict;
 use warnings;
 
+use Koha::Cron;
 use C4::Context;
 
 # this script will remove those older than 5 days
index 60e34fb..f9c5125 100755 (executable)
@@ -28,6 +28,8 @@
 use Modern::Perl;
 
 use Template;
+
+use Koha::Cron;
 use C4::Context;
 use Time::Local;
 use POSIX;
index c89a6d4..a673a5b 100755 (executable)
@@ -20,6 +20,7 @@
 
 use Modern::Perl;
 
+use Koha::Cron;
 use C4::Reports::Guided; # 0.12
 use Koha::Reports;
 use C4::Context;
index a478476..6bf40c1 100755 (executable)
@@ -28,6 +28,7 @@ BEGIN {
     eval { require "$FindBin::Bin/../kohalib.pl" };
 }
 
+use Koha::Cron;
 use C4::Context;
 use C4::Debug;
 use C4::Serials;
index 9039558..3173ab4 100755 (executable)
@@ -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;
index 80c01fd..909ad6f 100755 (executable)
@@ -23,6 +23,8 @@ use Modern::Perl;
 use utf8;
 use Pod::Usage;
 use Getopt::Long;
+
+use Koha::Cron;
 use C4::Biblio;
 use Koha::Sitemapper;
 
index 89d6b35..5bb9867 100755 (executable)
@@ -1,6 +1,8 @@
 #!/usr/bin/perl
 
 use Modern::Perl;
+
+use Koha::Cron;
 use C4::SocialData;
 
 my $results = C4::SocialData::get_report;
index 53058a7..81bc1d0 100755 (executable)
@@ -1,6 +1,8 @@
 #!/usr/bin/perl
 
 use Modern::Perl;
+
+use Koha::Cron;
 use C4::Context;
 use C4::SocialData;
 
index 5fee7f4..1d4c2dc 100755 (executable)
@@ -37,6 +37,7 @@ BEGIN {
 
 use Date::Calc qw/Date_to_Days/;
 
+use Koha::Cron;
 use C4::Context;
 use C4::Circulation;
 use C4::Overdues;
index 083c147..d178ed8 100755 (executable)
@@ -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;
index 1a70c4a..abf81cb 100755 (executable)
@@ -31,6 +31,7 @@ BEGIN {
 use Getopt::Long;
 use Pod::Usage;
 
+use Koha::Cron;
 use C4::Context;
 
 sub usage {
index d1ff392..216f39d 100755 (executable)
@@ -31,6 +31,7 @@ BEGIN {
 use Getopt::Long;
 use Pod::Usage;
 
+use Koha::Cron;
 use C4::Context;
 use C4::Items;
 use C4::Letters;
index affa2a7..667b5ac 100755 (executable)
@@ -30,6 +30,8 @@ BEGIN {
 
 use Getopt::Long;
 use Pod::Usage;
+
+use Koha::Cron;
 use C4::Context;
 use C4::Biblio;
 use C4::Log;
index e2c1825..70d9ac6 100755 (executable)
@@ -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 (file)
index 0000000..05ecd25
--- /dev/null
@@ -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 <http://www.gnu.org/licenses>.
+
+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;