Lines 424-429
sub AddItemsToImportBiblio {
Link Here
|
424 |
my $dbh = C4::Context->dbh; |
424 |
my $dbh = C4::Context->dbh; |
425 |
my ($item_tag,$item_subfield) = &GetMarcFromKohaField("items.itemnumber",''); |
425 |
my ($item_tag,$item_subfield) = &GetMarcFromKohaField("items.itemnumber",''); |
426 |
foreach my $item_field ($marc_record->field($item_tag)) { |
426 |
foreach my $item_field ($marc_record->field($item_tag)) { |
|
|
427 |
my ($b_tag,$b_sub) = &GetMarcFromKohaField("items.barcode",''); |
428 |
my ($c_tag,$c_sub) = &GetMarcFromKohaField("items.itemcallnumber",''); |
429 |
unless ( $item_field->subfield( $item_subfield ) || $item_field->subfield( $b_sub ) || $item_field->subfield( $c_sub ) ) { |
430 |
# No itemnumber, barcode, or call number. |
431 |
# This is probably a repeated subfield stuffed into it's own |
432 |
# field. The best action would be to join it to the previous |
433 |
# item record so we don't loose any data. |
434 |
# Yes, I have actually seen records like this from a vendor |
435 |
my $import_id = $import_items_ids[ $#import_items_ids ]; |
436 |
my $sth = $dbh->prepare("SELECT marcxml FROM import_items WHERE import_items_id = ?"); |
437 |
$sth->bind_param(1, $import_id); |
438 |
$sth->execute(); |
439 |
my ( $xml ) = $sth->fetchrow_array; |
440 |
my $item_marc = MARC::Record->new_from_xml( $xml ); |
441 |
foreach my $subfield ( $item_field->subfields() ) { |
442 |
my $data = $item_marc->subfield( $item_tag, $subfield->[0] ); |
443 |
$data .= " | " if ( $data ); |
444 |
$data .= $subfield->[1]; |
445 |
for my $field ( $item_marc->field( $item_tag ) ) { |
446 |
$field->update( $subfield->[0] => $data ); |
447 |
} |
448 |
} |
449 |
|
450 |
$sth = $dbh->prepare("UPDATE import_items SET marcxml = ? WHERE import_items_id = ?"); |
451 |
$sth->bind_param(1, $item_marc->as_xml()); |
452 |
$sth->bind_param(2, $import_id); |
453 |
$sth->execute(); |
454 |
|
455 |
next; |
456 |
} |
457 |
|
458 |
# make sure home and holding branch are set |
459 |
my $branch = C4::Context::userenv->{branch}; |
460 |
my ($h_tag,$h_sub) = &GetMarcFromKohaField("items.homebranch",''); |
461 |
my ($h2_tag,$h2_sub) = &GetMarcFromKohaField("items.holdingbranch",''); |
462 |
unless ( $item_field->subfield( $h_sub ) ) { |
463 |
$item_field->add_subfields( $h_sub, $branch ) if ( $branch ); |
464 |
} |
465 |
unless ( $item_field->subfield( $h2_sub ) ) { |
466 |
$item_field->add_subfields( $h2_sub, $branch ) if ( $branch ); |
467 |
} |
468 |
|
427 |
my $item_marc = MARC::Record->new(); |
469 |
my $item_marc = MARC::Record->new(); |
428 |
$item_marc->leader("00000 a "); # must set Leader/09 to 'a' |
470 |
$item_marc->leader("00000 a "); # must set Leader/09 to 'a' |
429 |
$item_marc->append_fields($item_field); |
471 |
$item_marc->append_fields($item_field); |
430 |
- |
|
|