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

(-)a/misc/cronjobs/cleanup_database.pl (-69 / +137 lines)
Lines 50-59 use Koha::Item::Transfers; Link Here
50
50
51
sub usage {
51
sub usage {
52
    print STDERR <<USAGE;
52
    print STDERR <<USAGE;
53
Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS] [--restrictions DAYS] [--all-restrictions] [--fees DAYS] [--temp-uploads] [--temp-uploads-days DAYS] [--uploads-missing 0|1 ] [--statistics DAYS] [--deleted-catalog DAYS] [--deleted-patrons DAYS] [--old-issues DAYS] [--old-reserves DAYS] [--transfers DAYS]
53
Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS] [--restrictions DAYS] [--all-restrictions] [--fees DAYS] [--temp-uploads] [--temp-uploads-days DAYS] [--uploads-missing 0|1 ] [--statistics DAYS] [--deleted-catalog DAYS] [--deleted-patrons DAYS] [--old-issues DAYS] [--old-reserves DAYS] [--transfers DAYS]
54
54
55
   -h --help          prints this help message, and exits, ignoring all
55
   -h --help          prints this help message, and exits, ignoring all
56
                      other options
56
                      other options
57
   --confirm          Confirmation flag, the script will be running in dry-run mode is not set.
57
   --sessions         purge the sessions table.  If you use this while users 
58
   --sessions         purge the sessions table.  If you use this while users 
58
                      are logged into Koha, they will have to reconnect.
59
                      are logged into Koha, they will have to reconnect.
59
   --sessdays DAYS    purge only sessions older than DAYS days.
60
   --sessdays DAYS    purge only sessions older than DAYS days.
Lines 108-113 USAGE Link Here
108
}
109
}
109
110
110
my $help;
111
my $help;
112
my $confirm;
111
my $sessions;
113
my $sessions;
112
my $sess_days;
114
my $sess_days;
113
my $verbose;
115
my $verbose;
Lines 140-145 my ( $pPseudoTransactions, $pPseudoTransactionsFrom, $pPseudoTransactionsTo ); Link Here
140
142
141
GetOptions(
143
GetOptions(
142
    'h|help'            => \$help,
144
    'h|help'            => \$help,
145
    'confirm'           => \$confirm,
143
    'sessions'          => \$sessions,
146
    'sessions'          => \$sessions,
144
    'sessdays:i'        => \$sess_days,
147
    'sessdays:i'        => \$sess_days,
145
    'v|verbose'         => \$verbose,
148
    'v|verbose'         => \$verbose,
Lines 225-231 if ($pDebarments && $allDebarments) { Link Here
225
    usage(1);
228
    usage(1);
226
}
229
}
227
230
228
cronlogaction();
231
say "Confirm flag not passed, running in dry-run mode..." unless $confirm;
232
233
cronlogaction() unless $confirm;
229
234
230
my $dbh = C4::Context->dbh();
235
my $dbh = C4::Context->dbh();
231
my $sth;
236
my $sth;
Lines 240-254 if ( $sessions && !$sess_days ) { Link Here
240
        my @count_arr = $sth->fetchrow_array;
245
        my @count_arr = $sth->fetchrow_array;
241
        print "$count_arr[0] entries will be deleted.\n";
246
        print "$count_arr[0] entries will be deleted.\n";
242
    }
247
    }
243
    $sth = $dbh->prepare(q{ TRUNCATE sessions });
248
    if ( $confirm ) {
244
    $sth->execute() or die $dbh->errstr;
249
        $sth = $dbh->prepare(q{ TRUNCATE sessions });
250
        $sth->execute() or die $dbh->errstr;
251
    }
245
    if ($verbose) {
252
    if ($verbose) {
246
        print "Done with session purge.\n";
253
        print "Done with session purge.\n";
247
    }
254
    }
