Bug 21337: (follow-up) Add parameter for move_to_deleted action
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Thu, 13 Sep 2018 10:26:57 +0000 (12:26 +0200)
committerNick Clemens <nick@bywatersolutions.com>
Mon, 15 Oct 2018 14:12:54 +0000 (14:12 +0000)
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 <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Michal Denar <black23@gmail.com>

Signed-off-by: Michal Denar <black23@gmail.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Koha/Patrons.pm
t/db_dependent/Koha/Patrons.t

index 713ad6c..37df417 100644 (file)
@@ -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;
index 3f51e23..f16c73f 100644 (file)
@@ -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' );
 };