item rework: replace direct SQL update of items
authorGalen Charlton <galen.charlton@liblime.com>
Thu, 3 Jan 2008 18:36:27 +0000 (12:36 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Thu, 3 Jan 2008 22:24:38 +0000 (16:24 -0600)
with ModItem calls

Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Accounts.pm
C4/Circulation.pm
misc/cronjobs/fines2.pl
misc/cronjobs/longoverdue.pl

index 7fe1df0..11b9378 100644 (file)
@@ -23,6 +23,7 @@ require Exporter;
 use C4::Context;
 use C4::Stats;
 use C4::Members;
+use C4::Items;
 
 #use C4::Circulation;
 use vars qw($VERSION @ISA @EXPORT);
@@ -279,9 +280,7 @@ sub returnlost {
       ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
     my $bor =
 "$borrower->{'firstname'} $borrower->{'surname'} $borrower->{'cardnumber'}";
-    $sth = $dbh->prepare("UPDATE items SET paidfor=? WHERE itemnumber=?");
-    $sth->execute( "Paid for by $bor $date", $itemnum );
-    $sth->finish;
+    ModItem({ paidfor =>  "Paid for by $bor $date" }, undef, $itemnum);
 }
 
 =head2 manualinvoice
index da0375d..4ee2e28 100644 (file)
@@ -1436,9 +1436,7 @@ sub FixAccountForLostAndReturned {
                        VALUES (?,?,?,?)");
                $usth->execute($borrower->{'borrowernumber'},$data->{'accountno'},$nextaccntno,$offset);
                $usth->finish;
-               $usth = $dbh->prepare("UPDATE items SET paidfor='' WHERE itemnumber=?");
-               $usth->execute($itm);
-               $usth->finish;
+        ModItem({ paidfor => '' }, undef, $itm);
        }
        $sth->finish;
        return;
@@ -1968,18 +1966,10 @@ Simple methode for updating hodlingbranch in items BDD line
 =cut
 
 sub UpdateHoldingbranch {
-       my ( $branch,$itmenumber ) = @_;
-       my $dbh = C4::Context->dbh;     
-# first step validate the actual line of transfert .
-       my $sth =
-               $dbh->prepare(
-                       "update items set holdingbranch = ? where itemnumber= ?"
-               );
-               $sth->execute($branch,$itmenumber);
-               $sth->finish;
-        
-       
+       my ( $branch,$itemnumber ) = @_;
+    ModItem({ holdingbranch => $branch }, undef, $itemnumber);
 }
+
 =head2 CheckValidDatedue
 
 $newdatedue = CheckValidDatedue($date_due,$itemnumber,$branchcode);
index 596e664..ae4b3b9 100755 (executable)
@@ -39,6 +39,7 @@ use C4::Circulation;
 use C4::Overdues;
 use Date::Manip;
 use C4::Biblio;
+use C4::Items;
 
 open (FILE,'>/tmp/fines') || die;
 # FIXME
@@ -120,9 +121,7 @@ for (my $i=0;$i<scalar(@$data);$i++){
                     $sth->execute($data->[$i]->{'borrowernumber'},$data->[$i]->{'itemnumber'},
                     $accountno,$cost,"Lost item $item->{'title'} $item->{'barcode'} $due",$cost);
                     $sth->finish;
-                    $sth=$dbh->prepare("UPDATE items SET itemlost=2 WHERE itemnumber=?");
-                    $sth->execute($data->[$i]->{'itemnumber'});
-                    $sth->finish;
+                    ModItem({ itemlost => 2 }, undef, $data->[$i]->{'itemnumber'});
                 }
             }
         }
index 256cd85..b47923b 100755 (executable)
@@ -20,20 +20,19 @@ BEGIN {
     eval { require "$FindBin::Bin/../kohalib.pl" };
 }
 use C4::Context;
+use C4::Items;
 
 my $dbh = C4::Context->dbh;
 
 my $itemnos_sth=$dbh->prepare("SELECT items.itemnumber FROM issues,items WHERE items.itemnumber=issues.itemnumber AND DATE_SUB(CURDATE(),INTERVAL 90 DAY) > date_due AND returndate IS NULL AND (itemlost=0 OR itemlost IS NULL)");
-my $put_sth=$dbh->prepare("UPDATE items SET itemlost=2 WHERE itemnumber=?");
 
 #    get itemnumbers of items more than 90 days overdue
 $itemnos_sth->execute();
 
 while (my $row=$itemnos_sth->fetchrow_arrayref) {
-    my $item=$row->[0];
+    my $itemnumber=$row->[0];
 
-    $put_sth->execute($item);
-    $put_sth->finish;
+    ModItem({ itemlost => 2 }, undef, $itemnumber);
 #    print "$item\n";
 }