From f7190f48aad671485bcf8a535bf7e48f493d8c22 Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT Date: Thu, 24 Mar 2011 09:58:12 +0100 Subject: [PATCH] Bug 5944 : (MT #3000) new cronjob script to delete old suggestions This patch is a new script that delete suggestion that have be processed by librarians. It take on argument, it's a number of days to keep suggestions. Suggestions olders than TODAY - $days will be deleted. This script should be used to purge suggestions and clean the table in intranet. Signed-off-by: Julian Maurice Signed-off-by: Chris Cormack --- C4/Suggestions.pm | 20 +++++++++- misc/cronjobs/purge_suggestions.pl | 60 ++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100755 misc/cronjobs/purge_suggestions.pl diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm index 81ff731696..9cb2c189cd 100644 --- a/C4/Suggestions.pm +++ b/C4/Suggestions.pm @@ -1,6 +1,7 @@ package C4::Suggestions; # Copyright 2000-2002 Katipo Communications +# Parts Copyright Biblibre 2011 # # This file is part of Koha. # @@ -43,9 +44,9 @@ our @EXPORT = qw< ModSuggestion NewSuggestion SearchSuggestion + DelSuggestionsOlderThan >; - =head1 NAME C4::Suggestions - Some useful functions for dealings with aqorders. @@ -429,6 +430,23 @@ sub DelSuggestion { } } +=head2 DelSuggestionsOlderThan + &DelSuggestionsOlderThan($days) + + Delete all suggestions older than TODAY-$days , that have be accepted or rejected. + +=cut +sub DelSuggestionsOlderThan { + my ($days) = @_; + return if not $days; + my $dbh = C4::Context->dbh; + + my $sth = $dbh->prepare(" + DELETE FROM suggestions WHERE STATUS <> 'ASKED' AND date < ADDDATE(NOW(), ?); + "); + $sth->execute("-$days"); +} + 1; __END__ diff --git a/misc/cronjobs/purge_suggestions.pl b/misc/cronjobs/purge_suggestions.pl new file mode 100755 index 0000000000..d38a7bf3c0 --- /dev/null +++ b/misc/cronjobs/purge_suggestions.pl @@ -0,0 +1,60 @@ +#!/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::Suggestions; + +my ($help, $days); + +GetOptions( + 'help|?' => \$help, + 'days=s' => \$days, +); + +if($help or not $days){ + print <