From 720d6360a0038a943b4554c4180cc0ebb61c2b4d Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 13 Sep 2018 12:26:57 +0200 Subject: [PATCH] Bug 21337: (follow-up) Add parameter for move_to_deleted action For consistency, it would be better to make the move optional. Test plan: Run again t/db_dependent/Koha/Patrons.t. Signed-off-by: Marcel de Rooy Signed-off-by: Michal Denar Signed-off-by: Michal Denar Signed-off-by: Josef Moravec Signed-off-by: Nick Clemens --- Koha/Patrons.pm | 8 ++++---- t/db_dependent/Koha/Patrons.t | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index 713ad6c312..37df417e4e 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -209,23 +209,23 @@ sub anonymise_issue_history { =head3 delete - Koha::Patrons->search({ some filters here })->delete; + Koha::Patrons->search({ some filters here })->delete({ move => 1 }); Delete passed set of patron objects. Wrapper for Koha::Patron->delete. (We do not want to bypass Koha::Patron and let DBIx do the job without further housekeeping.) - NOTE: By default includes a move to deletedborrowers. + Includes a move to deletedborrowers if move flag set. Return value (if relevant) is based on the individual return values. =cut sub delete { - my ( $self ) = @_; + my ( $self, $params ) = @_; my (@res, $rv); $rv = 1; while( my $patron = $self->next ) { - $patron->move_to_deleted; # Needed here, since it is no default action.. + $patron->move_to_deleted if $params->{move}; push @res, $patron->delete; $rv=-1 if $res[-1]==-1; $rv=0 if $rv==1 && $res[-1]==0; diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 3f51e2321e..f16c73fc4d 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -430,7 +430,7 @@ subtest 'Koha::Patrons->delete' => sub { my $set = Koha::Patrons->search({ borrowernumber => { '>=' => $id1 }}); is( $set->count, 2, 'Two patrons found as expected' ); my $count1 = $schema->resultset('Deletedborrower')->count; - is( $set->delete, 1, 'Two patrons deleted' ); + is( $set->delete({ move => 1 }), 1, 'Two patrons deleted' ); my $count2 = $schema->resultset('Deletedborrower')->count; is( $count2, $count1 + 2, 'Patrons moved to deletedborrowers' ); }; -- 2.39.5