248
}
255
}
249
elsif ( $sessions && $sess_days > 0 ) {
256
elsif ( $sessions && $sess_days > 0 ) {
250
    print "Session purge triggered with days>$sess_days.\n" if $verbose;
257
    print "Session purge triggered with days>$sess_days.\n" if $verbose;
251
    RemoveOldSessions();
258
    RemoveOldSessions() if $confirm;
252
    print "Done with session purge with days>$sess_days.\n" if $verbose;
259
    print "Done with session purge with days>$sess_days.\n" if $verbose;
253
}
260
}
254
261
Lines 262-271 if ($zebraqueue_days) { Link Here
262
            WHERE done=1 AND time < date_sub(curdate(), INTERVAL ? DAY)
269
            WHERE done=1 AND time < date_sub(curdate(), INTERVAL ? DAY)
263
        }
270
        }
264
    );
271
    );
265
    $sth->execute($zebraqueue_days) or die $dbh->errstr;
272
    if ( $confirm ) {
273
        $sth->execute($zebraqueue_days) or die $dbh->errstr;
274
    }
266
    $sth2 = $dbh->prepare(q{ DELETE FROM zebraqueue WHERE id=? });
275
    $sth2 = $dbh->prepare(q{ DELETE FROM zebraqueue WHERE id=? });
267
    while ( my $record = $sth->fetchrow_hashref ) {
276
    while ( my $record = $sth->fetchrow_hashref ) {
268
        $sth2->execute( $record->{id} ) or die $dbh->errstr;
277
        if ( $confirm ) {
278
            $sth2->execute( $record->{id} ) or die $dbh->errstr;
279
        }
269
        $count++;
280
        $count++;
270
    }
281
    }
271
    print "$count records were deleted.\nDone with zebraqueue purge.\n" if $verbose;
282
    print "$count records were deleted.\nDone with zebraqueue purge.\n" if $verbose;
Lines 279-306 if ($mail) { Link Here
279
            WHERE time_queued < date_sub(curdate(), INTERVAL ? DAY)
290
            WHERE time_queued < date_sub(curdate(), INTERVAL ? DAY)
280
        }
291
        }
281
    );
292
    );
282
    $sth->execute($mail) or die $dbh->errstr;
293
    if ( $confirm ) {
283
    $count = $sth->rows;
294
        $sth->execute($mail) or die $dbh->errstr;
284
    $sth->finish;
295
        $count = $sth->rows;
296
    }
285
    print "$count messages were deleted from the mail queue.\nDone with message_queue purge.\n" if $verbose;
297
    print "$count messages were deleted from the mail queue.\nDone with message_queue purge.\n" if $verbose;
286
}
298
}
287
299
288
if ($purge_merged) {
300
if ($purge_merged) {
289
    print "Purging completed entries from need_merge_authorities.\n" if $verbose;
301
    print "Purging completed entries from need_merge_authorities.\n" if $verbose;
290
    $sth = $dbh->prepare(q{ DELETE FROM need_merge_authorities WHERE done=1 });
302
    if ( $confirm ) {
291
    $sth->execute() or die $dbh->errstr;
303
        $sth = $dbh->prepare(q{ DELETE FROM need_merge_authorities WHERE done=1 });
304
        $sth->execute() or die $dbh->errstr;
305
    }
292
    print "Done with purging need_merge_authorities.\n" if $verbose;
306
    print "Done with purging need_merge_authorities.\n" if $verbose;
293
}
307
}
294
308
295
if ($pImport) {
309
if ($pImport) {
296
    print "Purging records from import tables.\n" if $verbose;
310
    print "Purging records from import tables.\n" if $verbose;
297
    PurgeImportTables();
311
    PurgeImportTables() if $confirm;
298
    print "Done with purging import tables.\n" if $verbose;
312
    print "Done with purging import tables.\n" if $verbose;
299
}
313
}
300
314
301
if ($pZ3950) {
315
if ($pZ3950) {
302
    print "Purging Z39.50 records from import tables.\n" if $verbose;
316
    print "Purging Z39.50 records from import tables.\n" if $verbose;
303
    PurgeZ3950();
317
    PurgeZ3950() if $confirm;
304
    print "Done with purging Z39.50 records from import tables.\n" if $verbose;
318
    print "Done with purging Z39.50 records from import tables.\n" if $verbose;
305
}
319
}
306
320
Lines 312-330 if ($pLogs) { Link Here
312
            WHERE timestamp < date_sub(curdate(), INTERVAL ? DAY)
326
            WHERE timestamp < date_sub(curdate(), INTERVAL ? DAY)
313
        }
