@@ -, +, @@ cleanup_database --- misc/cronjobs/cleanup_database.pl | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) --- a/misc/cronjobs/cleanup_database.pl +++ a/misc/cronjobs/cleanup_database.pl @@ -90,8 +90,8 @@ Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueu --old-issues DAYS Purge checkouts (old_issues) returned more than DAYS days ago. --old-reserves DAYS Purge reserves (old_reserves) more than DAYS old. --transfers DAYS Purge transfers completed more than DAYS day ago. - --labels DAYS Purge label items added more than DAYS days ago. - --cards DAY Purge card creator patrons added more than DAYS days ago. + --labels DAYS Purge item label batches last added to more than DAYS days ago. + --cards DAY Purge card creator batches last added to more than DAYS days ago. USAGE exit $_[0]; @@ -490,27 +490,39 @@ if ($pTransfers) { } if ($labels) { - print "Purging label items older than $labels days from batches.\n" if $verbose; + 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 timestamp < date_sub(curdate(), interval ? day) AND creator='Labels' + 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 label items older than $labels days from batches.\n" if $verbose; + print "Done with purging item label batches last added to more than $labels days ago.\n" if $verbose; } if ($cards) { - print "Purging card creator patrons older than $cards days from batches.\n" if $verbose; + 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 timestamp < date_sub(curdate(), interval ? day) AND creator='Patroncards' + 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 patrons older than $cards days from batches.\n" if $verbose; + print "Done with purging card creator batches last added to more than $cards days ago.\n" if $verbose; } exit(0); --