From 3b43e43e494681105308a55ffe1e9cfdb513d0c1 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 3 Jan 2008 12:36:34 -0600 Subject: [PATCH] item rework: moved DelItem Moved from C4::Biblio to C4::Items Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Biblio.pm | 81 ---------------------------------------------------- C4/Items.pm | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 81 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 37fda9393e..ca2d48b42b 100755 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -81,7 +81,6 @@ push @EXPORT, qw( # To delete something push @EXPORT, qw( &DelBiblio - &DelItem ); # Internal functions @@ -518,48 +517,6 @@ sub DelBiblio { return; } -=head2 DelItem - -=over - -DelItem( $biblionumber, $itemnumber ); -Exported function (core API) for deleting an item record in Koha. - -=back - -=cut - -sub DelItem { - my ( $dbh, $biblionumber, $itemnumber ) = @_; - - # check the item has no current issues - - - &_koha_delete_item( $dbh, $itemnumber ); - - # get the MARC record - my $record = GetMarcBiblio($biblionumber); - my $frameworkcode = GetFrameworkCode($biblionumber); - - # backup the record - my $copy2deleted = $dbh->prepare("UPDATE deleteditems SET marc=? WHERE itemnumber=?"); - $copy2deleted->execute( $record->as_usmarc(), $itemnumber ); - - #search item field code - my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",$frameworkcode); - my @fields = $record->field($itemtag); - - # delete the item specified - foreach my $field (@fields) { - if ( $field->subfield($itemsubfield) eq $itemnumber ) { - $record->delete_field($field); - } - } - &ModBiblioMarc( $record, $biblionumber, $frameworkcode ); - &logaction(C4::Context->userenv->{'number'},"CATALOGUING","DELETE",$itemnumber,"item") - if C4::Context->preference("CataloguingLog"); -} - =head2 CheckItemPreSave =over 4 @@ -3391,44 +3348,6 @@ sub _koha_delete_biblioitems { return undef; } -=head2 _koha_delete_item - -=over 4 - -_koha_delete_item( $dbh, $itemnum ); - -Internal function to delete an item record from the koha tables - -=back - -=cut - -sub _koha_delete_item { - my ( $dbh, $itemnum ) = @_; - - # save the deleted item to deleteditems table - my $sth = $dbh->prepare("SELECT * FROM items WHERE itemnumber=?"); - $sth->execute($itemnum); - my $data = $sth->fetchrow_hashref(); - $sth->finish(); - my $query = "INSERT INTO deleteditems SET "; - my @bind = (); - foreach my $key ( keys %$data ) { - $query .= "$key = ?,"; - push( @bind, $data->{$key} ); - } - $query =~ s/\,$//; - $sth = $dbh->prepare($query); - $sth->execute(@bind); - $sth->finish(); - - # delete from items table - $sth = $dbh->prepare("DELETE FROM items WHERE itemnumber=?"); - $sth->execute($itemnum); - $sth->finish(); - return undef; -} - =head1 UNEXPORTED FUNCTIONS =head2 ModBiblioMarc diff --git a/C4/Items.pm b/C4/Items.pm index ca8d74f9ce..0b224b5ac8 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -45,6 +45,7 @@ my $VERSION = 3.00; ModItem ModDateLastSeen ModItemTransfer + DelItem GetItemStatus GetItemLocation @@ -338,6 +339,48 @@ sub ModDateLastSeen { ModItem({ itemlost => 0, datelastseen => $today->output("iso") }, undef, $itemnumber); } +=head2 DelItem + +=over 4 + +DelItem($biblionumber, $itemnumber); + +=back + +Exported function (core API) for deleting an item record in Koha. + +=cut + +sub DelItem { + my ( $dbh, $biblionumber, $itemnumber ) = @_; + + # FIXME check the item has no current issues + + _koha_delete_item( $dbh, $itemnumber ); + + # get the MARC record + my $record = GetMarcBiblio($biblionumber); + my $frameworkcode = GetFrameworkCode($biblionumber); + + # backup the record + my $copy2deleted = $dbh->prepare("UPDATE deleteditems SET marc=? WHERE itemnumber=?"); + $copy2deleted->execute( $record->as_usmarc(), $itemnumber ); + + #search item field code + my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",$frameworkcode); + my @fields = $record->field($itemtag); + + # delete the item specified + foreach my $field (@fields) { + if ( $field->subfield($itemsubfield) eq $itemnumber ) { + $record->delete_field($field); + } + } + &ModBiblioMarc( $record, $biblionumber, $frameworkcode ); + &logaction(C4::Context->userenv->{'number'},"CATALOGUING","DELETE",$itemnumber,"item") + if C4::Context->preference("CataloguingLog"); +} + =head1 EXPORTED SPECIAL ACCESSOR FUNCTIONS The following functions provide various ways of @@ -1423,6 +1466,44 @@ sub _koha_modify_item { return ($item->{'itemnumber'},$error); } +=head2 _koha_delete_item + +=over 4 + +_koha_delete_item( $dbh, $itemnum ); + +=back + +Internal function to delete an item record from the koha tables + +=cut + +sub _koha_delete_item { + my ( $dbh, $itemnum ) = @_; + + # save the deleted item to deleteditems table + my $sth = $dbh->prepare("SELECT * FROM items WHERE itemnumber=?"); + $sth->execute($itemnum); + my $data = $sth->fetchrow_hashref(); + $sth->finish(); + my $query = "INSERT INTO deleteditems SET "; + my @bind = (); + foreach my $key ( keys %$data ) { + $query .= "$key = ?,"; + push( @bind, $data->{$key} ); + } + $query =~ s/\,$//; + $sth = $dbh->prepare($query); + $sth->execute(@bind); + $sth->finish(); + + # delete from items table + $sth = $dbh->prepare("DELETE FROM items WHERE itemnumber=?"); + $sth->execute($itemnum); + $sth->finish(); + return undef; +} + =head2 _marc_from_item_hash =over 4 -- 2.39.5