327
        }
314
    );
328
    );
315
    $sth->execute($pLogs) or die $dbh->errstr;
329
    if ( $confirm ) {
330
        $sth->execute($pLogs) or die $dbh->errstr;
331
    }
316
    print "Done with purging action_logs.\n" if $verbose;
332
    print "Done with purging action_logs.\n" if $verbose;
317
}
333
}
318
334
319
if ($fees_days) {
335
if ($fees_days) {
320
    print "Purging records from accountlines.\n" if $verbose;
336
    print "Purging records from accountlines.\n" if $verbose;
321
    purge_zero_balance_fees( $fees_days );
337
    purge_zero_balance_fees( $fees_days ) if $confirm;
322
    print "Done purging records from accountlines.\n" if $verbose;
338
    print "Done purging records from accountlines.\n" if $verbose;
323
}
339
}
324
340
325
if ($pSearchhistory) {
341
if ($pSearchhistory) {
326
    print "Purging records older than $pSearchhistory from search_history.\n" if $verbose;
342
    print "Purging records older than $pSearchhistory from search_history.\n" if $verbose;
327
    C4::Search::History::delete({ interval => $pSearchhistory });
343
    C4::Search::History::delete({ interval => $pSearchhistory }) if $confirm;
328
    print "Done with purging search_history.\n" if $verbose;
344
    print "Done with purging search_history.\n" if $verbose;
329
}
345
}
330
346
Lines 337-465 if ($pListShareInvites) { Link Here
337
            AND (sharedate + INTERVAL ? DAY) < NOW()
353
            AND (sharedate + INTERVAL ? DAY) < NOW()
338
        }
354
        }
339
    );
355
    );
340
    $sth->execute($pListShareInvites);
356
    if ( $confirm ) {
357
        $sth->execute($pListShareInvites);
358
    }
341
    print "Done with purging unaccepted list share invites.\n" if $verbose;
359
    print "Done with purging unaccepted list share invites.\n" if $verbose;
