From 35f8f65b416191222c88c342b948d79a5ea7ba51 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 3 Jan 2008 12:36:27 -0600 Subject: [PATCH] item rework: replace direct SQL update of items with ModItem calls Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Accounts.pm | 5 ++--- C4/Circulation.pm | 18 ++++-------------- misc/cronjobs/fines2.pl | 5 ++--- misc/cronjobs/longoverdue.pl | 7 +++---- 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/C4/Accounts.pm b/C4/Accounts.pm index 7fe1df0c88..11b937895d 100644 --- a/C4/Accounts.pm +++ b/C4/Accounts.pm @@ -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 diff --git a/C4/Circulation.pm b/C4/Circulation.pm index da0375d3a1..4ee2e28075 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -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); diff --git a/misc/cronjobs/fines2.pl b/misc/cronjobs/fines2.pl index 596e664a40..ae4b3b9138 100755 --- a/misc/cronjobs/fines2.pl +++ b/misc/cronjobs/fines2.pl @@ -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;$iexecute($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'}); } } } diff --git a/misc/cronjobs/longoverdue.pl b/misc/cronjobs/longoverdue.pl index 256cd856fe..b47923b3ea 100755 --- a/misc/cronjobs/longoverdue.pl +++ b/misc/cronjobs/longoverdue.pl @@ -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"; } -- 2.39.5