@@ -, +, @@ cleanup_database --- misc/cronjobs/cleanup_database.pl | 47 ++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) --- a/misc/cronjobs/cleanup_database.pl +++ a/misc/cronjobs/cleanup_database.pl @@ -55,7 +55,7 @@ use Koha::Patron::Messages; sub usage { print STDERR < \$help, @@ -177,6 +182,8 @@ GetOptions( 'pseudo-transactions:i' => \$pPseudoTransactions, 'pseudo-transactions-from:s' => \$pPseudoTransactionsFrom, 'pseudo-transactions-to:s' => \$pPseudoTransactionsTo, + 'labels' => \$labels, + 'cards' => \$cards, ) || usage(1); # Use default values @@ -222,6 +229,8 @@ unless ( $sessions || $pPseudoTransactionsFrom || $pPseudoTransactionsTo || $pMessages + || $labels + || $cards ) { print "You did not specify any cleanup work for the script to do.\n\n"; usage(1); @@ -600,6 +609,42 @@ if (defined $pPseudoTransactions or $pPseudoTransactionsFrom or $pPseudoTransact } } +if ($labels) { + print "Purging item label batches last added to more than $labels days ago.\n" if $verbose; + $sth = $dbh->prepare( + q{ + DELETE from creator_batches + WHERE batch_id in + (SELECT batch_id + FROM (SELECT batch_id + FROM creator_batches + WHERE creator='labels' + GROUP BY batch_id + HAVING max(timestamp) < date_sub(curdate(),interval ? day)) a) + } + ); + $sth->execute($labels) or die $dbh->errstr; + print "Done with purging item label batches last added to more than $labels days ago.\n" if $verbose; +} + +if ($cards) { + print "Purging card creator batches last added to more than $cards days ago.\n" if $verbose; + $sth = $dbh->prepare( + q{ + DELETE from creator_batches + WHERE batch_id in + (SELECT batch_id + FROM (SELECT batch_id + FROM creator_batches + WHERE creator='patroncards' + GROUP BY batch_id + HAVING max(timestamp) < date_sub(curdate(),interval ? day)) a); + } + ); + $sth->execute($cards) or die $dbh->errstr; + print "Done with purging card creator batches last added to more than $cards days ago.\n" if $verbose; +} + exit(0); sub RemoveOldSessions { --