item rework: moved DelItem
authorGalen Charlton <galen.charlton@liblime.com>
Thu, 3 Jan 2008 18:36:34 +0000 (12:36 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Thu, 3 Jan 2008 22:25:07 +0000 (16:25 -0600)
Moved from C4::Biblio to C4::Items

Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Biblio.pm
C4/Items.pm

index 37fda93..ca2d48b 100755 (executable)
@@ -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
index ca8d74f..0b224b5 100644 (file)
@@ -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