342
}
360
}
343
361
344
if ($pDebarments) {
362
if ($pDebarments) {
345
    print "Expired patrons restrictions purge triggered for $pDebarments days.\n" if $verbose;
363
    print "Expired patrons restrictions purge triggered for $pDebarments days.\n" if $verbose;
346
    $count = PurgeDebarments($pDebarments);
364
    $count = PurgeDebarments($pDebarments, $confirm);
347
    print "$count restrictions were deleted.\nDone with restrictions purge.\n" if $verbose;
365
    print "$count restrictions were deleted.\nDone with restrictions purge.\n" if $verbose;
348
}
366
}
349
367
350
if($allDebarments) {
368
if($allDebarments) {
351
    print "All expired patrons restrictions purge triggered.\n" if $verbose;
369
    print "All expired patrons restrictions purge triggered.\n" if $verbose;
352
    $count = PurgeDebarments(0);
370
    $count = PurgeDebarments(0, $confirm);
353
    print "$count restrictions were deleted.\nDone with all restrictions purge.\n" if $verbose;
371
    print "$count restrictions were deleted.\nDone with all restrictions purge.\n" if $verbose;
354
}
372
}
355
373
356
# Handle unsubscribe requests from GDPR consent form, depends on UnsubscribeReflectionDelay preference
374
# Handle unsubscribe requests from GDPR consent form, depends on UnsubscribeReflectionDelay preference
357
my $unsubscribed_patrons = Koha::Patrons->search_unsubscribed;
375
my $unsubscribed_patrons = Koha::Patrons->search_unsubscribed;
358
$count = $unsubscribed_patrons->count;
376
$count = $unsubscribed_patrons->count;
359
$unsubscribed_patrons->lock( { expire => 1, remove => 1 } );
377
$unsubscribed_patrons->lock( { expire => 1, remove => 1 } ) if $confirm;
360
say sprintf "Locked %d patrons", $count if $verbose;
378
say sprintf "Locked %d patrons", $count if $verbose;
361
379
362
# Anonymize patron data, depending on PatronAnonymizeDelay
380
# Anonymize patron data, depending on PatronAnonymizeDelay
363
my $anonymize_candidates = Koha::Patrons->search_anonymize_candidates( { locked => 1 } );
381
my $anonymize_candidates = Koha::Patrons->search_anonymize_candidates( { locked => 1 } );
364
$count = $anonymize_candidates->count;
382
$count = $anonymize_candidates->count;
365
$anonymize_candidates->anonymize;
383
$anonymize_candidates->anonymize if $confirm;
366
say sprintf "Anonymized %s patrons", $count if $verbose;
384
say sprintf "Anonymized %s patrons", $count if $verbose;
367
385
368
# Remove patron data, depending on PatronRemovalDelay (will raise an exception if problem encountered
386
# Remove patron data, depending on PatronRemovalDelay (will raise an exception if problem encountered
369
my $anonymized_patrons = Koha::Patrons->search_anonymized;
387
my $anonymized_patrons = Koha::Patrons->search_anonymized;
370
$count = $anonymized_patrons->count;
388
$count = $anonymized_patrons->count;
371
$anonymized_patrons->delete( { move => 1 } );
389
if ( $confirm ) {
372
if ($@) {
390
    $anonymized_patrons->delete( { move => 1 } );
373
    warn $@;
391
    if ($@) {
374
}
392
        warn $@;
375
elsif ($verbose) {
393
    }
394
    elsif ($verbose) {
395
        say sprintf "Deleted %d patrons", $count;
396
    }
397
} else {
376
    say sprintf "Deleted %d patrons", $count;
398
    say sprintf "Deleted %d patrons", $count;
377
}
399
}
378
400
401
# FIXME The output for dry-run mode needs to be improved
402
# But non trivial changes to C4::Members need to be done before.
379
if( $pExpSelfReg ) {
403
if( $pExpSelfReg ) {
380
    DeleteExpiredSelfRegs();
404
    if ( $confirm ) {
405
        DeleteExpiredSelfRegs();
406
    } elsif ( $verbose ) {
407
        say "self-registered borrowers may be deleted";
408
    }
381
}
409
}
382
if( $pUnvSelfReg ) {
410
if( $pUnvSelfReg ) {
383
    DeleteUnverifiedSelfRegs( $pUnvSelfReg );
411
    if ( $confirm ) {
412
        DeleteUnverifiedSelfRegs( $pUnvSelfReg );
413
    } elsif ( $verbose ) {
414
        say "unverified self-registrations may be deleted";
415
    }
384
}
416
}
385
417
386
if ($special_holidays_days) {
418
if ($special_holidays_days) {
387
    DeleteSpecialHolidays( abs($special_holidays_days) );
419
    if ( $confirm ) {
420
        DeleteSpecialHolidays( abs($special_holidays_days) );
421
    } elsif ( $verbose ) {
422
        say "self-registered borrowers may be deleted";
423
    }
388
}
424
}
389
425
390
if( $temp_uploads ) {
426
if( $temp_uploads ) {
391
    # Delete temporary uploads, governed by a pref (unless you override)
427
    # Delete temporary uploads, governed by a pref (unless you override)
392
    print "Purging temporary uploads.\n" if $verbose;
428
    print "Purging temporary uploads.\n" if $verbose;
393
    Koha::UploadedFiles->delete_temporary({
429
    if ( $confirm ) {
394
        defined($temp_uploads_days)
430
        Koha::UploadedFiles->delete_temporary({
395
            ? ( override_pref => $temp_uploads_days )
431
            defined($temp_uploads_days)
396
            : ()
432
                ? ( override_pref => $temp_uploads_days )
397
    });
433
                : ()
434
        });
435
    }
398
    print "Done purging temporary uploads.\n" if $verbose;
436
    print "Done purging temporary uploads.\n" if $verbose;
399
}
437
}
400
438
401
if( defined $uploads_missing ) {
439
if( defined $uploads_missing ) {
402
    print "Looking for missing uploads\n" if $verbose;
440
    print "Looking for missing uploads\n" if $verbose;
403
    my $keep = $uploads_missing == 1 ? 0 : 1;
441
    if ( $confirm ) {
404
    my $count = Koha::UploadedFiles->delete_missing({ keep_record => $keep });
442
        my $keep = $uploads_missing == 1 ? 0 : 1;
405
    if( $keep ) {
443
        my $count = Koha::UploadedFiles->delete_missing({ keep_record => $keep });
406
        print "Counted $count missing uploaded files\n";
444
        if( $keep ) {
445
            print "Counted $count missing uploaded files\n";
446
        } else {
447
            print "Removed $count records for missing uploads\n";
448
        }
407
    } else {
449
    } else {
408
        print "Removed $count records for missing uploads\n";
450
        # FIXME need to create a filter_by_missing method (then call ->delete) instead of delete_missing
451
        say "Dry-run mode cannot guess how many uploads would have been deleted";
409
    }
452
    }
410
}
453
}
411
454
412
if ($oauth_tokens) {
455
if ($oauth_tokens) {
413
    require Koha::OAuthAccessTokens;
456
    require Koha::OAuthAccessTokens;
414
457
415
    my $count = int Koha::OAuthAccessTokens->search({ expires => { '<=', time } })->delete;
458
    my $tokens = Koha::OAuthAccessTokens->search({ expires => { '<=', time } });
416
    say "Removed $count expired OAuth2 tokens" if $verbose;
459
    my $count = $tokens->count;
460
    $tokens->delete if $confirm;
461
    say sprintf "Removed %s expired OAuth2 tokens", $count if $verbose;
417
}
462
}
418
463
419
if ($pStatistics) {
464
if ($pStatistics) {
420
    print "Purging statistics older than $pStatistics days.\n" if $verbose;
465
    print "Purging statistics older than $pStatistics days.\n" if $verbose;
421
    Koha::Statistics->filter_by_last_update(
466
    my $statistics = Koha::Statistics->filter_by_last_update(
422
        { timestamp_column_name => 'datetime', days => $pStatistics } )->delete;
467
        { timestamp_column_name => 'datetime', days => $pStatistics } );
423
    print "Done with purging statistics.\n" if $verbose;
468
    my $count = $statistics->count;
469
    $statistics->delete if $confirm;
470
    say sprintf "Done with purging %s statistics.", $count if $verbose;
424
}
471
}
425
472
426
if ($pDeletedCatalog) {
473
if ($pDeletedCatalog) {
427
    print "Purging deleted catalog older than $pDeletedCatalog days.\n" if $verbose;
474
    print "Purging deleted catalog older than $pDeletedCatalog days.\n"
428
    Koha::Old::Items      ->filter_by_last_update( { days => $pDeletedCatalog } )->delete;
475
      if $verbose;
429
    Koha::Old::Biblioitems->filter_by_last_update( { days => $pDeletedCatalog } )->delete;
476
    my $old_items = Koha::Old::Items->filter_by_last_update( { days => $pDeletedCatalog } );
430
    Koha::Old::Biblios    ->filter_by_last_update( { days => $pDeletedCatalog } )->delete;
477
    my $old_biblioitems = Koha::Old::Biblioitems->filter_by_last_update( { days => $pDeletedCatalog } );
431
    print "Done with purging deleted catalog.\n" if $verbose;
478
    my $old_biblios = Koha::Old::Biblios->filter_by_last_update( { days => $pDeletedCatalog } );
479
    my ( $c_i, $c_bi, $c_b ) =
480
      ( $old_items->count, $old_biblioitems->count, $old_biblios->count );
481
    if ($confirm) {
482
        $old_items->delete;
483
        $old_biblioitems->delete;
484
        $old_biblios->delete;
485
    }
486
    say sprintf
487
        "Done with purging deleted catalog (%d items, %d biblioitems, %d biblios).",
488
      $c_i, $c_bi, $c_b
489
      if $verbose;
432
}
490
}
433
491
434
if ($pDeletedPatrons) {
492
if ($pDeletedPatrons) {
435
    print "Purging deleted patrons older than $pDeletedPatrons days.\n" if $verbose;
493
    print "Purging deleted patrons older than $pDeletedPatrons days.\n" if $verbose;
436
    Koha::Old::Patrons->filter_by_last_update(
494
    my $old_patrons = Koha::Old::Patrons->filter_by_last_update(
437
        { timestamp_column_name => 'updated_on', days => $pDeletedPatrons } )
495
        { timestamp_column_name => 'updated_on', days => $pDeletedPatrons } );
438
      ->delete;
496
    my $count = $old_patrons->count;
439
    print "Done with purging deleted patrons.\n" if $verbose;
497
    $old_patrons->delete if $confirm;
498
    say sprintf "Done with purging %d deleted patrons.", $count if $verbose;
440
}
499
}
441
500
442
if ($pOldIssues) {
501
if ($pOldIssues) {
443
    print "Purging old issues older than $pOldIssues days.\n" if $verbose;
502
    print "Purging old issues older than $pOldIssues days.\n" if $verbose;
444
    Koha::Old::Checkouts->filter_by_last_update( { days => $pOldIssues } )->delete;
503
    my $old_checkouts = Koha::Old::Checkouts->filter_by_last_update( { days => $pOldIssues } );
445
    print "Done with purging old issues.\n" if $verbose;
504
    my $count = $old_checkouts->count;
505
    $old_checkouts->delete if $confirm;
506
    say sprintf "Done with purging %d old issues.", $count if $verbose;
446
}
507
}
447
508
448
if ($pOldReserves) {
509
if ($pOldReserves) {
449
    print "Purging old reserves older than $pOldReserves days.\n" if $verbose;
510
    print "Purging old reserves older than $pOldReserves days.\n" if $verbose;
450
    Koha::Old::Holds->filter_by_last_update( { days => $pOldReserves } )->delete;
511
    my $old_reserves = Koha::Old::Holds->filter_by_last_update( { days => $pOldReserves } );
451
    print "Done with purging old reserves.\n" if $verbose;
512
    my $count = $old_reserves->count;
513
    $old_reserves->delete if $verbose;
514
    say sprintf "Done with purging %d old reserves.", $count if $verbose;
452
}
515
}
453
516
454
if ($pTransfers) {
517
if ($pTransfers) {
455
    print "Purging arrived item transfers older than $pTransfers days.\n" if $verbose;
518
    print "Purging arrived item transfers older than $pTransfers days.\n" if $verbose;
456
    Koha::Item::Transfers->filter_by_last_update(
519
    my $transfers = Koha::Item::Transfers->filter_by_last_update(
457
        {
520
        {
458
            timestamp_column_name => 'datearrived',
521
            timestamp_column_name => 'datearrived',
459
            days => $pTransfers,
522
            days => $pTransfers,
460
        }
523
        }
461
    )->delete;
524
    );
462
    print "Done with purging transfers.\n" if $verbose;
525
    my $count = $transfers->count;
526
    $transfers->delete if $verbose;
527
    say sprintf "Done with purging %d transfers.", $count if $verbose;
463
}
528
}
464
529
465
if (defined $pPseudoPatrons) {
530
if (defined $pPseudoPatrons) {
Lines 471-491 if (defined $pPseudoPatrons) { Link Here
471
            ( $pPseudoPatronsFrom ? ( from => $pPseudoPatronsFrom ) : () ),
536
            ( $pPseudoPatronsFrom ? ( from => $pPseudoPatronsFrom ) : () ),
472
            ( $pPseudoPatronsTo   ? ( to   => $pPseudoPatronsTo   ) : () ),
537
            ( $pPseudoPatronsTo   ? ( to   => $pPseudoPatronsTo   ) : () ),
473
        }
538
        }
474
    )->delete;
