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

(-)a/misc/cronjobs/cleanup_database.pl (-27 / +65 lines)
Lines 235-245 my $count; Link Here
235
235
236
if ( $sessions && !$sess_days ) {
236
if ( $sessions && !$sess_days ) {
237
    if ($verbose) {
237
    if ($verbose) {
238
        print "Session purge triggered.\n";
238
        say "Session purge triggered.";
239
        $sth = $dbh->prepare(q{ SELECT COUNT(*) FROM sessions });
239
        $sth = $dbh->prepare(q{ SELECT COUNT(*) FROM sessions });
240
        $sth->execute() or die $dbh->errstr;
240
        $sth->execute() or die $dbh->errstr;
241
        my @count_arr = $sth->fetchrow_array;
241
        my @count_arr = $sth->fetchrow_array;
242
        print "$count_arr[0] entries will be deleted.\n";
242
        say $confirm ? "$count_arr[0] entries will be deleted." : "$count_arr[0] entries would be deleted.";
243
    }
243
    }
244
    if ( $confirm ) {
244
    if ( $confirm ) {
245
        $sth = $dbh->prepare(q{ TRUNCATE sessions });
245
        $sth = $dbh->prepare(q{ TRUNCATE sessions });
Lines 275-281 if ($zebraqueue_days) { Link Here
275
        }
275
        }
276
        $count++;
276
        $count++;
277
    }
277
    }
278
    print "$count records were deleted.\nDone with zebraqueue purge.\n" if $verbose;
278
    if ( $verbose ) {
279
        say $confirm ? "$count records were deleted." : "$count records would have been deleted.";
280
        say "Done with zebraqueue purge.";
281
    }
279
}
282
}
280
283
281
if ($mail) {
284
if ($mail) {
Lines 290-298 if ($mail) { Link Here
290
    if ( $confirm ) {
293
    if ( $confirm ) {
291
        $sth->execute($mail) or die $dbh->errstr;
294
        $sth->execute($mail) or die $dbh->errstr;
292
        $count = $sth->rows;
295
        $count = $sth->rows;
293
        print "$count messages were deleted from the mail queue.\nDone with message_queue purge.\n" if $verbose;
296
    }
294
    } else {
297
    if ( $verbose ) {
295
        print "Messages were deleted from the mail queue.\nDone with message_queue purge.\n" if $verbose;
298
        say $confirm ? "$count messages were deleted from the mail queue." : "Message from message_queue would have been deleted";
299
        say "Done with message_queue purge.";
296
    }
300
    }
297
}
301
}
298
302
Lines 361-386 if ($pListShareInvites) { Link Here
361
if ($pDebarments) {
365
if ($pDebarments) {
362
    print "Expired patrons restrictions purge triggered for $pDebarments days.\n" if $verbose;
366
    print "Expired patrons restrictions purge triggered for $pDebarments days.\n" if $verbose;
363
    $count = PurgeDebarments($pDebarments, $confirm);
367
    $count = PurgeDebarments($pDebarments, $confirm);
364
    print "$count restrictions were deleted.\nDone with restrictions purge.\n" if $verbose;
368
    if ( $verbose ) {
369
        say $confirm ? "$count restrictions were deleted." : "$count restrictions would have been deleted";
370
        say "Done with restrictions purge.";
371
    }
365
}
372
}
366
373
367
if($allDebarments) {
374
if($allDebarments) {
368
    print "All expired patrons restrictions purge triggered.\n" if $verbose;
375
    print "All expired patrons restrictions purge triggered.\n" if $verbose;
369
    $count = PurgeDebarments(0, $confirm);
376
    $count = PurgeDebarments(0, $confirm);
370
    print "$count restrictions were deleted.\nDone with all restrictions purge.\n" if $verbose;
377
    if ( $verbose ) {
378
        say $confirm ? "$count restrictions were deleted." : "$count restrictions would have been deleted";
379
        say "Done with all restrictions purge.";
380
    }
371
}
381
}
372
382
373
# Handle unsubscribe requests from GDPR consent form, depends on UnsubscribeReflectionDelay preference
383
# Handle unsubscribe requests from GDPR consent form, depends on UnsubscribeReflectionDelay preference
374
my $unsubscribed_patrons = Koha::Patrons->search_unsubscribed;
384
my $unsubscribed_patrons = Koha::Patrons->search_unsubscribed;
375
$count = $unsubscribed_patrons->count;
385
$count = $unsubscribed_patrons->count;
376
$unsubscribed_patrons->lock( { expire => 1, remove => 1 } ) if $confirm;
386
$unsubscribed_patrons->lock( { expire => 1, remove => 1 } ) if $confirm;
377
say sprintf "Locked %d patrons", $count if $verbose;
387
say $confirm ? sprintf("Locked %d patrons", $count) : sprintf("%d patrons would have been locked", $count) if $verbose;
378
388
379
# Anonymize patron data, depending on PatronAnonymizeDelay
389
# Anonymize patron data, depending on PatronAnonymizeDelay
380
my $anonymize_candidates = Koha::Patrons->search_anonymize_candidates( { locked => 1 } );
390
my $anonymize_candidates = Koha::Patrons->search_anonymize_candidates( { locked => 1 } );
381
$count = $anonymize_candidates->count;
391
$count = $anonymize_candidates->count;
382
$anonymize_candidates->anonymize if $confirm;
392
$anonymize_candidates->anonymize if $confirm;
383
say sprintf "Anonymized %s patrons", $count if $verbose;
393
say $confirm ? sprintf("Anonymized %d patrons", $count) : sprintf("%d patrons would have been anonymized", $count) if $verbose;
384
394
385
# Remove patron data, depending on PatronRemovalDelay (will raise an exception if problem encountered
395
# Remove patron data, depending on PatronRemovalDelay (will raise an exception if problem encountered
386
my $anonymized_patrons = Koha::Patrons->search_anonymized;
396
my $anonymized_patrons = Koha::Patrons->search_anonymized;
Lines 390-400 if ( $confirm ) { Link Here
390
    if ($@) {
400
    if ($@) {
391
        warn $@;
401
        warn $@;
392
    }
402
    }
393
    elsif ($verbose) {
403
}
394
        say sprintf "Deleted %d patrons", $count;
404
if ($verbose) {
395
    }
405
    say $confirm ? sprintf("Deleted %d patrons", $count) : sprintf("%d patrons would have been deleted", $count);
396
} else {
397
    say sprintf "Deleted %d patrons", $count;
398
}
406
}
399
407
400
# FIXME The output for dry-run mode needs to be improved
408
# FIXME The output for dry-run mode needs to be improved
Lines 457-463 if ($oauth_tokens) { Link Here
457
    my $tokens = Koha::OAuthAccessTokens->search({ expires => { '<=', time } });
465
    my $tokens = Koha::OAuthAccessTokens->search({ expires => { '<=', time } });
458
    my $count = $tokens->count;
466
    my $count = $tokens->count;
459
    $tokens->delete if $confirm;
467
    $tokens->delete if $confirm;
460
    say sprintf "Removed %s expired OAuth2 tokens", $count if $verbose;
468
    if ( $verbose ) {
469
        say $confirm
470
          ? sprintf( "Removed %d expired OAuth2 tokens", $count )
471
          : sprintf( "%d expired OAuth tokens would have been removed", $count );
472
    }
461
}
473
}
462
474
463
if ($pStatistics) {
475
if ($pStatistics) {
Lines 466-472 if ($pStatistics) { Link Here
466
        { timestamp_column_name => 'datetime', days => $pStatistics } );
478
        { timestamp_column_name => 'datetime', days => $pStatistics } );
467
    my $count = $statistics->count;
479
    my $count = $statistics->count;
468
    $statistics->delete if $confirm;
480
    $statistics->delete if $confirm;
469
    say sprintf "Done with purging %s statistics.", $count if $verbose;
481
    if ( $verbose ) {
482
        say $confirm
483
          ? sprintf( "Done with purging %d statistics", $count )
484
          : sprintf( "%d statistics would have been removed", $count );
485
    }
470
}
486
}
471
487
472
if ($pDeletedCatalog) {
488
if ($pDeletedCatalog) {
Lines 482-491 if ($pDeletedCatalog) { Link Here
482
        $old_biblioitems->delete;
498
        $old_biblioitems->delete;
483
        $old_biblios->delete;
499
        $old_biblios->delete;
484
    }
500
    }
485
    say sprintf
501
    if ($verbose) {
486
        "Done with purging deleted catalog (%d items, %d biblioitems, %d biblios).",
502
        say sprintf(
487
      $c_i, $c_bi, $c_b
503
            $confirm
488
      if $verbose;
504
            ? "Done with purging deleted catalog (%d items, %d biblioitems, %d biblios)."
505
            : "Deleted catalog would have been removed (%d items, %d biblioitems, %d biblios).",
506
        $c_i, $c_bi, $c_b);
507
    }
489
}
508
}
490
509
491
if ($pDeletedPatrons) {
510
if ($pDeletedPatrons) {
Lines 494-500 if ($pDeletedPatrons) { Link Here
494
        { timestamp_column_name => 'updated_on', days => $pDeletedPatrons } );
513
        { timestamp_column_name => 'updated_on', days => $pDeletedPatrons } );
495
    my $count = $old_patrons->count;
514
    my $count = $old_patrons->count;
496
    $old_patrons->delete if $confirm;
515
    $old_patrons->delete if $confirm;
497
    say sprintf "Done with purging %d deleted patrons.", $count if $verbose;
516
    if ($verbose) {
517
        say $confirm
518
          ? sprintf "Done with purging %d deleted patrons.", $count
519
          : sprintf "%d deleted patrons would have been purged.", $count;
520
    }
498
}
521
}
499
522
500
if ($pOldIssues) {
523
if ($pOldIssues) {
Lines 502-508 if ($pOldIssues) { Link Here
502
    my $old_checkouts = Koha::Old::Checkouts->filter_by_last_update( { days => $pOldIssues } );
525
    my $old_checkouts = Koha::Old::Checkouts->filter_by_last_update( { days => $pOldIssues } );
503
    my $count = $old_checkouts->count;
526
    my $count = $old_checkouts->count;
504
    $old_checkouts->delete if $confirm;
527
    $old_checkouts->delete if $confirm;
505
    say sprintf "Done with purging %d old checkouts.", $count if $verbose;
528
    if ($verbose) {
529
        say $confirm
530
          ? sprintf "Done with purging %d old checkouts.", $count
531
          : sprintf "%d old checkouts would have been purged.", $count;
532
    }
506
}
533
}
507
534
508
if ($pOldReserves) {
535
if ($pOldReserves) {
Lines 510-516 if ($pOldReserves) { Link Here
510
    my $old_reserves = Koha::Old::Holds->filter_by_last_update( { days => $pOldReserves } );
537
    my $old_reserves = Koha::Old::Holds->filter_by_last_update( { days => $pOldReserves } );
511
    my $count = $old_reserves->count;
538
    my $count = $old_reserves->count;
512
    $old_reserves->delete if $verbose;
539
    $old_reserves->delete if $verbose;
513
    say sprintf "Done with purging %d old reserves.", $count if $verbose;
540
    if ($verbose) {
541
        say $confirm
542
          ? sprintf "Done with purging %d old reserves.", $count
543
          : sprintf "%d old reserves would have been purged.", $count;
544
    }
514
}
545
}
515
546
516
if ($pTransfers) {
547
if ($pTransfers) {
Lines 523-529 if ($pTransfers) { Link Here
523
    );
554
    );
524
    my $count = $transfers->count;
555
    my $count = $transfers->count;
525
    $transfers->delete if $verbose;
556
    $transfers->delete if $verbose;
526
    say sprintf "Done with purging %d transfers.", $count if $verbose;
557
    if ($verbose) {
558
        say $confirm
559
          ? sprintf "Done with purging %d transfers.", $count
560
          : sprintf "%d transfers would have been purged.", $count;
561
    }
527
}
562
}
528
563
529
if (defined $pPseudoTransactions or $pPseudoTransactionsFrom or $pPseudoTransactionsTo ) {
564
if (defined $pPseudoTransactions or $pPseudoTransactionsFrom or $pPseudoTransactionsTo ) {
Lines 538-544 if (defined $pPseudoTransactions or $pPseudoTransactionsFrom or $pPseudoTransact Link Here
538
    );
573
    );
539
    my $count = $anonymized_transactions->count;
574
    my $count = $anonymized_transactions->count;
540
    $anonymized_transactions->delete if $confirm;
575
    $anonymized_transactions->delete if $confirm;
541
    say sprintf "Done with purging %d pseudonymized transactions.", $count if $verbose;
576
    if ($verbose) {
577
        say $confirm
578
          ? sprintf "Done with purging %d pseudonymized transactions.", $count
579
          : sprintf "%d pseudonymized transactions would have been purged.", $count;
580
    }
542
}
581
}
543
582
544
exit(0);
583
exit(0);
545
- 

Return to bug 24153