MT 1975 : Fixed broken MoveItemFromBiblio in Items.pm

This commit is contained in:
Matthias Meusburger 2009-09-25 11:23:40 +02:00 committed by Henri-Damien LAURENT
parent 9eba7dc594
commit 56750eebba

View file

@ -2032,12 +2032,39 @@ sub MoveItemFromBiblio {
my $sth = $dbh->prepare("UPDATE items SET biblioitemnumber = ?, biblionumber = ? WHERE itemnumber = ? AND biblionumber = ?");
my $return = $sth->execute($tobiblio, $tobiblio, $itemnumber, $frombiblio);
if ($return == 1) {
my $record = GetMarcBiblio($frombiblio);
# Getting framework
my $frameworkcode = GetFrameworkCode($frombiblio);
# Getting marc field for itemnumber
my ($itemtag, $itemsubfield) = GetMarcFromKohaField('items.itemnumber', $frameworkcode);
# Getting the record we want to move the item from
my $record = GetMarcBiblio($frombiblio);
# The item we want to move
my $item;
# For each item
foreach my $fielditem ($record->field($itemtag)){
# If it is the item we want to move
if ($fielditem->subfield($itemsubfield) == $itemnumber) {
# We save it
$item = $fielditem;
# Then delete it from the record
$record->delete_field($fielditem)
}
}
# Saving the modification
ModBiblioMarc($record, $frombiblio, $frameworkcode);
# Getting the record we want to move the item to
$record = GetMarcBiblio($tobiblio);
$frameworkcode = GetFrameworkCode($frombiblio);
# Inserting the previously saved item
$record->insert_fields_ordered($item);
# Saving the modification
ModBiblioMarc($record, $tobiblio, $frameworkcode);
} else {
return -1;