539
    );
475
    print "Done with purging pseudonymized patrons.\n" if $verbose;
540
    my $count = $anonymized_patrons->count;
541
    $anonymized_patrons->delete;
542
    say sprintf "Done with purging %d pseudonymized patrons.", $count if $verbose;
476
}
543
}
477
544
478
if (defined $pPseudoTransactions) {
545
if (defined $pPseudoTransactions) {
479
    print "Purging pseudonymized transactions older than $pPseudoTransactions days.\n" if $verbose;
546
    print "Purging pseudonymized transactions older than $pPseudoTransactions days.\n" if $verbose;
480
    Koha::Anonymized::Transactions->filter_by_last_update(
547
    my $anonymized_transactions = Koha::Anonymized::Transactions->filter_by_last_update(
481
        {
548
        {
482
            timestamp_column_name => 'datetime',
549
            timestamp_column_name => 'datetime',
483
            ( $pPseudoTransactions     ? ( days => $pPseudoTransactions     ) : () ),
550
            ( $pPseudoTransactions     ? ( days => $pPseudoTransactions     ) : () ),
484
            ( $pPseudoTransactionsFrom ? ( from => $pPseudoTransactionsFrom ) : () ),
551
            ( $pPseudoTransactionsFrom ? ( from => $pPseudoTransactionsFrom ) : () ),
485
            ( $pPseudoTransactionsTo   ? ( to   => $pPseudoTransactionsTo   ) : () ),
552
            ( $pPseudoTransactionsTo   ? ( to   => $pPseudoTransactionsTo   ) : () ),
486
        }
553
        }
487
    )->delete;
554
    );
488
    print "Done with purging pseudonymized transactions.\n" if $verbose;
555
    my $count = $anonymized_transactions->count;
556
    $anonymized_transactions->delete if $confirm;
557
    say sprintf "Done with purging %d pseudonymized transactions.", $count if $verbose;
489
}
558
}
490
559
491
exit(0);
560
exit(0);
Lines 559-565 sub PurgeZ3950 { Link Here
559
628
560
sub PurgeDebarments {
629
sub PurgeDebarments {
561
    require Koha::Patron::Debarments;
630
    require Koha::Patron::Debarments;
562
    my $days = shift;
631
    my ( $days, $doit ) = @_;
563
    $count = 0;
632
    $count = 0;
564
    $sth   = $dbh->prepare(
633
    $sth   = $dbh->prepare(
565
        q{
634
        q{
Lines 570-576 sub PurgeDebarments { Link Here
570
    );
639
    );
571
    $sth->execute($days) or die $dbh->errstr;
640
    $sth->execute($days) or die $dbh->errstr;
572
    while ( my ($borrower_debarment_id) = $sth->fetchrow_array ) {
641
    while ( my ($borrower_debarment_id) = $sth->fetchrow_array ) {
573
        Koha::Patron::Debarments::DelDebarment($borrower_debarment_id);
642
        Koha::Patron::Debarments::DelDebarment($borrower_debarment_id) if $doit;
574
        $count++;
643
        $count++;
575
    }
644
    }
576
    return $count;
645
    return $count;
577
- 

Return to bug 24153