From 18a1c3db11bd2cb45c8d6937bd58149a5d8427be Mon Sep 17 00:00:00 2001 From: Robin Sheat Date: Tue, 31 Aug 2010 11:48:20 +1200 Subject: [PATCH] Bug 5139 - packages now do email and other cron jobs By default the packages now set up the cron jobs to handle things like overdues and email etc. By default, email is off, 'koha-email-enable' and 'koha-email-disable' can manage this. Signed-off-by: Chris Cormack Signed-off-by: Galen Charlton --- debian/koha-common.README.Debian | 2 ++ debian/koha-common.cron.d | 1 + debian/koha-common.cron.daily | 24 +++++++++++++++++ debian/koha-common.install | 4 ++- debian/scripts/koha-create | 6 +++++ debian/scripts/koha-email-disable | 36 +++++++++++++++++++++++++ debian/scripts/koha-email-enable | 36 +++++++++++++++++++++++++ debian/scripts/koha-enable | 0 debian/scripts/koha-foreach | 17 +++++++----- debian/scripts/koha-list | 45 ++++++++++++++++++++++++------- misc/cronjobs/cleanup_database.pl | 36 ++++++++++++++++++------- 11 files changed, 181 insertions(+), 26 deletions(-) create mode 100644 debian/koha-common.cron.daily create mode 100755 debian/scripts/koha-email-disable create mode 100755 debian/scripts/koha-email-enable mode change 100644 => 100755 debian/scripts/koha-enable diff --git a/debian/koha-common.README.Debian b/debian/koha-common.README.Debian index 42167eb5e2..ba831af848 100644 --- a/debian/koha-common.README.Debian +++ b/debian/koha-common.README.Debian @@ -33,6 +33,8 @@ The Debian packaging of Koha puts files in the following places: * /etc/koha -- system configuration files * /etc/cron.hourly/koha-common -- cron job +* /etc/cron.daily/koha-common -- cron job +* /etc/cron.d/koha-common -- cron job * /usr/share/koha -- shared files (HTML templates, Perl code, etc) Each Koha instance has files in the following places: diff --git a/debian/koha-common.cron.d b/debian/koha-common.cron.d index 715d1b06d2..cd7f3c207d 100644 --- a/debian/koha-common.cron.d +++ b/debian/koha-common.cron.d @@ -7,3 +7,4 @@ SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin */5 * * * * root test -x /usr/sbin/koha-rebuild-zebra && koha-rebuild-zebra $(koha-list --enabled) +*/15 * * * * root koha-foreach --enabled --email /usr/share/koha/bin/cronjobs/process_message_queue.pl diff --git a/debian/koha-common.cron.daily b/debian/koha-common.cron.daily new file mode 100644 index 0000000000..059682e803 --- /dev/null +++ b/debian/koha-common.cron.daily @@ -0,0 +1,24 @@ +#!/bin/sh +# /etc/cron.daily/koha-common -- Daily housekeeping tasks for all Kohas. +# Copyright 2010 Catalyst IT, Ltd +# +# This program 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. +# +# This program 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 this program. If not, see . + +koha-foreach --enabled --email /usr/share/koha/bin/cronjobs/overdue_notices.pl -t +koha-foreach --enabled /usr/share/koha/bin/cronjobs/fines.pl +koha-foreach --enabled --email /usr/share/koha/bin/cronjobs/advance_notices.pl -c +koha-foreach --enabled /usr/share/koha/bin/cronjobs/holds/cancel_expired_holds.pl >/dev/null 2>&1 +koha-foreach --enabled /usr/share/koha/bin/cronjobs/services_throttle.pl > /dev/null 2>&1 +koha-foreach --enabled /usr/share/koha/bin/cronjobs/cleanup_database.pl --sessions --zebraqueue 10 +koha-foreach --enabled --noemail /usr/share/koha/bin/cronjobs/cleanup_database.pl --mail diff --git a/debian/koha-common.install b/debian/koha-common.install index 986aa075e0..6ed2587982 100644 --- a/debian/koha-common.install +++ b/debian/koha-common.install @@ -3,7 +3,7 @@ debian/tmp/usr/* usr debian/tmp/etc/koha/pazpar2 debian/tmp/etc/koha/zebradb/[!z]* debian/templates/* etc/koha -debian/koha-post-install-setup usr/sbin +debian/koha-post-install-setup usr/sbin debian/unavailable.html usr/share/koha/intranet/htdocs debian/unavailable.html usr/share/koha/opac/htdocs debian/templates/* etc/koha @@ -12,6 +12,8 @@ debian/scripts/koha-create-dirs usr/sbin debian/scripts/koha-disable usr/sbin debian/scripts/koha-dump usr/sbin debian/scripts/koha-dump-defaults usr/sbin +debian/scripts/koha-email-disable usr/sbin +debian/scripts/koha-email-enable usr/sbin debian/scripts/koha-enable usr/sbin debian/scripts/koha-foreach usr/sbin debian/scripts/koha-list usr/sbin diff --git a/debian/scripts/koha-create b/debian/scripts/koha-create index 4f77603067..672c841de6 100755 --- a/debian/scripts/koha-create +++ b/debian/scripts/koha-create @@ -234,3 +234,9 @@ if [ "$op" = request ] then koha-disable "$name" fi + +echo <. + +set -e + +if [ "$#" = 0 ] +then + echo "Disables the email for a koha instance." 1>&2 + echo "Usage: $0 instancename..." 1>&2 + exit 1 +fi +libdir=/var/lib/koha +for name in "$@" +do + if [ ! -d $libdir/$name ] + then + echo "$0: no koha instance \"$name\"" 1>&2 + continue + fi + rm -f $libdir/$name/email.enabled +done diff --git a/debian/scripts/koha-email-enable b/debian/scripts/koha-email-enable new file mode 100755 index 0000000000..da63589ea0 --- /dev/null +++ b/debian/scripts/koha-email-enable @@ -0,0 +1,36 @@ +#!/bin/sh +# +# koha-email-enable -- turn on the email for a Koha instance +# Copyright 2010 Catalyst IT, Ltd +# +# This program 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. +# +# This program 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 this program. If not, see . + +set -e + +if [ "$#" = 0 ] +then + echo "Enables email for a koha instance." 1>&2 + echo "Usage: $0 instancename..." 1>&2 + exit 1 +fi +libdir=/var/lib/koha +for name in "$@" +do + if [ ! -d $libdir/$name ] + then + echo "$0: no koha instance \"$name\"" 1>&2 + continue + fi + touch $libdir/$name/email.enabled +done diff --git a/debian/scripts/koha-enable b/debian/scripts/koha-enable old mode 100644 new mode 100755 diff --git a/debian/scripts/koha-foreach b/debian/scripts/koha-foreach index 80152bc831..9cf150d811 100755 --- a/debian/scripts/koha-foreach +++ b/debian/scripts/koha-foreach @@ -18,15 +18,18 @@ set -e - listopts="" -if [ "$1" = --enabled ] -then - listopts="--enabled" +while [ ! -z "$1" ] +do + case "$1" in + --email) listopts="$listopts --email";; + --noemail) listopts="$listopts --noemail";; + --enabled) listopts="$listopts --enabled";; + *) break;; + esac shift -fi - - +done + for name in $(koha-list $listopts) do sudo -u "$name-koha" \ diff --git a/debian/scripts/koha-list b/debian/scripts/koha-list index af810ae40b..1e19f1afc4 100755 --- a/debian/scripts/koha-list +++ b/debian/scripts/koha-list @@ -29,19 +29,46 @@ is_enabled() { fi } -all=yes -if [ "$1" = --enabled ] -then +help() { + echo < \$help, - 'sessions' => \$sessions, + 'h|help' => \$help, + 'sessions' => \$sessions, 'v|verbose' => \$verbose, + 'm|mail' => \$mail, 'zebraqueue:i' => \$zebraqueue_days, ) || usage(1); @@ -60,7 +66,7 @@ if ($help) { usage(0); } -if (!($sessions || $zebraqueue_days)){ +if (!($sessions || $zebraqueue_days || $mail)){ print "You did not specify any cleanup work for the script to do.\n\n"; usage(1); } @@ -103,4 +109,16 @@ if ($zebraqueue_days){ print "$count records were deleted.\nDone with zebraqueue purge.\n"; } } + +if ($mail) { + if ($verbose) { + $sth = $dbh->prepare("SELECT COUNT(*) FROM message_queue"); + $sth->execute() or die $dbh->errstr; + my @count_arr = $sth->fetchrow_array; + print "Deleting $count_arr[0] entries from the mail queue.\n"; + } + $sth = $dbh->prepare("TRUNCATE message_queue"); + $sth->execute() or $dbh->errstr; + print "Done with purging the mail queue.\n" if ($verbose); +} exit(0); -- 2.39.5