[Koha-patches] [PATCH] Bug 5139 - packages now do email and other cron jobs

Chris Cormack chrisc at catalyst.net.nz
Tue Aug 31 01:48:20 CEST 2010


From: Robin Sheat <robin at catalyst.net.nz>

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 <chrisc at catalyst.net.nz>
---
 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-foreach       |   17 ++++++++-----
 debian/scripts/koha-list          |   45 +++++++++++++++++++++++++++++-------
 misc/cronjobs/cleanup_database.pl |   36 ++++++++++++++++++++++-------
 10 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 42167eb..ba831af 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 715d1b0..cd7f3c2 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 0000000..059682e
--- /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 <http://www.gnu.org/licenses/>.
+
+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 986aa07..6ed2587 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 43e7c4e..16786f7 100755
--- a/debian/scripts/koha-create
+++ b/debian/scripts/koha-create
@@ -233,3 +233,9 @@ if [ "$op" = request ]
 then
     koha-disable "$name"
 fi
+
+echo <<eoh
+
+Email for this instance is disabled. When you're ready to enable it, use:
+koha-email-enable $name
+eoh
diff --git a/debian/scripts/koha-email-disable b/debian/scripts/koha-email-disable
new file mode 100755
index 0000000..5d381cb
--- /dev/null
+++ b/debian/scripts/koha-email-disable
@@ -0,0 +1,36 @@
+#!/bin/sh
+#
+# koha-email-disable -- turn off 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 <http://www.gnu.org/licenses/>.
+
+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 0000000..da63589
--- /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 <http://www.gnu.org/licenses/>.
+
+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 80152bc..9cf150d 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 af810ae..1e19f1a 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 <<eoh
+Lists Koha instances, optionally only those that are enabled or have
+email turned on.
+    
+Usage: $0 [--enabled] [--email] [-h]
+Options:
+    --enabled       only show instances that are enabled
+    --email         only show instances that have email enabled
+    --noemail       only show instances that do not have email enabled
+    -h              this help
+
+The filtering options can be combined, and you probably want to do this
+(except --email and --noemail, that's just silly.)
+eoh
+}
+
+enabled=no
+email=no
+noemail=no
+args=$(getopt -l enabled,email,noemail -o h -n $0 -- "$@")
+set -- $args
+while [ ! -z "$1" ]
+do
+    case "$1" in
+         -h) help; exit;;
+    --email) email=yes;;
+  --enabled) enabled=yes;;
+  --noemail) noemail=yes;;
+          *) break;;
+    esac
     shift
-    all=no
-fi
+done
 
 find /etc/koha/sites -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | 
 sort |
 while read name
 do
-    if [ "$all" = yes ] || is_enabled "$name"
-    then
-        echo "$name"
-    fi
+    [ "$enabled" = yes ] && ! is_enabled "$name" && continue
+    [ "$email" = yes ] && [ ! -e /var/lib/koha/$name/email.enabled ] && continue
+    [ "$noemail" = yes ] && [ -e /var/lib/koha/$name/email.enabled ] && continue
+    echo "$name"
 done
diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl
index 20481f5..f811b24 100755
--- a/misc/cronjobs/cleanup_database.pl
+++ b/misc/cronjobs/cleanup_database.pl
@@ -38,21 +38,27 @@ use Getopt::Long;
 sub usage {
     print STDERR <<USAGE;
 Usage: $0 [-h|--help] [--sessions] [-v|--verbose] [--zebraqueue DAYS]
-   -h --help         prints this help message, and exits, ignoring all other options
-   --sessions        purge the sessions table.  If you use this while users are logged
-                     into Koha, they will have to reconnect.
-   -v --verbose      will cause the script to give you a bit more information about the run.
-   --zebraqueue DAYS purge completed entries from the zebraqueue from more than DAYS days ago.
+        [-m|--mail]
+   -h --help          prints this help message, and exits, ignoring all
+                      other options
+   --sessions         purge the sessions table.  If you use this while users 
+                      are logged into Koha, they will have to reconnect.
+   -v --verbose       will cause the script to give you a bit more information
+                      about the run.
+   --zebraqueue DAYS  purge completed entries from the zebraqueue from 
+                      more than DAYS days ago.
+   -m --mail          purge the mail queue. 
 USAGE
     exit $_[0];
 }
 
-my ($help, $sessions, $verbose, $zebraqueue_days);
+my ($help, $sessions, $verbose, $zebraqueue_days, $mail);
 
 GetOptions(
-    'h|help' => \$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);
-- 
1.7.0.4



More information about the Koha-patches mailing list