Lines 26-31
use constant DEFAULT_IMPORT_PURGEDAYS => 60;
Link Here
|
26 |
use constant DEFAULT_LOGS_PURGEDAYS => 180; |
26 |
use constant DEFAULT_LOGS_PURGEDAYS => 180; |
27 |
use constant DEFAULT_SEARCHHISTORY_PURGEDAYS => 30; |
27 |
use constant DEFAULT_SEARCHHISTORY_PURGEDAYS => 30; |
28 |
use constant DEFAULT_SHARE_INVITATION_EXPIRY_DAYS => 14; |
28 |
use constant DEFAULT_SHARE_INVITATION_EXPIRY_DAYS => 14; |
|
|
29 |
use constant DEFAULT_DEBARMENTS_PURGEDAYS => 30; |
29 |
|
30 |
|
30 |
BEGIN { |
31 |
BEGIN { |
31 |
# find Koha's Perl modules |
32 |
# find Koha's Perl modules |
Lines 43-49
use Getopt::Long;
Link Here
|
43 |
|
44 |
|
44 |
sub usage { |
45 |
sub usage { |
45 |
print STDERR <<USAGE; |
46 |
print STDERR <<USAGE; |
46 |
Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS] |
47 |
Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS] [--restrictions DAYS] |
47 |
|
48 |
|
48 |
-h --help prints this help message, and exits, ignoring all |
49 |
-h --help prints this help message, and exits, ignoring all |
49 |
other options |
50 |
other options |
Lines 67-72
Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueu
Link Here
|
67 |
Defaults to 30 days if no days specified |
68 |
Defaults to 30 days if no days specified |
68 |
--list-invites DAYS purge (unaccepted) list share invites older than DAYS |
69 |
--list-invites DAYS purge (unaccepted) list share invites older than DAYS |
69 |
days. Defaults to 14 days if no days specified. |
70 |
days. Defaults to 14 days if no days specified. |
|
|
71 |
--restrictions DAYS purge patrons restrictions expired since more than DAYS days. |
72 |
Defaults to 30 days if no days specified. |
70 |
USAGE |
73 |
USAGE |
71 |
exit $_[0]; |
74 |
exit $_[0]; |
72 |
} |
75 |
} |
Lines 75-81
my (
Link Here
|
75 |
$help, $sessions, $sess_days, $verbose, |
78 |
$help, $sessions, $sess_days, $verbose, |
76 |
$zebraqueue_days, $mail, $purge_merged, $pImport, |
79 |
$zebraqueue_days, $mail, $purge_merged, $pImport, |
77 |
$pLogs, $pSearchhistory, $pZ3950, |
80 |
$pLogs, $pSearchhistory, $pZ3950, |
78 |
$pListShareInvites, |
81 |
$pListShareInvites, $pDebarments, |
79 |
); |
82 |
); |
80 |
|
83 |
|
81 |
GetOptions( |
84 |
GetOptions( |
Lines 91-96
GetOptions(
Link Here
|
91 |
'logs:i' => \$pLogs, |
94 |
'logs:i' => \$pLogs, |
92 |
'searchhistory:i' => \$pSearchhistory, |
95 |
'searchhistory:i' => \$pSearchhistory, |
93 |
'list-invites:i' => \$pListShareInvites, |
96 |
'list-invites:i' => \$pListShareInvites, |
|
|
97 |
'restrictions:i' => \$pDebarments, |
94 |
) || usage(1); |
98 |
) || usage(1); |
95 |
|
99 |
|
96 |
$sessions=1 if $sess_days && $sess_days>0; |
100 |
$sessions=1 if $sess_days && $sess_days>0; |
Lines 102-107
$zebraqueue_days= DEFAULT_ZEBRAQ_PURGEDAYS if defined($zebraqueue_days) && $zebr
Link Here
|
102 |
$mail= DEFAULT_MAIL_PURGEDAYS if defined($mail) && $mail==0; |
106 |
$mail= DEFAULT_MAIL_PURGEDAYS if defined($mail) && $mail==0; |
103 |
$pSearchhistory= DEFAULT_SEARCHHISTORY_PURGEDAYS if defined($pSearchhistory) && $pSearchhistory==0; |
107 |
$pSearchhistory= DEFAULT_SEARCHHISTORY_PURGEDAYS if defined($pSearchhistory) && $pSearchhistory==0; |
104 |
$pListShareInvites = DEFAULT_SHARE_INVITATION_EXPIRY_DAYS if defined($pListShareInvites) && $pListShareInvites == 0; |
108 |
$pListShareInvites = DEFAULT_SHARE_INVITATION_EXPIRY_DAYS if defined($pListShareInvites) && $pListShareInvites == 0; |
|
|
109 |
$pDebarments = DEFAULT_DEBARMENTS_PURGEDAYS if defined($pDebarments) && $pDebarments == 0; |
105 |
|
110 |
|
106 |
if ($help) { |
111 |
if ($help) { |
107 |
usage(0); |
112 |
usage(0); |
Lines 115-121
unless ( $sessions
Link Here
|
115 |
|| $pLogs |
120 |
|| $pLogs |
116 |
|| $pSearchhistory |
121 |
|| $pSearchhistory |
117 |
|| $pZ3950 |
122 |
|| $pZ3950 |
118 |
|| $pListShareInvites ) |
123 |
|| $pListShareInvites |
|
|
124 |
|| $pDebarments ) |
119 |
{ |
125 |
{ |
120 |
print "You did not specify any cleanup work for the script to do.\n\n"; |
126 |
print "You did not specify any cleanup work for the script to do.\n\n"; |
121 |
usage(1); |
127 |
usage(1); |
Lines 224-229
if ($pListShareInvites) {
Link Here
|
224 |
print "Done with purging unaccepted list share invites.\n" if $verbose; |
230 |
print "Done with purging unaccepted list share invites.\n" if $verbose; |
225 |
} |
231 |
} |
226 |
|
232 |
|
|
|
233 |
if($pDebarments) { |
234 |
print "Expired patrons restrictions purge triggered for $pDebarments days.\n" if $verbose; |
235 |
$count = PurgeDebarments(); |
236 |
print "$count restrictions were deleted.\nDone with restrictions purge.\n" if $verbose; |
237 |
} |
238 |
|
227 |
exit(0); |
239 |
exit(0); |
228 |
|
240 |
|
229 |
sub RemoveOldSessions { |
241 |
sub RemoveOldSessions { |
Lines 279-281
sub PurgeZ3950 {
Link Here
|
279 |
}); |
291 |
}); |
280 |
$sth->execute() or die $dbh->errstr; |
292 |
$sth->execute() or die $dbh->errstr; |
281 |
} |
293 |
} |
282 |
- |
294 |
|
|
|
295 |
sub PurgeDebarments { |
296 |
require Koha::Borrower::Debarments; |
297 |
$count = 0; |
298 |
$sth = $dbh->prepare(q{ |
299 |
SELECT borrower_debarment_id FROM borrower_debarments WHERE expiration < date_sub(curdate(), INTERVAL ? DAY) |
300 |
}); |
301 |
$sth->execute($pDebarments) or die $dbh->errstr; |
302 |
while ( my ($borrower_debarment_id) = $sth->fetchrow_array ) { |
303 |
Koha::Borrower::Debarments::DelDebarment($borrower_debarment_id); |
304 |
$count++; |
305 |
} |
306 |
return $count; |
307 |
} |