From f28e817ea57a2dddb0fc803e0caf56170e45c489 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 6 Apr 2021 09:16:52 -0400 Subject: [PATCH] Bug 25429: Use filter_by_last_update Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- misc/cronjobs/cleanup_database.pl | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index f29c7a76a7..0a4ab9b32f 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -530,14 +530,22 @@ if ($pStatistics) { if ($return_claims) { print "Purging return claims older than $return_claims days.\n" if $verbose; - $sth = $dbh->prepare( - q{ - DELETE FROM return_claims - WHERE resolved_on < DATE_SUB(CURDATE(), INTERVAL ? DAY) + + $return_claims = Koha::Checkouts::ReturnClaims->filter_by_last_update( + { + timestamp_column_name => 'resolved_on', + days => $return_claims } ); - $sth->execute($return_claims); - print "Done with purging return claims.\n" if $verbose; + + my $count = $return_claims->count; + $return_claims->delete if $confirm; + + if ($verbose) { + say $confirm + ? sprintf "Done with purging %d resolved return claims.", $count + : sprintf "%d resolved return claims would have been purged.", $count; + } } if ($pDeletedCatalog) { -- 2.39.5