From 257efcde60502ec29fbc5fae7d419247d62dfe8b Mon Sep 17 00:00:00 2001 From: simith Date: Tue, 18 Nov 2014 11:04:03 -0500 Subject: [PATCH] Add a system preference to define the number of days used in purge_suggestions.pl http://bugs.koha-community.org/show_bug.cgi?id=13287 --- installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 8 ++++ .../prog/en/modules/admin/preferences/opac.pref | 9 +++++ misc/cronjobs/purge_suggestions.pl | 45 +++++++++++++++------- 4 files changed, 50 insertions(+), 13 deletions(-) diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 4fb8cbd..285106f 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -337,6 +337,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('previousIssuesDefaultSortOrder','asc','asc|desc','Specify the sort order of Previous Issues on the circulation page','Choice'), ('printcirculationslips','1','','If ON, enable printing circulation receipts','YesNo'), ('PrintNoticesMaxLines','0','','If greater than 0, sets the maximum number of lines an overdue notice will print. If the number of items is greater than this number, the notice will end with a warning asking the borrower to check their online account for a full list of overdue items.','Integer'), +('PurgeSuggestionsOlderThan', '', NULL, 'If this script is called without the days parameter', 'Integer'), ('QueryAutoTruncate','1',NULL,'If ON, query truncation is enabled by default','YesNo'), ('QueryFuzzy','1',NULL,'If ON, enables fuzzy option for searches','YesNo'), ('QueryStemming','1',NULL,'If ON, enables query stemming','YesNo'), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index e36c20e..cfd0727 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -9525,6 +9525,14 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('PurgeSuggestionsOlderThan', '', NULL, 'If this script is called without the days parameter', 'Integer')"); + print "Upgrade to $DBversion done (Bug 13287 - Add a system preference to define the number of days used in purge_suggestions.pl)\n"; + SetVersion($DBversion); +} + + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index 45df9f8..6f461a0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -555,6 +555,15 @@ OPAC: no: "Don't block" - expired patrons from OPAC actions such as placing a hold or renewing. Note that the setting for a patron category takes priority over this system preference. + - + - Keep purchase suggestions for a period of + - pref: PurgeSuggestionsOlderThan + class: integer + - days. + -
WARNING - Leave this field empty if you don't want to activate this automatic feature. + - "
Example: [30] Sets purgation of suggestions for those older than 30 days." + -
(Used when the purge_suggestions.pl script is called with a specific number of days) + Privacy: - - pref: AnonSuggestions diff --git a/misc/cronjobs/purge_suggestions.pl b/misc/cronjobs/purge_suggestions.pl index d38a7bf..5d00e43 100755 --- a/misc/cronjobs/purge_suggestions.pl +++ b/misc/cronjobs/purge_suggestions.pl @@ -32,6 +32,7 @@ BEGIN { use Getopt::Long; use Pod::Usage; use C4::Suggestions; +use C4::Context; my ($help, $days); @@ -40,21 +41,39 @@ GetOptions( 'days=s' => \$days, ); -if($help or not $days){ - print <preference('PurgeSuggestionsOlderThan') || ''; + if($purge_sugg_days ne '' and $purge_sugg_days >= 0) { + $days = $purge_sugg_days; + } +} +# If this script is called with the 'help' parameter, we show up the help message and we leave the script without doing anything. +if ($help) { + print $usage; exit; } -if($days){ +if(defined($days) && $days > 0 && $days ne ''){ DelSuggestionsOlderThan($days); } - +elsif(defined($days) && $days == 0) { + print << 'ERROR'; + This script is not executed with 0 days. Aborted. +ERROR +} +else { + print << 'ERROR'; + This script requires a positive number of days. Aborted. +ERROR +} \ No newline at end of file -- 1.9.1