From 57b6c1da363acd516daae8ac7ba7faec6cfbaadf Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Thu, 13 Feb 2020 10:43:49 +0200 Subject: [PATCH] Bug 20897: Add generic cronjob to run plugins with a cronjob method This adds a run_cronjob_plugins.pl script, which will run the cronjob-methods of the installed plugins. Test plan: 1) Enable plugins, upload the Bug20897 test plugin 2) Set up the run_cronjob_plugins.pl in cronjob 3) Check the cron logs to see the message "PLUGIN Bug20897: CRONJOB" shows up there every time the cronjob is run 4) Test that the plugins-home.pl -page can filter the cronjob plugins Signed-off-by: Pasi Kallinen --- .../prog/en/modules/plugins/plugins-home.tt | 3 + misc/cronjobs/run_cronjob_plugins.pl | 74 ++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100755 misc/cronjobs/run_cronjob_plugins.pl diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt index 5d598c525e..312f386c24 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt @@ -36,6 +36,7 @@
  • View MARC conversion plugins
  • View online payment plugins
  • View intranet catalog biblio enhancement plugins
  • +
  • View cronjob plugins
  • @@ -56,6 +57,8 @@
    No plugins that can process online payments via the public catalog are installed
    [% ELSIF method == 'intranet_catalog_biblio_enhancements' %]
    No plugins that can enhance the intranet catalog biblio records are installed
    + [% ELSIF method == 'cronjob' %] +
    No plugins that are run regularly via cronjob are installed
    [% ELSE %]
    Unknown plugin type [% method | html %]
    [% END %] diff --git a/misc/cronjobs/run_cronjob_plugins.pl b/misc/cronjobs/run_cronjob_plugins.pl new file mode 100755 index 0000000000..df75c89770 --- /dev/null +++ b/misc/cronjobs/run_cronjob_plugins.pl @@ -0,0 +1,74 @@ +#!/usr/bin/perl + +# This script runs the 'cronjob' methods of installed plugins. + +# Copyright 2020 Koha-Suomi +# +# 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 Getopt::Long; +use Pod::Usage; + +BEGIN { + + # find Koha's Perl modules + # test carefully before changing this + use FindBin; + eval { require "$FindBin::Bin/../kohalib.pl" }; +} + +use Koha::Plugins; +use C4::Context; + +my $help = 0; + +GetOptions( + 'h|help' => \$help, +); + +if ($help) { + pod2usage(1); +} else { + if ( C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins") ) { + my @plugins = Koha::Plugins->new()->GetPlugins( { method => 'cronjob' } ); + foreach my $plugin (@plugins) { + $plugin->cronjob(); + } + } else { + warn "Koha plugins not enabled."; + } +} + +=head1 NAME + +run_cronjob_plugins.pl + +=head1 DESCRIPTION + +Cron script to run the 'cronjob' methods of installed plugins. + +=head1 SYNOPSIS + +run_cronjob_plugins.pl + +run_cronjob_plugins.pl -h + +=head1 OPTIONS + +-h : this help message + +=cut -- 2.11.0