[Koha-patches] [PATCH] Bug 6090: Empty mails in message_queue are sent

Julian Maurice julian.maurice at biblibre.com
Wed Apr 6 15:56:12 CEST 2011


From: Sophie Meynieux <sophie.meynieux at biblibre.com>

Add a new script to purge message_queue table. This script should be run before process_message_queue.pl

BibLibre MT4764
---
 C4/Letters.pm                        |   19 ++++++++++-
 misc/cronjobs/purge_message_queue.pl |   58 ++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 1 deletions(-)
 create mode 100644 misc/cronjobs/purge_message_queue.pl

diff --git a/C4/Letters.pm b/C4/Letters.pm
index 34e3686..a439036 100644
--- a/C4/Letters.pm
+++ b/C4/Letters.pm
@@ -42,7 +42,7 @@ BEGIN {
 	$VERSION = 3.01;
 	@ISA = qw(Exporter);
 	@EXPORT = qw(
-	&GetLetters &getletter &addalert &getalert &delalert &findrelatedto &SendAlerts GetPrintMessages
+	&GetLetters &getletter &addalert &getalert &delalert &findrelatedto &SendAlerts &GetPrintMessages &DelEmptyMessages
 	);
 }
 
@@ -710,6 +710,23 @@ ENDSQL
     return $sth->fetchall_arrayref({});
 }
 
+
+=head2 DelEmptyMessages
+    &DelcwEmptyMessages()
+    
+    Delete all messages without subjet nor content
+    
+=cut
+sub DelEmptyMessages {
+    my $dbh = C4::Context->dbh;
+
+    my $sth = $dbh->prepare("
+        DELETE FROM message_queue WHERE subject is null and content is null;
+    ");
+    $sth->execute();
+}
+
+
 =head2 _add_attachements
 
 named parameters:
diff --git a/misc/cronjobs/purge_message_queue.pl b/misc/cronjobs/purge_message_queue.pl
new file mode 100644
index 0000000..9a532da
--- /dev/null
+++ b/misc/cronjobs/purge_message_queue.pl
@@ -0,0 +1,58 @@
+
+#!/usr/bin/perl -w
+
+# Copyright 2010 Biblibre SARL
+#
+# 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 2 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 strict;
+use warnings;
+use utf8;
+
+BEGIN {
+
+    # find Koha's Perl modules
+    # test carefully before changing this
+    use FindBin;
+    eval { require "$FindBin::Bin/../kohalib.pl" };
+}
+
+use Getopt::Long;
+use Pod::Usage;
+use C4::Letters;
+
+my ($help);
+
+GetOptions(
+    'help|?'         => \$help
+);
+
+if($help){
+    print <<EOF
+    This script delete message without subject nor content.
+    It has to be run before sending messages.
+    Parameters :
+    -help|? This message
+
+     example :
+     export PERL5LIB=/path/to/koha;export KOHA_CONF=/etc/koha/koha-conf.xml;./purge_message_queue.pl
+EOF
+;
+    exit;
+}
+
+DelEmptyMessages();
+
-- 
1.7.4.1



More information about the Koha-patches mailing list