@@ -, +, @@ cleanup_database --- misc/cronjobs/cleanup_database.pl | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) --- a/misc/cronjobs/cleanup_database.pl +++ a/misc/cronjobs/cleanup_database.pl @@ -103,6 +103,9 @@ Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose] --pseudo-transactions DAYS Purge the pseudonymized transactions that have been originally created more than DAYS days ago DAYS is optional and can be replaced by: --pseudo-transactions-from YYYY-MM-DD and/or --pseudo-transactions-to YYYY-MM-DD + --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]; } @@ -577,6 +580,50 @@ if (defined $pPseudoTransactions or $pPseudoTransactionsFrom or $pPseudoTransact ? sprintf "Done with purging %d pseudonymized transactions.", $count : sprintf "%d pseudonymized transactions would have been purged.", $count; } + $sth = $dbh->prepare( + q{ + DELETE FROM branchtransfers + WHERE datearrived < DATE_SUB(CURDATE(), INTERVAL ? DAY) + } + ); + $sth->execute($pTransfers); + print "Done with purging transfers.\n" if $verbose; +} + +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); --