[Koha-patches] [PATCH] [bug #2781] Move checks of additem.pl to the API
Nahuel Angelinetti
nahuel.angelinetti at biblibre.com
Thu Nov 13 15:35:08 CET 2008
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).
---
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 a0d2a4b..e0064a5 100644
--- a/C4/Items.pm
+++ b/C4/Items.pm
@@ -49,6 +49,7 @@ BEGIN {
ModDateLastSeen
ModItemTransfer
DelItem
+ DelItemCheck
CheckItemPreSave
@@ -536,6 +537,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 f8780c2..c114de3 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 "saveitem") {
--
1.5.6.3
More information about the Koha-patches
mailing list