Lines 227-236
sub process_update {
Link Here
|
227 |
my $marcxml; |
227 |
my $marcxml; |
228 |
if ($server eq "biblioserver") { |
228 |
if ($server eq "biblioserver") { |
229 |
my $marc = GetMarcBiblio($record_number); |
229 |
my $marc = GetMarcBiblio($record_number); |
230 |
$marcxml = $marc->as_xml_record() if $marc; |
230 |
if($marc) { |
|
|
231 |
fix_leader($marc); |
232 |
if(fix_biblio_ids($dbh, $marc, $record_number)) { |
233 |
fix_unimarc_100($marc) if C4::Context->preference("marcflavour") eq "UNIMARC"; |
234 |
$marcxml = $marc->as_xml_record(); |
235 |
} |
236 |
} |
231 |
} |
237 |
} |
232 |
elsif ($server eq "authorityserver") { |
238 |
elsif ($server eq "authorityserver") { |
233 |
$marcxml = C4::AuthoritiesMarc::GetAuthorityXML($record_number); |
239 |
my $marc = C4::AuthoritiesMarc::GetAuthority($record_number); |
|
|
240 |
if($marc) { |
241 |
fix_authority_id($marc, $record_number); |
242 |
fix_unimarc_100($marc) if C4::Context->preference("marcflavour") eq "UNIMARC"; |
243 |
$marcxml = $marc->as_xml_record(); |
244 |
} |
234 |
} |
245 |
} |
235 |
# check it's XML, just in case |
246 |
# check it's XML, just in case |
236 |
eval { |
247 |
eval { |
Lines 442-447
sub get_zebra_connection {
Link Here
|
442 |
} |
453 |
} |
443 |
} |
454 |
} |
444 |
|
455 |
|
|
|
456 |
sub fix_leader { |
457 |
# FIXME - this routine is suspect |
458 |
# It blanks the Leader/00-05 and Leader/12-16 to |
459 |
# force them to be recalculated correct when |
460 |
# the $marc->as_usmarc() or $marc->as_xml() is called. |
461 |
# But why is this necessary? It would be a serious bug |
462 |
# in MARC::Record (definitely) and MARC::File::XML (arguably) |
463 |
# if they are emitting incorrect leader values. |
464 |
my $marc = shift; |
465 |
|
466 |
my $leader = $marc->leader; |
467 |
substr($leader, 0, 5) = ' '; |
468 |
substr($leader, 10, 7) = '22 '; |
469 |
$marc->leader(substr($leader, 0, 24)); |
470 |
} |
471 |
|
472 |
sub fix_biblio_ids { |
473 |
# FIXME - it is essential to ensure that the biblionumber is present, |
474 |
# otherwise, Zebra will choke on the record. However, this |
475 |
# logic belongs in the relevant C4::Biblio APIs. |
476 |
my $dbh = shift; |
477 |
my $marc = shift; |
478 |
my $biblionumber = shift; |
479 |
my $biblioitemnumber; |
480 |
if (@_) { |
481 |
$biblioitemnumber = shift; |
482 |
} else { |
483 |
my $sth = $dbh->prepare( |
484 |
"SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?"); |
485 |
$sth->execute($biblionumber); |
486 |
($biblioitemnumber) = $sth->fetchrow_array; |
487 |
$sth->finish; |
488 |
unless ($biblioitemnumber) { |
489 |
warn "failed to get biblioitemnumber for biblio $biblionumber"; |
490 |
return 0; |
491 |
} |
492 |
} |
493 |
|
494 |
# FIXME - this is cheating on two levels |
495 |
# 1. C4::Biblio::_koha_marc_update_bib_ids is meant to be an internal function |
496 |
# 2. Making sure that the biblionumber and biblioitemnumber are correct and |
497 |
# present in the MARC::Record object ought to be part of GetMarcBiblio. |
498 |
# |
499 |
# On the other hand, this better for now than what rebuild_zebra.pl used to |
500 |
# do, which was duplicate the code for inserting the biblionumber |
501 |
# and biblioitemnumber |
502 |
C4::Biblio::_koha_marc_update_bib_ids($marc, '', $biblionumber, $biblioitemnumber); |
503 |
|
504 |
return 1; |
505 |
} |
506 |
|
507 |
sub fix_authority_id { |
508 |
# FIXME - as with fix_biblio_ids, the authid must be present |
509 |
# for Zebra's sake. However, this really belongs |
510 |
# in C4::AuthoritiesMarc. |
511 |
my ($marc, $authid) = @_; |
512 |
unless ($marc->field('001') and $marc->field('001')->data() eq $authid){ |
513 |
$marc->delete_field($marc->field('001')); |
514 |
$marc->insert_fields_ordered(MARC::Field->new('001',$authid)); |
515 |
} |
516 |
} |
517 |
|
518 |
sub fix_unimarc_100 { |
519 |
# FIXME - again, if this is necessary, it belongs in C4::AuthoritiesMarc. |
520 |
my $marc = shift; |
521 |
|
522 |
my $string; |
523 |
if ( length($marc->subfield( 100, "a" )) == 35 ) { |
524 |
$string = $marc->subfield( 100, "a" ); |
525 |
my $f100 = $marc->field(100); |
526 |
$marc->delete_field($f100); |
527 |
} |
528 |
else { |
529 |
$string = POSIX::strftime( "%Y%m%d", localtime ); |
530 |
$string =~ s/\-//g; |
531 |
$string = sprintf( "%-*s", 35, $string ); |
532 |
} |
533 |
substr( $string, 22, 6, "frey50" ); |
534 |
unless ( length($marc->subfield( 100, "a" )) == 35 ) { |
535 |
$marc->delete_field($marc->field(100)); |
536 |
$marc->insert_grouped_field(MARC::Field->new( 100, "", "", "a" => $string )); |
537 |
} |
538 |
} |
539 |
|
445 |
# given a ZOOM::Exception or |
540 |
# given a ZOOM::Exception or |
446 |
# ZOOM::Connection object, generate |
541 |
# ZOOM::Connection object, generate |
447 |
# a human-reaable error message |
542 |
# a human-reaable error message |
448 |
- |
|
|