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