From c266194cbde4536e60a0a2903dccba928a5add89 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 Content-Type: text/plain; charset=utf-8 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 --- 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 713ad6c..37df417 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 81b0da2..dac7f52 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -429,7 +429,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.1.4