From badaf236c9d49d852cb4bcb5754b9f032cd8b6c6 Mon Sep 17 00:00:00 2001 From: remi Date: Tue, 28 Jul 2015 12:10:59 -0400 Subject: [PATCH] Bug 13287: Add a system preference to define the number of days used in purge_suggestions.pl The system preferences value is used whenever purge_suggestions.pl is called without the 'days' parameter. This patch uses the preference description suggested by comment #9. This version should now be cleanly applicable. I Apply the patch II Run updatedatabase.pl a) Run purge_suggestions.pl without the days parameter - validate that there is an error message b) Run purge_suggestions.pl with the days parameter - validate that there is no error message c) Insert a number of days in the system variable PurgeSuggestionsOlderThan d) Run purge_suggestions.pl without the days parameter - validate that there is no error message Signed-off-by: Liz Rea Tested per plan, all tests pass. Signed-off-by: Marc Veron Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- installer/data/mysql/sysprefs.sql | 1 + .../en/modules/admin/preferences/opac.pref | 8 ++++ misc/cronjobs/purge_suggestions.pl | 44 ++++++++++++++----- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 8f5e94b4c4..76bb2cc03a 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -440,6 +440,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('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'), ('ProcessingFeeNote', '', NULL, 'Set the text to be recorded in the column note, table accountlines when the processing fee (defined in item type) is applied', 'textarea'), +('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/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index c44b10948b..973c86af49 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 @@ -614,6 +614,14 @@ OPAC: - pref: MaxOpenSuggestions class: integer - "open suggestions. Leave empty for no limit. **Note: this setting does not affect anonymous suggestions" + - + - Keep accepted or rejected purchase suggestions for a period of [ ] days. + - 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 cronjob purge_suggestions.pl is active and called without a specific number of days) Privacy: - - pref: StoreLastBorrower diff --git a/misc/cronjobs/purge_suggestions.pl b/misc/cronjobs/purge_suggestions.pl index ee3da2ee63..2b691708c8 100755 --- a/misc/cronjobs/purge_suggestions.pl +++ b/misc/cronjobs/purge_suggestions.pl @@ -33,6 +33,7 @@ use Getopt::Long; use Pod::Usage; use C4::Suggestions; use C4::Log; +use C4::Context; my ($help, $days); @@ -41,22 +42,41 @@ 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 ''){ cronlogaction(); 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 -- 2.39.5