Bugzilla – Attachment 58527 Details for
Bug 17828
Koha::Patron::Attribute->store should raise an exception if unique_id is being broken
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17828: Overload Koha::Patron::Attribute->store to check for unique_id
Bug-17828-Overload-KohaPatronAttribute-store-to-ch.patch (text/plain), 2.83 KB, created by
Tomás Cohen Arazi (tcohen)
on 2016-12-30 14:17:37 UTC
(
hide
)
Description:
Bug 17828: Overload Koha::Patron::Attribute->store to check for unique_id
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2016-12-30 14:17:37 UTC
Size:
2.83 KB
patch
obsolete
>From e933e607bc0b7887d2e16634fbed28323bea99f2 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 30 Dec 2016 11:12:32 -0300 >Subject: [PATCH] Bug 17828: Overload Koha::Patron::Attribute->store to check > for unique_id > >This patch introduces a Koha::Patron::Attribute->store method that does >the required check for the corresponding Koha::Patron::Attribute::Type >and raises an exception if trying to store more than one unique >attribute. > >This patch introduces an exception definition for that purpose. > >To test: >- Apply the unit tests patches >- Run: > $ prove t/db_dependent/Koha/Patron/Attributes.t >=> FAIL: Tests fail >- Apply this patch >- Run: > $ prove t/db_dependent/Koha/Patron/Attributes.t >=> SUCCESS: Tests pass! >- Sign off :-D >--- > Koha/Exceptions/Patron/Attribute.pm | 16 ++++++++++++++++ > Koha/Patron/Attribute.pm | 28 ++++++++++++++++++++++++++++ > 2 files changed, 44 insertions(+) > create mode 100644 Koha/Exceptions/Patron/Attribute.pm > >diff --git a/Koha/Exceptions/Patron/Attribute.pm b/Koha/Exceptions/Patron/Attribute.pm >new file mode 100644 >index 0000000000..2df1a0151f >--- /dev/null >+++ b/Koha/Exceptions/Patron/Attribute.pm >@@ -0,0 +1,16 @@ >+package Koha::Exceptions::Patron::Attribute; >+ >+use Modern::Perl; >+ >+use Exception::Class ( >+ >+ 'Koha::Exceptions::Patron::Attribute' => { >+ description => 'Something went wrong' >+ }, >+ 'Koha::Exceptions::Patron::Attribute::UniqueIDConstraint' => { >+ isa => 'Koha::Exceptions::Patron::Attribute', >+ description => "unique_id set for attribute type and tried to add a new attribute for the same code" >+ } >+); >+ >+1; >diff --git a/Koha/Patron/Attribute.pm b/Koha/Patron/Attribute.pm >index 7643536b7c..c133f0026f 100644 >--- a/Koha/Patron/Attribute.pm >+++ b/Koha/Patron/Attribute.pm >@@ -17,6 +17,8 @@ package Koha::Patron::Attribute; > > use Modern::Perl; > >+use Koha::Database; >+use Koha::Exceptions::Patron::Attribute; > use Koha::Patron::Attribute::Types; > > use base qw(Koha::Object); >@@ -31,6 +33,32 @@ Koha::Patron::Attribute - Koha Patron Attribute Object class > > =cut > >+=head3 store >+ >+ my $attribute = Koha::Patron::Attribute->new({ code => 'a_code', ... }); >+ try { $attribute->store } >+ catch { handle_exception }; >+ >+=cut >+ >+sub store { >+ >+ my $self = shift; >+ >+ if ( Koha::Patron::Attribute::Types->find( $self->code )->unique_id ) { >+ my $attr_count >+ = Koha::Database->new->schema->resultset( $self->_type )->search( >+ { borrowernumber => $self->borrowernumber, >+ code => $self->code >+ } >+ )->count; >+ Koha::Exceptions::Patron::Attribute::UniqueIDConstraint->throw() >+ if $attr_count > 0; >+ } >+ >+ return $self->SUPER::store(); >+} >+ > =head3 opac_display > > my $attribute = Koha::Patron::Attribute->new({ code => 'a_code', ... }); >-- >2.11.0
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 17828
:
58526
|
58527
|
58557
|
58558
|
61505
|
61506
|
61547
|
61644
|
61662
|
61703
|
61704
|
61705
|
61706
|
61707
|
61708
|
61709