From 82ff8138b4bb5bb4fba16a979c75a4673a15e348 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 15 Oct 2018 14:38:14 -0300 Subject: [PATCH] Bug 21337: Koha::Objects->delete must return the number of deleted rows To follow DBIC behaviour Signed-off-by: Jonathan Druart Signed-off-by: Nick Clemens --- Koha/Patrons.pm | 4 +++- t/db_dependent/Koha/Patrons.t | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index 0068f340ac..21061cd37f 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -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 diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 88fcc6cabb..e2e80197c6 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -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 -- 2.39.5