From 87a18579c4d0ab15591e5daf3875dc5450086c95 Mon Sep 17 00:00:00 2001 From: Petro Vashchuk Date: Tue, 15 Oct 2024 17:27:43 +0300 Subject: [PATCH] Bug 26024: Purge option for undone zebraq entries in cleanup_database.pl Added --zebraqueue-undone DAYS option to cleanup_database.pl to purge uncompleted (done=0) zebraqueue entries older than DAYS days (90 days default). --- debian/koha-common.cron.daily | 2 +- misc/cronjobs/cleanup_database.pl | 55 ++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/debian/koha-common.cron.daily b/debian/koha-common.cron.daily index 0d960ef0c5d..e518ed15ad5 100644 --- a/debian/koha-common.cron.daily +++ b/debian/koha-common.cron.daily @@ -25,7 +25,7 @@ koha-foreach --chdir --enabled --email /usr/share/koha/bin/cronjobs/advance_noti koha-foreach --chdir --enabled /usr/share/koha/bin/cronjobs/serialsUpdate.pl -c koha-foreach --chdir --enabled /usr/share/koha/bin/cronjobs/membership_expiry.pl -c koha-foreach --chdir --enabled /usr/share/koha/bin/cronjobs/holds/cancel_expired_holds.pl >/dev/null 2>&1 -koha-foreach --chdir --enabled /usr/share/koha/bin/cronjobs/cleanup_database.pl --confirm --sessions --zebraqueue 10 --list-invites --temp-uploads --del-unv-selfreg 14 +koha-foreach --chdir --enabled /usr/share/koha/bin/cronjobs/cleanup_database.pl --confirm --sessions --zebraqueue-undone 30 --zebraqueue 10 --list-invites --temp-uploads --del-unv-selfreg 14 koha-foreach --chdir --enabled --noemail /usr/share/koha/bin/cronjobs/cleanup_database.pl --confirm --mail koha-foreach --chdir --enabled /usr/share/koha/bin/cronjobs/holds/auto_unsuspend_holds.pl > /dev/null 2>&1 koha-foreach --chdir --enabled /usr/share/koha/bin/cronjobs/merge_authorities.pl -b diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index 01930181294..ea25e7b37cf 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -20,6 +20,7 @@ use Modern::Perl; use constant DEFAULT_ZEBRAQ_PURGEDAYS => 30; +use constant DEFAULT_ZEBRAQ_UNDONE_PURGEDAYS => 90; use constant DEFAULT_MAIL_PURGEDAYS => 30; use constant DEFAULT_IMPORT_PURGEDAYS => 60; use constant DEFAULT_LOGS_PURGEDAYS => 180; @@ -57,7 +58,7 @@ use Koha::UploadedFiles; sub usage { print STDERR < \$verbose, 'm|mail:i' => \$mail, 'zebraqueue:i' => \$zebraqueue_days, + 'zebraqueue-undone:i' => \$zebraqueue_days_undone, 'merged' => \$purge_merged, 'import:i' => \$pImport, 'z3950' => \$pZ3950, @@ -221,17 +226,18 @@ GetOptions( ) || usage(1); # Use default values -$sessions = 1 if $sess_days && $sess_days > 0; -$pImport = DEFAULT_IMPORT_PURGEDAYS if defined($pImport) && $pImport == 0; -$pLogs = DEFAULT_LOGS_PURGEDAYS if defined($pLogs) && $pLogs == 0; -$zebraqueue_days = DEFAULT_ZEBRAQ_PURGEDAYS if defined($zebraqueue_days) && $zebraqueue_days == 0; -$mail = DEFAULT_MAIL_PURGEDAYS if defined($mail) && $mail == 0; -$pSearchhistory = DEFAULT_SEARCHHISTORY_PURGEDAYS if defined($pSearchhistory) && $pSearchhistory == 0; -$pDebarments = DEFAULT_DEBARMENTS_PURGEDAYS if defined($pDebarments) && $pDebarments == 0; -$pMessages = DEFAULT_MESSAGES_PURGEDAYS if defined($pMessages) && $pMessages == 0; -$jobs_days = DEFAULT_JOBS_PURGEDAYS if defined($jobs_days) && $jobs_days == 0; -@jobs_types = (DEFAULT_JOBS_PURGETYPES) if $jobs_days && @jobs_types == 0; -$edifact_msg_days = DEFAULT_EDIFACT_MSG_PURGEDAYS if defined($edifact_msg_days) && $edifact_msg_days == 0; +$sessions = 1 if $sess_days && $sess_days > 0; +$pImport = DEFAULT_IMPORT_PURGEDAYS if defined($pImport) && $pImport == 0; +$pLogs = DEFAULT_LOGS_PURGEDAYS if defined($pLogs) && $pLogs == 0; +$zebraqueue_days = DEFAULT_ZEBRAQ_PURGEDAYS if defined($zebraqueue_days) && $zebraqueue_days == 0; +$zebraqueue_days_undone = DEFAULT_ZEBRAQ_UNDONE_PURGEDAYS if defined($zebraqueue_days_undone) && $zebraqueue_days_undone == 0; +$mail = DEFAULT_MAIL_PURGEDAYS if defined($mail) && $mail == 0; +$pSearchhistory = DEFAULT_SEARCHHISTORY_PURGEDAYS if defined($pSearchhistory) && $pSearchhistory == 0; +$pDebarments = DEFAULT_DEBARMENTS_PURGEDAYS if defined($pDebarments) && $pDebarments == 0; +$pMessages = DEFAULT_MESSAGES_PURGEDAYS if defined($pMessages) && $pMessages == 0; +$jobs_days = DEFAULT_JOBS_PURGEDAYS if defined($jobs_days) && $jobs_days == 0; +@jobs_types = (DEFAULT_JOBS_PURGETYPES) if $jobs_days && @jobs_types == 0; +$edifact_msg_days = DEFAULT_EDIFACT_MSG_PURGEDAYS if defined($edifact_msg_days) && $edifact_msg_days == 0; # Choose the number of days at which to purge unaccepted list invites: # - DAYS defined in the list-invites parameter is prioritised first @@ -251,6 +257,7 @@ if ($help) { unless ( $sessions || $zebraqueue_days + || $zebraqueue_days_undone || $mail || $purge_merged || $pImport @@ -347,6 +354,30 @@ if ($zebraqueue_days) { } } +if ($zebraqueue_days_undone) { + my $count = 0; + print "Zebraqueue undone purge triggered for $zebraqueue_days_undone days.\n" if $verbose; + $sth = $dbh->prepare( + q{ + SELECT id,biblio_auth_number,server,time + FROM zebraqueue + WHERE done=0 AND time < date_sub(curdate(), INTERVAL ? DAY) + } + ); + $sth->execute($zebraqueue_days_undone) or die $dbh->errstr; + $sth2 = $dbh->prepare(q{ DELETE FROM zebraqueue WHERE id=? }); + while ( my $record = $sth->fetchrow_hashref ) { + if ($confirm) { + $sth2->execute( $record->{id} ) or die $dbh->errstr; + } + $count++; + } + if ($verbose) { + say $confirm ? "$count records were deleted." : "$count records would have been deleted."; + say "Done with zebraqueue undone purge."; + } +} + if ($mail) { my $count = 0; print "Mail queue purge triggered for $mail days.\n" if $verbose; -- 2.46.0