View | Details | Raw Unified | Return to bug 13166
Collapse All | Expand All

(-)a/misc/cronjobs/cleanup_database.pl (-5 / +19 lines)
Lines 69-74 Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueu Link Here
69
                         days.  Defaults to 14 days if no days specified.
69
                         days.  Defaults to 14 days if no days specified.
70
   --restrictions DAYS   purge patrons restrictions expired since more than DAYS days.
70
   --restrictions DAYS   purge patrons restrictions expired since more than DAYS days.
71
                         Defaults to 30 days if no days specified.
71
                         Defaults to 30 days if no days specified.
72
    --all-restrictions   purge all expired patrons restrictions.
72
USAGE
73
USAGE
73
    exit $_[0];
74
    exit $_[0];
74
}
75
}
Lines 76-82 USAGE Link Here
76
my (
77
my (
77
    $help,   $sessions,          $sess_days, $verbose, $zebraqueue_days,
78
    $help,   $sessions,          $sess_days, $verbose, $zebraqueue_days,
78
    $mail,   $purge_merged,      $pImport,   $pLogs,   $pSearchhistory,
79
    $mail,   $purge_merged,      $pImport,   $pLogs,   $pSearchhistory,
79
    $pZ3950, $pListShareInvites, $pDebarments,
80
    $pZ3950, $pListShareInvites, $pDebarments, $allDebarments,
80
);
81
);
81
82
82
GetOptions(
83
GetOptions(
Lines 93-98 GetOptions( Link Here
93
    'searchhistory:i' => \$pSearchhistory,
94
    'searchhistory:i' => \$pSearchhistory,
94
    'list-invites:i'  => \$pListShareInvites,
95
    'list-invites:i'  => \$pListShareInvites,
95
    'restrictions:i'  => \$pDebarments,
96
    'restrictions:i'  => \$pDebarments,
97
    'all-restrictions' => \$allDebarments,
96
) || usage(1);
98
) || usage(1);
97
99
98
# Use default values
100
# Use default values
Lines 118-129 unless ( $sessions Link Here
118
    || $pSearchhistory
120
    || $pSearchhistory
119
    || $pZ3950
121
    || $pZ3950
120
    || $pListShareInvites
122
    || $pListShareInvites
121
    || $pDebarments )
123
    || $pDebarments
124
    || $allDebarments )
122
{
125
{
123
    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";
124
    usage(1);
127
    usage(1);
125
}
128
}
126
129
130
if ($pDebarments && $allDebarments) {
131
    print "You can not specify both --restrictions and --all-restrictions.\n\n";
132
    usage(1);
133
}
134
127
my $dbh = C4::Context->dbh();
135
my $dbh = C4::Context->dbh();
128
my $sth;
136
my $sth;
129
my $sth2;
137
my $sth2;
Lines 234-243 if ($pListShareInvites) { Link Here
234
242
235
if ($pDebarments) {
243
if ($pDebarments) {
236
    print "Expired patrons restrictions purge triggered for $pDebarments days.\n" if $verbose;
244
    print "Expired patrons restrictions purge triggered for $pDebarments days.\n" if $verbose;
237
    $count = PurgeDebarments();
245
    $count = PurgeDebarments($pDebarments);
238
    print "$count restrictions were deleted.\nDone with restrictions purge.\n" if $verbose;
246
    print "$count restrictions were deleted.\nDone with restrictions purge.\n" if $verbose;
239
}
247
}
240
248
249
if($allDebarments) {
250
    print "All expired patrons restrictions purge triggered.\n" if $verbose;
251
    $count = PurgeDebarments(0);
252
    print "$count restrictions were deleted.\nDone with all restrictions purge.\n" if $verbose;
253
}
254
241
exit(0);
255
exit(0);
242
256
243
sub RemoveOldSessions {
257
sub RemoveOldSessions {
Lines 309-314 sub PurgeZ3950 { Link Here
309
323
310
sub PurgeDebarments {
324
sub PurgeDebarments {
311
    require Koha::Borrower::Debarments;
325
    require Koha::Borrower::Debarments;
326
    my $days = shift;
312
    $count = 0;
327
    $count = 0;
313
    $sth   = $dbh->prepare(
328
    $sth   = $dbh->prepare(
314
        q{
329
        q{
Lines 317-323 sub PurgeDebarments { Link Here
317
            WHERE expiration < date_sub(curdate(), INTERVAL ? DAY)
332
            WHERE expiration < date_sub(curdate(), INTERVAL ? DAY)
318
        }
333
        }
319
    );
334
    );
320
    $sth->execute($pDebarments) or die $dbh->errstr;
335
    $sth->execute($days) or die $dbh->errstr;
321
    while ( my ($borrower_debarment_id) = $sth->fetchrow_array ) {
336
    while ( my ($borrower_debarment_id) = $sth->fetchrow_array ) {
322
        Koha::Borrower::Debarments::DelDebarment($borrower_debarment_id);
337
        Koha::Borrower::Debarments::DelDebarment($borrower_debarment_id);
323
        $count++;
338
        $count++;
324
- 

Return to bug 13166