[Koha-patches] [PATCH] Move checks of additem.pl to the API

henridamien.laurent at biblibre.com henridamien.laurent at biblibre.com
Fri Mar 6 11:38:05 CET 2009


From: Nahuel Angelinetti <nahuel.angelinetti at biblibre.com>

This patch create a new function DelItemCheck, that add some checks before deleting an item and return 1 if it worked fine, else an error
code (the same as in additem.pl).

Signed-off-by: Henri-Damien LAURENT <henridamien.laurent at biblibre.com>
---
 C4/Items.pm            |   42 ++++++++++++++++++++++++++++++++++++++++++
 cataloguing/additem.pl |   27 ++++++---------------------
 2 files changed, 48 insertions(+), 21 deletions(-)

diff --git a/C4/Items.pm b/C4/Items.pm
index c69d693..81ec0c9 100644
--- a/C4/Items.pm
+++ b/C4/Items.pm
@@ -49,6 +49,7 @@ BEGIN {
         ModDateLastSeen
         ModItemTransfer
         DelItem
+        DelItemCheck
     
         CheckItemPreSave
     
@@ -586,6 +587,47 @@ sub DelItem {
     logaction("CATALOGUING", "DELETE", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
 }
 
+=head2 DelItemCheck
+
+=over 4
+
+DelItemCheck($dbh, $biblionumber, $itemnumber);
+
+=back
+
+Exported function (core API) for deleting an item record in Koha if there no current issue.
+
+=cut
+
+sub DelItemCheck {
+    my ( $dbh, $biblionumber, $itemnumber ) = @_;
+    my $error;
+
+    # check that there is no issue on this item before deletion.
+    my $sth=$dbh->prepare("select * from issues i where i.itemnumber=?");
+    $sth->execute($itemnumber);
+
+    my $onloan=$sth->fetchrow;
+
+    $sth->finish();
+    if ($onloan){
+        $error = "book_on_loan" 
+    }else{
+        # check it doesnt have a waiting reserve
+        $sth=$dbh->prepare("SELECT * FROM reserves WHERE found = 'W' AND itemnumber = ?");
+        $sth->execute($itemnumber);
+        my $reserve=$sth->fetchrow;
+        $sth->finish();
+        if ($reserve){
+            $error = "book_reserved";
+        }else{
+            DelItem($dbh, $biblionumber, $itemnumber);
+            return 1;
+        }
+    }
+    return $error;
+}
+
 =head2 CheckItemPreSave
 
 =over 4
diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl
index 376687c..ee551c9 100755
--- a/cataloguing/additem.pl
+++ b/cataloguing/additem.pl
@@ -134,27 +134,12 @@ if ($op eq "additem") {
 #-------------------------------------------------------------------------------
 } elsif ($op eq "delitem") {
 #-------------------------------------------------------------------------------
-    # check that there is no issue on this item before deletion.
-    my $sth=$dbh->prepare("select * from issues i where i.itemnumber=?");
-    $sth->execute($itemnumber);
-    my $onloan=$sth->fetchrow;
-	$sth->finish();
-    push @errors,"book_on_loan" if ($onloan); ##error book_on_loan added to template as well
-    if ($onloan){
-		$nextop="additem";
-    } else {
-		# check it doesnt have a waiting reserve
-		$sth=$dbh->prepare("SELECT * FROM reserves WHERE found = 'W' AND itemnumber = ?");
-		$sth->execute($itemnumber);
-		my $reserve=$sth->fetchrow;
-		if ($reserve){
-			push @errors,"book_reserved";
-			$nextop="additem";
-		}
-		else {
-			&DelItem($dbh,$biblionumber,$itemnumber);
-			print $input->redirect("additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode");
-		}
+    $error = &DelItemCheck($dbh,$biblionumber,$itemnumber);
+    if($error == 1){
+        print $input->redirect("additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode");
+    }else{
+        push @errors,$error;
+        $nextop="additem";
     }
 #-------------------------------------------------------------------------------
 } elsif ($op eq "delallitems") {
-- 
1.5.6.3




More information about the Koha-patches mailing list