From a18359058f53c0864b23ee767e3a886ee93880f2 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 21 Nov 2019 09:22:28 +0000 Subject: [PATCH] Bug 23260: (QA follow-up) Use ->update instead of ->next Content-Type: text/plain; charset=utf-8 Also moves initialization of $anonymous_patron closer to associated comment lines. And removes the unneeded changes from Koha::Patrons. --- Koha/Item/LastPatrons.pm | 10 ++++------ Koha/Patrons.pm | 2 -- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Koha/Item/LastPatrons.pm b/Koha/Item/LastPatrons.pm index 7ed7c8fd5d..62dd878349 100644 --- a/Koha/Item/LastPatrons.pm +++ b/Koha/Item/LastPatrons.pm @@ -56,8 +56,9 @@ sub anonymise_items_last_borrower { # The default of 0 does not work due to foreign key constraints # The anonymisation should not fail quietly if AnonymousPatron is not a valid entry # Set it to undef (NULL) + my $anonymous_patron = C4::Context->preference('AnonymousPatron') || undef; + my $dtf = Koha::Database->new->schema->storage->datetime_parser; - my $nb_rows = 0; my $last_borrowers = $self->search( { ( @@ -68,11 +69,8 @@ sub anonymise_items_last_borrower { ) } ); - my $anonymous_patron = C4::Context->preference('AnonymousPatron') || undef; - while(my $last_borrower = $last_borrowers->next) { - $last_borrower->borrowernumber( $anonymous_patron )->store; - $nb_rows++; - } + my $nb_rows = $last_borrowers->count; # unaffected by update + $last_borrowers->update({ borrowernumber => $anonymous_patron }); return $nb_rows; } diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index 1935dd8d48..fbe696ec7a 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -31,7 +31,6 @@ use Koha::Patron; use Koha::Exceptions::Patron; use Koha::Patron::Categories; use Date::Calc qw( Today Add_Delta_YMD ); -use Koha::Item::LastPatrons; use base qw(Koha::Objects); @@ -140,7 +139,6 @@ sub search_patrons_to_anonymise { my ( $class, $params ) = @_; my $older_than_date = $params->{before}; my $library = $params->{library}; - $older_than_date = $older_than_date ? dt_from_string($older_than_date) : dt_from_string; $library ||= ( C4::Context->preference('IndependentBranches') && C4::Context->userenv && !C4::Context->IsSuperLibrarian() && C4::Context->userenv->{branch} ) -- 2.11.0