From bc9ee0cff9e12828c1135997c5a8b0dc8477c873 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 3 Jan 2008 12:36:17 -0600 Subject: [PATCH] item rework: moved ModItemInMarc * Moved exported ModItemInMarc from C4::Biblio to C4::Items and renamed to _replace_item_field_in_biblio. Function is now private and is not exported, as ModItem is now the sole entry point for updating an item record. * Replaced calls to ModItemInMarc in C4::Circulation with appropriate ModItem calls. Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Biblio.pm | 33 --------------------------------- C4/Circulation.pm | 36 ++++++++++-------------------------- C4/Items.pm | 32 +++++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 60 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 6edc0ee0a7..d4571d36b8 100755 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -88,7 +88,6 @@ push @EXPORT, qw( &ModBiblio &ModBiblioframework &ModZebra - &ModItemInMarc ); # To delete something @@ -470,38 +469,6 @@ sub ModBiblioframework { return 1; } -=head2 ModItemInMarc - -=over - -&ModItemInMarc( $record, $biblionumber, $itemnumber, $frameworkcode ) - -=back - -=cut - -sub ModItemInMarc { - my ( $ItemRecord, $biblionumber, $itemnumber, $frameworkcode) = @_; - my $dbh = C4::Context->dbh; - - # get complete MARC record & replace the item field by the new one - my $completeRecord = GetMarcBiblio($biblionumber); - my ($itemtag,$itemsubfield) = GetMarcFromKohaField("items.itemnumber",$frameworkcode); - my $itemField = $ItemRecord->field($itemtag); - my @items = $completeRecord->field($itemtag); - foreach (@items) { - if ($_->subfield($itemsubfield) eq $itemnumber) { -# $completeRecord->delete_field($_); - $_->replace_with($itemField); - } - } - # save the record - my $sth = $dbh->prepare("UPDATE biblioitems SET marc=?,marcxml=? WHERE biblionumber=?"); - $sth->execute( $completeRecord->as_usmarc(), $completeRecord->as_xml_record(),$biblionumber ); - $sth->finish; - ModZebra($biblionumber,"specialUpdate","biblioserver",$completeRecord); -} - =head2 DelBiblio =over diff --git a/C4/Circulation.pm b/C4/Circulation.pm index ca3c34fe34..da0375d3a1 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1013,20 +1013,14 @@ sub AddIssue { ); $sth->finish; $item->{'issues'}++; - $sth = - $dbh->prepare( - "UPDATE items SET issues=?, holdingbranch=?, itemlost=0, datelastborrowed = now(), onloan = ? WHERE itemnumber=?"); - $sth->execute( - $item->{'issues'}, - C4::Context->userenv->{'branch'}, - $dateduef->output('iso'), - $item->{'itemnumber'} - ); - $sth->finish; - &ModDateLastSeen( $item->{'itemnumber'} ); - my $record = GetMarcItem( $item->{'biblionumber'}, $item->{'itemnumber'} ); - my $frameworkcode = GetFrameworkCode( $item->{'biblionumber'} ); - ModItemInMarc( $record, $item->{'biblionumber'}, $item->{'itemnumber'}, $frameworkcode ); + ModItem({ issues => $item->{'issues'}, + holdingbranch => C4::Context->userenv->{'branch'}, + itemlost => 0, + datelastborrowed => C4::Dates->new()->output('iso'), + onloan => $dateduef->output('iso'), + }, $item->{'biblionumber'}, $item->{'itemnumber'}); + ModDateLastSeen( $item->{'itemnumber'} ); + # If it costs to borrow this book, charge it to the patron's account. my ( $charge, $itemtype ) = GetIssuingCharges( $item->{'itemnumber'}, @@ -1235,12 +1229,7 @@ sub AddReturn { $iteminformation->{'holdingbranch'} = C4::Context->userenv->{'branch'}; } ModDateLastSeen( $iteminformation->{'itemnumber'} ); - my $sth = $dbh->prepare("UPDATE items SET onloan = NULL where itemnumber = ?"); - $sth->execute($iteminformation->{'itemnumber'}); - $sth->finish(); - my $record = GetMarcItem( $biblio->{'biblionumber'}, $iteminformation->{'itemnumber'} ); - my $frameworkcode = GetFrameworkCode( $biblio->{'biblionumber'} ); - ModItemInMarc( $record, $biblio->{'biblionumber'}, $iteminformation->{'itemnumber'}, $frameworkcode ); + ModItem({ onloan => undef }, $biblio->{'biblionumber'}, $iteminformation->{'itemnumber'}); if ($iteminformation->{borrowernumber}){ ($borrower) = C4::Members::GetMemberDetails( $iteminformation->{borrowernumber}, 0 ); @@ -1712,12 +1701,7 @@ sub AddRenewal { # Update the renewal count on the item, and tell zebra to reindex $renews = $biblio->{'renewals'} + 1; - $sth = $dbh->prepare("UPDATE items SET renewals = ? WHERE itemnumber = ?"); - $sth->execute($renews,$itemnumber); - $sth->finish(); - my $record = GetMarcItem( $biblio->{'biblionumber'}, $itemnumber ); - my $frameworkcode = GetFrameworkCode( $biblio->{'biblionumber'} ); - ModItemInMarc( $record, $biblio->{'biblionumber'}, $itemnumber, $frameworkcode ); + ModItem({ renewals => $renews }, $biblio->{'biblionumber'}, $itemnumber); # Charge a new rental fee, if applicable? my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); diff --git a/C4/Items.pm b/C4/Items.pm index 29e4da53c8..a3c972503e 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -201,7 +201,7 @@ sub ModItem { # update biblio MARC XML my $whole_item = GetItem($itemnumber); my $new_item_marc = _marc_from_item_hash($whole_item, $frameworkcode); - ModItemInMarc($new_item_marc, $biblionumber, $itemnumber, $frameworkcode); + _replace_item_field_in_biblio($new_item_marc, $biblionumber, $itemnumber, $frameworkcode); logaction(C4::Context->userenv->{'number'},"CATALOGUING","MODIFY",$itemnumber,$new_item_marc->as_formatted) if C4::Context->preference("CataloguingLog"); @@ -687,4 +687,34 @@ sub _add_item_field_to_biblio { ModBiblioMarc($biblio_marc, $biblionumber, $frameworkcode); } + +=head2 _replace_item_field_in_biblio + +=over + +&_replace_item_field_in_biblio( $record, $biblionumber, $itemnumber, $frameworkcode ) + +=back + +=cut + +sub _replace_item_field_in_biblio { + my ($ItemRecord, $biblionumber, $itemnumber, $frameworkcode) = @_; + my $dbh = C4::Context->dbh; + + # get complete MARC record & replace the item field by the new one + my $completeRecord = GetMarcBiblio($biblionumber); + my ($itemtag,$itemsubfield) = GetMarcFromKohaField("items.itemnumber",$frameworkcode); + my $itemField = $ItemRecord->field($itemtag); + my @items = $completeRecord->field($itemtag); + foreach (@items) { + if ($_->subfield($itemsubfield) eq $itemnumber) { + $_->replace_with($itemField); + } + } + + # save the record + ModBiblioMarc($completeRecord, $biblionumber, $frameworkcode); +} + 1; -- 2.39.5