From 1497f1ddeb8cb53273663a83cc2c235488f9631e Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 6 Jan 2014 13:46:02 -0500 Subject: [PATCH] Bug 11484 - Add option to purge z39.50 search records from import table to cleanup_database.pl Content-Type: text/plain; charset=utf-8 It would be good to be able to specifically target import records from z39.50 for cleanup. Test Plan: 1) Apply this patch 2) Import one or more batch record sets into Koha 3) Perform some z39.50 searches 4) Run this command: misc/cronjobs/cleanup_database.pl -v --z3950 5) Verify that only z39.50 records were deleted Signed-off-by: Jonathan Druart Signed-off-by: Marcel de Rooy --- misc/cronjobs/cleanup_database.pl | 33 +++++++++++++++++++++++++++++++-- 1 files changed, 31 insertions(+), 2 deletions(-) diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index c190a80..27d92c2 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -58,6 +58,8 @@ Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueu --merged purged completed entries from need_merge_authorities. --import DAYS purge records from import tables older than DAYS days. Defaults to 60 days if no days specified. + --z3950 purge records from import tables that are the result + of z39.50 searches --logs DAYS purge entries from action_logs older than DAYS days. Defaults to 180 days if no days specified. --searchhistory DAYS purge entries from search_history older than DAYS days. @@ -66,7 +68,11 @@ USAGE exit $_[0]; } -my ( $help, $sessions, $sess_days, $verbose, $zebraqueue_days, $mail, $purge_merged, $pImport, $pLogs, $pSearchhistory); +my ( + $help, $sessions, $sess_days, $verbose, + $zebraqueue_days, $mail, $purge_merged, $pImport, + $pLogs, $pSearchhistory, $pZ3950 +); GetOptions( 'h|help' => \$help, @@ -77,6 +83,7 @@ GetOptions( 'zebraqueue:i' => \$zebraqueue_days, 'merged' => \$purge_merged, 'import:i' => \$pImport, + 'z3950' => \$pZ3950, 'logs:i' => \$pLogs, 'searchhistory:i' => \$pSearchhistory, ) || usage(1); @@ -94,7 +101,15 @@ if ($help) { usage(0); } -if ( !( $sessions || $zebraqueue_days || $mail || $purge_merged || $pImport || $pLogs || $pSearchhistory ) ) { +unless ( $sessions + || $zebraqueue_days + || $mail + || $purge_merged + || $pImport + || $pLogs + || $pSearchhistory + || $pZ3950 ) +{ print "You did not specify any cleanup work for the script to do.\n\n"; usage(1); } @@ -172,6 +187,12 @@ if($pImport) { print "Done with purging import tables.\n" if $verbose; } +if($pZ3950) { + print "Purging z39.50 records from import tables.\n" if $verbose; + PurgeZ3950(); + print "Done with purging z39.50 records from import tables.\n" if $verbose; +} + if($pLogs) { print "Purging records from action_logs.\n" if $verbose; $sth = $dbh->prepare("DELETE FROM action_logs WHERE timestamp < date_sub(curdate(), interval ? DAY)"); @@ -232,3 +253,11 @@ sub PurgeImportTables { ba.upload_timestamp < date_sub(curdate(), interval ? DAY)"); $sth->execute($pImport) or die $dbh->errstr; } + + +sub PurgeZ3950 { + $sth = $dbh->prepare(q{ + DELETE FROM import_batches WHERE batch_type = 'z3950' + }); + $sth->execute() or die $dbh->errstr; +} -- 1.7.7.6