Bug 7677 [QA Followup] - Replace GetItemnumberFromSerialId with use of Koha::Serial...
authorKyle M Hall <kyle@bywatersolutions.com>
Fri, 29 Jan 2016 01:46:02 +0000 (01:46 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Mon, 12 Sep 2016 09:13:56 +0000 (09:13 +0000)
GetItemnumberFromSerialId has no unit tests. It would be better to start
using our object system here.

Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

C4/Serials.pm
Koha/Serial/Item.pm [new file with mode: 0644]
Koha/Serial/Items.pm [new file with mode: 0644]
serials/serials-edit.pl

index 3408c47..3c76cd8 100644 (file)
@@ -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 (file)
index 0000000..3509b3d
--- /dev/null
@@ -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 <kyle@bywatersolutions.com>
+
+=cut
+
+1;
diff --git a/Koha/Serial/Items.pm b/Koha/Serial/Items.pm
new file mode 100644 (file)
index 0000000..fbd6227
--- /dev/null
@@ -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 <kyle@bywatersolutions.com>
+
+=cut
+
+1;
index 125c701..12efa67 100755 (executable)
@@ -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]);