From 5fc1c11198c74ae2921be7c365dd7b1198f6325b Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 29 Jan 2016 01:46:02 +0000 Subject: [PATCH] Bug 7677 [QA Followup] - Replace GetItemnumberFromSerialId with use of Koha::Serial::Item(s) GetItemnumberFromSerialId has no unit tests. It would be better to start using our object system here. Signed-off-by: Katrin Fischer Signed-off-by: Kyle M Hall --- C4/Serials.pm | 27 +------------------ Koha/Serial/Item.pm | 52 ++++++++++++++++++++++++++++++++++++ Koha/Serial/Items.pm | 58 +++++++++++++++++++++++++++++++++++++++++ serials/serials-edit.pl | 5 +++- 4 files changed, 115 insertions(+), 27 deletions(-) create mode 100644 Koha/Serial/Item.pm create mode 100644 Koha/Serial/Items.pm diff --git a/C4/Serials.pm b/C4/Serials.pm index 3408c470e4..3c76cd8260 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -66,7 +66,7 @@ BEGIN { @EXPORT = qw( &NewSubscription &ModSubscription &DelSubscription &GetSubscription &CountSubscriptionFromBiblionumber &GetSubscriptionsFromBiblionumber - &SearchSubscriptions &GetItemnumberFromSerialId + &SearchSubscriptions &GetFullSubscriptionsFromBiblionumber &GetFullSubscription &ModSubscriptionHistory &HasSubscriptionStrictlyExpired &HasSubscriptionExpired &GetExpirationDate &abouttoexpire &GetSubscriptionHistoryFromSubscriptionId @@ -183,33 +183,8 @@ sub GetSerialStatusFromSerialId { return $dbh->prepare($query); } -=head2 GetItemnumberFromSerialId - -$itemnumber = GetSerialInformation($serialid); -this function returns the itemnumber, given a serialid in parameter -return : itemnumber - -=cut - -sub GetItemnumberFromSerialId { - my ($serialid) = @_; - my $dbh = C4::Context->dbh; - my $query = qq| - SELECT itemnumber - FROM serialitems - WHERE serialid = ? - |; - my $sth = $dbh->prepare($query); - $sth->execute($serialid); - my ($result) = $sth->fetchrow; - return ($result); -} - - - =head2 GetSerialInformation - $data = GetSerialInformation($serialid); returns a hash_ref containing : items : items marcrecord (can be an array) diff --git a/Koha/Serial/Item.pm b/Koha/Serial/Item.pm new file mode 100644 index 0000000000..3509b3deb3 --- /dev/null +++ b/Koha/Serial/Item.pm @@ -0,0 +1,52 @@ +package Koha::Serial::Item; + +# Copyright ByWater Solutions 2016 +# +# 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 Carp; + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Serial::Item - Koha Serial Item Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Serialitem'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/Serial/Items.pm b/Koha/Serial/Items.pm new file mode 100644 index 0000000000..fbd6227b8b --- /dev/null +++ b/Koha/Serial/Items.pm @@ -0,0 +1,58 @@ +package Koha::Serial::Items; + +# Copyright ByWater Solutions 2016 +# +# 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 Carp; + +use Koha::Database; + +use Koha::Serial::Item; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Serial::Items - Koha Serial Items Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Serialitem'; +} + +sub object_class { + return 'Koha::Serial::Item'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/serials/serials-edit.pl b/serials/serials-edit.pl index 125c70193d..12efa67930 100755 --- a/serials/serials-edit.pl +++ b/serials/serials-edit.pl @@ -74,6 +74,7 @@ use C4::Context; use C4::Serials; use C4::Search qw/enabled_staff_search_views/; use Koha::DateUtils; +use Koha::Serial::Items; use List::MoreUtils qw/uniq/; @@ -256,7 +257,9 @@ if ( $op and $op eq 'serialchangestatus' ) { my $previous = GetPreviousSerialid($subscriptionids[$i]); if ($previous) { - if (my $itemnumber = GetItemnumberFromSerialId($previous)) { + my $serialitem = Koha::Serial::Items->find( $previous ); + my $itemnumber = $serialitem ? $serialitem->itemnumber : undef; + if ($itemnumber) { # Getting the itemtype to set from the database my $subscriptioninfos = GetSubscription($subscriptionids[$i]); -- 2.39.5