Bugzilla – Attachment 60989 Details for
Bug 17755
Introduce Koha::Patron::Attribute::Type(s)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17755: Introduce Koha::Object::Limit::Library
Bug-17755-Introduce-KohaObjectLimitLibrary.patch (text/plain), 6.52 KB, created by
Tomás Cohen Arazi (tcohen)
on 2017-03-10 13:49:37 UTC
(
hide
)
Description:
Bug 17755: Introduce Koha::Object::Limit::Library
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2017-03-10 13:49:37 UTC
Size:
6.52 KB
patch
obsolete
>From d8bafca36ada1561b40adece30404d3917b421c4 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 12 Dec 2016 14:17:44 -0300 >Subject: [PATCH] Bug 17755: Introduce Koha::Object::Limit::Library > >This patch introduces a new class for extending Koha::Object using >multiple inheritance. It cannot be used standalone, it needs to be >used in Koha::Object implementations like this: > >use base qw( Koha::Object Koha::Object::Limit::Library ); > >Its goal is to provide a single way and place to deal with this common >pattern in Koha's codebase. > >As it happened with Koha::Object, that needed to be tested in a real object >class, this work was done on top of Koha::Patron::Attribute::Type implementation >and it is fully covered by the tests that are introduced for it. > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/Exceptions.pm | 9 ++- > Koha/Object/Limit/Library.pm | 171 +++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 179 insertions(+), 1 deletion(-) > create mode 100644 Koha/Object/Limit/Library.pm > >diff --git a/Koha/Exceptions.pm b/Koha/Exceptions.pm >index dd8647b..12540c9 100644 >--- a/Koha/Exceptions.pm >+++ b/Koha/Exceptions.pm >@@ -8,11 +8,14 @@ use Exception::Class ( > 'Koha::Exceptions::Exception' => { > description => 'Something went wrong!', > }, >- > 'Koha::Exceptions::DuplicateObject' => { > isa => 'Koha::Exceptions::Exception', > description => 'Same object already exists', > }, >+ 'Koha::Exceptions::ObjectNotFound' => { >+ isa => 'Koha::Exceptions::Exception', >+ description => 'The required object doesn\'t exist', >+ }, > 'Koha::Exceptions::CannotDeleteDefault' => { > isa => 'Koha::Exceptions::Exception', > description => 'The default value cannot be deleted' >@@ -21,6 +24,10 @@ use Exception::Class ( > isa => 'Koha::Exceptions::Exception', > description => 'A required parameter is missing' > }, >+ 'Koha::Exceptions::CannotAddLibraryLimit' => { >+ isa => 'Koha::Exceptions::Exception', >+ description => 'General problem adding a library limit' >+ }, > # Virtualshelves exceptions > 'Koha::Exceptions::Virtualshelves::DuplicateObject' => { > isa => 'Koha::Exceptions::DuplicateObject', >diff --git a/Koha/Object/Limit/Library.pm b/Koha/Object/Limit/Library.pm >new file mode 100644 >index 0000000..678782b >--- /dev/null >+++ b/Koha/Object/Limit/Library.pm >@@ -0,0 +1,171 @@ >+package Koha::Object::Limit::Library; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Koha::Database; >+use Koha::Exceptions; >+ >+use Try::Tiny; >+ >+=head1 NAME >+ >+Koha::Object::Limit::Library - Generic library limit handling class >+ >+=head1 SYNOPSIS >+ >+ use base qw(Koha::Object Koha::Object::Limit::Library); >+ my $object = Koha::Object->new({ property1 => $property1, property2 => $property2, etc... } ); >+ >+=head1 DESCRIPTION >+ >+This class is provided as a generic way of handling library limits for Koha::Object-based classes >+in Koha. >+ >+This class must always be subclassed. >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 library_limits >+ >+my $limits = $object->library_limits(); >+ >+$object->library_limits( \@branchcodes ); >+ >+=cut >+ >+sub library_limits { >+ my ( $self, $branchcodes ) = @_; >+ >+ if ($branchcodes) { >+ return $self->replace_library_limits($branchcodes); >+ } >+ else { >+ return $self->get_library_limits(); >+ } >+} >+ >+=head3 get_library_limits >+ >+my $limits = $object->get_library_limits(); >+ >+=cut >+ >+sub get_library_limits { >+ my ($self) = @_; >+ >+ my @branchcodes >+ = $self->_library_limit_rs->search( >+ { $self->_library_limits->{id} => $self->id } ) >+ ->get_column( $self->_library_limits->{library} )->all(); >+ >+ return \@branchcodes; >+} >+ >+=head3 add_library_limit >+ >+$object->add_library_limit( $branchcode ); >+ >+=cut >+ >+sub add_library_limit { >+ my ( $self, $branchcode ) = @_; >+ >+ Koha::Exceptions::MissingParameter->throw( >+ "Required parameter 'branchcode' missing") >+ unless $branchcode; >+ >+ my $limitation; >+ try { >+ $limitation = $self->_library_limit_rs->update_or_create( >+ { $self->_library_limits->{id} => $self->id, >+ $self->_library_limits->{library} => $branchcode >+ } >+ ); >+ } >+ catch { >+ Koha::Exceptions::CannotAddLibraryLimit->throw( $_->{msg} ); >+ }; >+ >+ return $limitation ? 1 : undef; >+} >+ >+=head3 del_library_limit >+ >+$object->del_library_limit( $branchcode ); >+ >+=cut >+ >+sub del_library_limit { >+ my ( $self, $branchcode ) = @_; >+ >+ Koha::Exceptions::MissingParameter->throw( >+ "Required parameter 'branchcode' missing") >+ unless $branchcode; >+ >+ my $limitation = $self->_library_limit_rs->search( >+ { $self->_library_limits->{id} => $self->id, >+ $self->_library_limits->{library} => $branchcode >+ } >+ ); >+ >+ Koha::Exceptions::ObjectNotFound->throw( >+ "No branch limit for branch $branchcode found for id " >+ . $self->id >+ . " to delete!" ) >+ unless ($limitation->count); >+ >+ return $limitation->delete(); >+} >+ >+=head3 replace_library_limits >+ >+$object->replace_library_limits( \@branchcodes ); >+ >+=cut >+ >+sub replace_library_limits { >+ my ( $self, $branchcodes ) = @_; >+ >+ $self->_library_limit_rs->search( >+ { $self->_library_limits->{id} => $self->id } )->delete; >+ >+ my @return_values = map { $self->add_library_limit($_) } @$branchcodes; >+ >+ return \@return_values; >+} >+ >+=head3 Koha::Objects->_library_limit_rs >+ >+Returns the internal resultset for the branch limitation table or creates it if undefined >+ >+=cut >+ >+sub _library_limit_rs { >+ my ($self) = @_; >+ >+ $self->{_library_limit_rs} ||= Koha::Database->new->schema->resultset( >+ $self->_library_limits->{class} ); >+ >+ return $self->{_library_limit_rs}; >+} >+ >+1; >-- >2.7.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 17755
:
58142
|
58143
|
58144
|
58145
|
58167
|
58495
|
58496
|
58497
|
58498
|
59354
|
60989
|
60990
|
60991
|
60992
|
60995
|
61000
|
61001
|
61548
|
61549
|
61550
|
61551
|
61552