Bug 21337: Koha::Objects->delete must return the number of deleted rows
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 15 Oct 2018 17:38:14 +0000 (14:38 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Mon, 15 Oct 2018 17:53:15 +0000 (17:53 +0000)
To follow DBIC behaviour

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

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

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

index 0068f34..21061cd 100644 (file)
@@ -224,14 +224,16 @@ sub anonymise_issue_history {
 
 sub delete {
     my ( $self, $params ) = @_;
+    my $patrons_deleted;
     $self->_resultset->result_source->schema->txn_do( sub {
         my ( $set, $params ) = @_;
         while( my $patron = $set->next ) {
             $patron->move_to_deleted if $params->{move};
             $patron->delete == 1 || Koha::Exceptions::Patron::Delete->throw;
+            $patrons_deleted++;
         }
     }, $self, $params );
-    return 1;
+    return $patrons_deleted;
 }
 
 =head3 _type
index 88fcc6c..e2e8019 100644 (file)
@@ -435,7 +435,7 @@ subtest 'Koha::Patrons->delete' => sub {
     my $id1 = $patron1->borrowernumber;
     my $set = Koha::Patrons->search({ borrowernumber => { '>=' => $id1 }});
     is( $set->count, 2, 'Two patrons found as expected' );
-    is( $set->delete({ move => 1 }), 1, 'Two patrons deleted' );
+    is( $set->delete({ move => 1 }), 2, 'Two patrons deleted' );
     is( $moved_to_deleted, 2, 'Patrons moved to deletedborrowers' );
 
     # Add again, test if we can raise an exception