Bugzilla – Attachment 78586 Details for
Bug 21337
Add Koha::Patrons->delete
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21337: Add Koha::Patrons->delete (trivial wrapper)
Bug-21337-Add-KohaPatrons-delete-trivial-wrapper.patch (text/plain), 3.05 KB, created by
Marcel de Rooy
on 2018-09-12 14:29:29 UTC
(
hide
)
Description:
Bug 21337: Add Koha::Patrons->delete (trivial wrapper)
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2018-09-12 14:29:29 UTC
Size:
3.05 KB
patch
obsolete
>From e27d29b8386c2d75f8e787b8dac928d4ad921ab7 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Wed, 12 Sep 2018 15:49:45 +0200 >Subject: [PATCH] Bug 21337: Add Koha::Patrons->delete (trivial wrapper) >Content-Type: text/plain; charset=utf-8 > >Adds Koha::Patrons->delete as wrapper around Koha::Patron->delete. We do >not want to bypass Koha::Patron and let DBIx do the job without further >housekeeping. A call to move_to_deleted is included now, but could be >made optional with a parameter if needed. > >Test plan: >Run t/db_dependent/Koha/Patrons.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/Patrons.pm | 30 ++++++++++++++++++++++++++++++ > t/db_dependent/Koha/Patrons.t | 15 ++++++++++++++- > 2 files changed, 44 insertions(+), 1 deletion(-) > >diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm >index 0d2d9ec..eb042ab 100644 >--- a/Koha/Patrons.pm >+++ b/Koha/Patrons.pm >@@ -207,6 +207,36 @@ sub anonymise_issue_history { > return $nb_rows; > } > >+=head3 delete >+ >+ Koha::Patrons->search({ some filters here })->delete; >+ >+ 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. >+ >+ Return value (if relevant) is based on the individual return values. >+ >+=cut >+ >+sub delete { >+ my ( $self ) = @_; >+ my (@res, $rv); >+ $rv = 1; >+ map { >+ $_->move_to_deleted; # Needed here, since it is no default action.. >+ push @res, $_->delete; >+ $rv=-1 if $res[-1]==-1; >+ $rv=0 if $rv==1 && $res[-1]==0; >+ } $self->_wrap( $self->_resultset->all ); >+ >+ # Return -1 if we encountered a single -1 >+ # Return 0 if we encountered a single 0 (but not a -1) >+ # Return 1 if all individual deletes passed >+ return $rv; >+} >+ > =head3 _type > > =cut >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index 6521db1..81b0da2 100644 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 32; >+use Test::More tests => 33; > use Test::Warn; > use Test::Exception; > use Time::Fake; >@@ -421,6 +421,19 @@ subtest "delete" => sub { > is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' ); > }; > >+subtest 'Koha::Patrons->delete' => sub { >+ plan tests => 3; >+ my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $id1 = $patron1->borrowernumber; >+ 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' ); >+ my $count2 = $schema->resultset('Deletedborrower')->count; >+ is( $count2, $count1 + 2, 'Patrons moved to deletedborrowers' ); >+}; >+ > subtest 'add_enrolment_fee_if_needed' => sub { > plan tests => 4; > >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 21337
:
78586
|
78619
|
78621
|
79461
|
79462
|
79708
|
79709
|
79915
|
79916
|
79917
|
80624
|
81251
|
81252
|
81257