Lines 18-27
Link Here
|
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
use utf8; |
|
|
22 |
|
21 |
|
23 |
BEGIN { |
22 |
BEGIN { |
24 |
|
|
|
25 |
# find Koha's Perl modules |
23 |
# find Koha's Perl modules |
26 |
# test carefully before changing this |
24 |
# test carefully before changing this |
27 |
use FindBin; |
25 |
use FindBin; |
Lines 34-81
use C4::Suggestions;
Link Here
|
34 |
use C4::Log; |
32 |
use C4::Log; |
35 |
use C4::Context; |
33 |
use C4::Context; |
36 |
|
34 |
|
37 |
my ( $help, $days ); |
35 |
my ( $help, $days, $confirm ); |
38 |
|
36 |
|
39 |
GetOptions( |
37 |
GetOptions( |
40 |
'help|?' => \$help, |
38 |
'help|?' => \$help, |
41 |
'days=s' => \$days, |
39 |
'days:i' => \$days, |
|
|
40 |
'confirm'=> \$confirm, |
42 |
); |
41 |
); |
43 |
|
42 |
|
44 |
my $usage = << 'ENDUSAGE'; |
43 |
my $usage = << 'ENDUSAGE'; |
45 |
This script delete old suggestions |
44 |
This script deletes old suggestions |
46 |
Parameters: |
45 |
Parameters: |
47 |
-help|? This message |
46 |
-help|? This message |
48 |
-days TTT to define the age of suggestions to delete |
47 |
-days TTT to define the age of suggestions to delete |
|
|
48 |
-confirm flag needed to confirm purge operation |
49 |
|
50 |
The days parameter falls back to the value of system preference |
51 |
PurgeSuggestionsOlderThan. Suggestions are deleted only for a positive |
52 |
number of days. |
49 |
|
53 |
|
50 |
Example: |
54 |
Example: |
51 |
ENDUSAGE |
55 |
ENDUSAGE |
52 |
$usage .= $0 . " -days 30\n"; |
56 |
$usage .= $0 . " -confirm -days 30\n"; |
53 |
|
57 |
|
54 |
# If this script is called without the 'days' parameter, we use the system preferences value instead. |
58 |
# If this script is called without the 'days' parameter, we use the system preferences value instead. |
55 |
if ( !defined($days) && !$help ) { |
59 |
$days = C4::Context->preference('PurgeSuggestionsOlderThan') if !defined($days); |
56 |
my $purge_sugg_days = |
|
|
57 |
C4::Context->preference('PurgeSuggestionsOlderThan') || q{}; |
58 |
if ( $purge_sugg_days ne q{} and $purge_sugg_days >= 0 ) { |
59 |
$days = $purge_sugg_days; |
60 |
} |
61 |
} |
62 |
|
60 |
|
63 |
# If this script is called with the 'help' parameter, we show up the help message and we leave the script without doing anything. |
61 |
# If this script is called with the 'help' parameter, we show up the help message and we leave the script without doing anything. |
64 |
if ($help) { |
62 |
if( !$confirm || $help || !defined($days) ) { |
|
|
63 |
print "No confirm parameter passed!\n\n" if !$confirm && !$help; |
65 |
print $usage; |
64 |
print $usage; |
66 |
exit; |
65 |
} elsif( $days > 0 ) { |
67 |
} |
|
|
68 |
|
69 |
if ( defined($days) && $days ne q{} && $days > 0 ) { |
70 |
cronlogaction(); |
66 |
cronlogaction(); |
71 |
DelSuggestionsOlderThan($days); |
67 |
DelSuggestionsOlderThan($days); |
72 |
} |
68 |
} else { |
73 |
elsif (!defined($days)){ |
|
|
74 |
print $usage; |
75 |
} |
76 |
elsif ( $days == 0 ) { |
77 |
warn "This script is not executed with 0 days. Aborted.\n"; |
78 |
} |
79 |
else { |
80 |
warn "This script requires a positive number of days. Aborted.\n"; |
69 |
warn "This script requires a positive number of days. Aborted.\n"; |
81 |
} |
70 |
} |
82 |
- |
|
|