|
Lines 11-18
use File::Path;
Link Here
|
| 11 |
use C4::Biblio; |
11 |
use C4::Biblio; |
| 12 |
use C4::AuthoritiesMarc; |
12 |
use C4::AuthoritiesMarc; |
| 13 |
use C4::Items; |
13 |
use C4::Items; |
| 14 |
use Koha::RecordProcessor; |
14 |
use C4::ZebraIndex; |
| 15 |
use XML::LibXML; |
|
|
| 16 |
|
15 |
|
| 17 |
use constant LOCK_FILENAME => 'rebuild..LCK'; |
16 |
use constant LOCK_FILENAME => 'rebuild..LCK'; |
| 18 |
|
17 |
|
|
Lines 239-250
if ( $verbose_logging ) {
Link Here
|
| 239 |
} |
238 |
} |
| 240 |
if ($keep_export) { |
239 |
if ($keep_export) { |
| 241 |
print "NOTHING cleaned : the export $directory has been kept.\n"; |
240 |
print "NOTHING cleaned : the export $directory has been kept.\n"; |
| 242 |
print "You can re-run this script with the -s "; |
241 |
print "You can re-run this script with the -s and -d $directory parameters"; |
| 243 |
if ($use_tempdir) { |
|
|
| 244 |
print " and -d $directory parameters"; |
| 245 |
} else { |
| 246 |
print "parameter"; |
| 247 |
} |
| 248 |
print "\n"; |
242 |
print "\n"; |
| 249 |
print "if you just want to rebuild zebra after changing the record.abs\n"; |
243 |
print "if you just want to rebuild zebra after changing the record.abs\n"; |
| 250 |
print "or another zebra config file\n"; |
244 |
print "or another zebra config file\n"; |
|
Lines 315-387
sub check_zebra_dirs {
Link Here
|
| 315 |
sub index_records { |
309 |
sub index_records { |
| 316 |
my ($record_type, $directory, $skip_export, $skip_index, $process_zebraqueue, $as_xml, $noxml, $nosanitize, $do_not_clear_zebraqueue, $verbose_logging, $zebraidx_log_opt, $server_dir) = @_; |
310 |
my ($record_type, $directory, $skip_export, $skip_index, $process_zebraqueue, $as_xml, $noxml, $nosanitize, $do_not_clear_zebraqueue, $verbose_logging, $zebraidx_log_opt, $server_dir) = @_; |
| 317 |
|
311 |
|
| 318 |
my $num_records_exported = 0; |
|
|
| 319 |
my $records_deleted = {}; |
| 320 |
my $need_reset = check_zebra_dirs($server_dir); |
312 |
my $need_reset = check_zebra_dirs($server_dir); |
| 321 |
if ($need_reset) { |
313 |
if ($need_reset) { |
| 322 |
print "$0: found broken zebra server directories: forcing a rebuild\n"; |
314 |
print "$0: found broken zebra server directories: forcing a rebuild\n"; |
| 323 |
$reset = 1; |
315 |
$reset = 1; |
| 324 |
} |
316 |
} |
| 325 |
if ($skip_export && $verbose_logging) { |
317 |
|
|
|
318 |
if ( $verbose_logging ) { |
| 326 |
print "====================\n"; |
319 |
print "====================\n"; |
| 327 |
print "SKIPPING $record_type export\n"; |
320 |
print "REINDEXING zebra\n"; |
| 328 |
print "====================\n"; |
321 |
print "====================\n"; |
| 329 |
} else { |
|
|
| 330 |
if ( $verbose_logging ) { |
| 331 |
print "====================\n"; |
| 332 |
print "exporting $record_type\n"; |
| 333 |
print "====================\n"; |
| 334 |
} |
| 335 |
mkdir "$directory" unless (-d $directory); |
| 336 |
mkdir "$directory/$record_type" unless (-d "$directory/$record_type"); |
| 337 |
if ($process_zebraqueue) { |
| 338 |
my $entries; |
| 339 |
|
| 340 |
unless ( $process_zebraqueue_skip_deletes ) { |
| 341 |
$entries = select_zebraqueue_records($record_type, 'deleted'); |
| 342 |
mkdir "$directory/del_$record_type" unless (-d "$directory/del_$record_type"); |
| 343 |
$records_deleted = generate_deleted_marc_records($record_type, $entries, "$directory/del_$record_type", $as_xml); |
| 344 |
mark_zebraqueue_batch_done($entries); |
| 345 |
} |
| 346 |
|
| 347 |
$entries = select_zebraqueue_records($record_type, 'updated'); |
| 348 |
mkdir "$directory/upd_$record_type" unless (-d "$directory/upd_$record_type"); |
| 349 |
$num_records_exported = export_marc_records_from_list($record_type,$entries, "$directory/upd_$record_type", $as_xml, $noxml, $records_deleted); |
| 350 |
mark_zebraqueue_batch_done($entries); |
| 351 |
|
| 352 |
} else { |
| 353 |
my $sth = select_all_records($record_type); |
| 354 |
$num_records_exported = export_marc_records_from_sth($record_type, $sth, "$directory/$record_type", $as_xml, $noxml, $nosanitize); |
| 355 |
unless ($do_not_clear_zebraqueue) { |
| 356 |
mark_all_zebraqueue_done($record_type); |
| 357 |
} |
| 358 |
} |
| 359 |
} |
322 |
} |
| 360 |
|
323 |
|
| 361 |
# |
324 |
my $record_fmt = ($as_xml) ? 'marcxml' : 'iso2709' ; |
| 362 |
# and reindexing everything |
325 |
if ($process_zebraqueue) { |
| 363 |
# |
326 |
my ($entries, @entries_to_delete); |
| 364 |
if ($skip_index) { |
327 |
unless ( $process_zebraqueue_skip_deletes ) { |
| 365 |
if ($verbose_logging) { |
328 |
# Process 'deleted' records |
| 366 |
print "====================\n"; |
329 |
$entries = select_zebraqueue_records( $record_type, 'deleted' ); |
| 367 |
print "SKIPPING $record_type indexing\n"; |
330 |
@entries_to_delete = map { $_->{biblio_auth_id} } @$entries; |
| 368 |
print "====================\n"; |
331 |
|
|
|
332 |
C4::ZebraIndex::DeleteRecordIndex($record_type, \@entries_to_delete, { |
| 333 |
as_xml => $as_xml, noshadow => $noshadow, record_format => $record_fmt, |
| 334 |
zebraidx_log_opt => $zebraidx_log_opt, verbose => $verbose_logging, |
| 335 |
skip_export => $skip_export, skip_index => $skip_index, |
| 336 |
keep_export => $keep_export, directory => $directory |
| 337 |
}); |
| 338 |
|
| 339 |
mark_zebraqueue_batch_done($entries); |
| 369 |
} |
340 |
} |
|
|
341 |
|
| 342 |
# Process 'updated' records' |
| 343 |
$entries = select_zebraqueue_records( $record_type, 'updated' ); |
| 344 |
my @entries_to_update = map { |
| 345 |
my $id = $_->{biblio_auth_id}; |
| 346 |
# do not try to update deleted records |
| 347 |
(0 == grep { $id == $_ } @entries_to_delete) ? $id : () |
| 348 |
} @$entries; |
| 349 |
|
| 350 |
C4::ZebraIndex::IndexRecord($record_type, \@entries_to_update, { |
| 351 |
as_xml => $as_xml, noxml => $noxml, reset_index => $reset, |
| 352 |
noshadow => $noshadow, record_format => $record_fmt, |
| 353 |
zebraidx_log_opt => $zebraidx_log_opt, verbose => $verbose_logging, |
| 354 |
skip_export => $skip_export, skip_index => $skip_index, |
| 355 |
keep_export => $keep_export, directory => $directory |
| 356 |
}); |
| 357 |
|
| 358 |
mark_zebraqueue_batch_done($entries); |
| 370 |
} else { |
359 |
} else { |
| 371 |
if ( $verbose_logging ) { |
360 |
my $sth = select_all_records($record_type); |
| 372 |
print "====================\n"; |
361 |
my $entries = $sth->fetchall_arrayref([]); |
| 373 |
print "REINDEXING zebra\n"; |
362 |
my @entries_to_update = map { $_->[0] } @$entries; |
| 374 |
print "====================\n"; |
363 |
|
| 375 |
} |
364 |
C4::ZebraIndex::IndexRecord($record_type, \@entries_to_update, { |
| 376 |
my $record_fmt = ($as_xml) ? 'marcxml' : 'iso2709' ; |
365 |
as_xml => $as_xml, noxml => $noxml, reset_index => $reset, |
| 377 |
if ($process_zebraqueue) { |
366 |
noshadow => $noshadow, record_format => $record_fmt, |
| 378 |
do_indexing($record_type, 'adelete', "$directory/del_$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt) |
367 |
zebraidx_log_opt => $zebraidx_log_opt, nosanitize => $nosanitize, |
| 379 |
if %$records_deleted; |
368 |
verbose => $verbose_logging, skip_export => $skip_export, |
| 380 |
do_indexing($record_type, 'update', "$directory/upd_$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt) |
369 |
skip_index => $skip_index, keep_export => $keep_export, |
| 381 |
if $num_records_exported; |
370 |
directory => $directory |
| 382 |
} else { |
371 |
}); |
| 383 |
do_indexing($record_type, 'update', "$directory/$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt) |
372 |
|
| 384 |
if ($num_records_exported or $skip_export); |
373 |
unless ($do_not_clear_zebraqueue) { |
|
|
374 |
mark_all_zebraqueue_done($record_type); |
| 385 |
} |
375 |
} |
| 386 |
} |
376 |
} |
| 387 |
} |
377 |
} |
|
Lines 451-791
sub select_all_biblios {
Link Here
|
| 451 |
return $sth; |
441 |
return $sth; |
| 452 |
} |
442 |
} |
| 453 |
|
443 |
|
| 454 |
sub include_xml_wrapper { |
|
|
| 455 |
my $as_xml = shift; |
| 456 |
my $record_type = shift; |
| 457 |
|
| 458 |
return 0 unless $as_xml; |
| 459 |
return 1 if $record_type eq 'biblio' and $bib_index_mode eq 'dom'; |
| 460 |
return 1 if $record_type eq 'authority' and $auth_index_mode eq 'dom'; |
| 461 |
return 0; |
| 462 |
|
| 463 |
} |
| 464 |
|
| 465 |
sub export_marc_records_from_sth { |
| 466 |
my ($record_type, $sth, $directory, $as_xml, $noxml, $nosanitize) = @_; |
| 467 |
|
| 468 |
my $num_exported = 0; |
| 469 |
open my $fh, '>:encoding(UTF-8) ', "$directory/exported_records" or die $!; |
| 470 |
if (include_xml_wrapper($as_xml, $record_type)) { |
| 471 |
# include XML declaration and root element |
| 472 |
print {$fh} '<?xml version="1.0" encoding="UTF-8"?><collection>'; |
| 473 |
} |
| 474 |
my $i = 0; |
| 475 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",''); |
| 476 |
while (my ($record_number) = $sth->fetchrow_array) { |
| 477 |
print "." if ( $verbose_logging ); |
| 478 |
print "\r$i" unless ($i++ %100 or !$verbose_logging); |
| 479 |
if ( $nosanitize ) { |
| 480 |
my $marcxml = $record_type eq 'biblio' |
| 481 |
? GetXmlBiblio( $record_number ) |
| 482 |
: GetAuthorityXML( $record_number ); |
| 483 |
if ($record_type eq 'biblio'){ |
| 484 |
my @items = GetItemsInfo($record_number); |
| 485 |
if (@items){ |
| 486 |
my $record = MARC::Record->new; |
| 487 |
$record->encoding('UTF-8'); |
| 488 |
my @itemsrecord; |
| 489 |
foreach my $item (@items){ |
| 490 |
my $record = Item2Marc($item, $record_number); |
| 491 |
push @itemsrecord, $record->field($itemtag); |
| 492 |
} |
| 493 |
$record->insert_fields_ordered(@itemsrecord); |
| 494 |
my $itemsxml = $record->as_xml_record(); |
| 495 |
$marcxml = |
| 496 |
substr($marcxml, 0, length($marcxml)-10) . |
| 497 |
substr($itemsxml, index($itemsxml, "</leader>\n", 0) + 10); |
| 498 |
} |
| 499 |
} |
| 500 |
# extra test to ensure that result is valid XML; otherwise |
| 501 |
# Zebra won't parse it in DOM mode |
| 502 |
eval { |
| 503 |
my $doc = $tester->parse_string($marcxml); |
| 504 |
}; |
| 505 |
if ($@) { |
| 506 |
warn "Error exporting record $record_number ($record_type): $@\n"; |
| 507 |
next; |
| 508 |
} |
| 509 |
if ( $marcxml ) { |
| 510 |
$marcxml =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!; |
| 511 |
print {$fh} $marcxml; |
| 512 |
$num_exported++; |
| 513 |
} |
| 514 |
next; |
| 515 |
} |
| 516 |
my ($marc) = get_corrected_marc_record($record_type, $record_number, $noxml); |
| 517 |
if (defined $marc) { |
| 518 |
eval { |
| 519 |
my $rec; |
| 520 |
if ($as_xml) { |
| 521 |
$rec = $marc->as_xml_record(C4::Context->preference('marcflavour')); |
| 522 |
eval { |
| 523 |
my $doc = $tester->parse_string($rec); |
| 524 |
}; |
| 525 |
if ($@) { |
| 526 |
die "invalid XML: $@"; |
| 527 |
} |
| 528 |
$rec =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!; |
| 529 |
} else { |
| 530 |
$rec = $marc->as_usmarc(); |
| 531 |
} |
| 532 |
print {$fh} $rec; |
| 533 |
$num_exported++; |
| 534 |
}; |
| 535 |
if ($@) { |
| 536 |
warn "Error exporting record $record_number ($record_type) ".($noxml ? "not XML" : "XML"); |
| 537 |
warn "... specific error is $@" if $verbose_logging; |
| 538 |
} |
| 539 |
} |
| 540 |
} |
| 541 |
print "\nRecords exported: $num_exported\n" if ( $verbose_logging ); |
| 542 |
print {$fh} '</collection>' if (include_xml_wrapper($as_xml, $record_type)); |
| 543 |
close $fh; |
| 544 |
return $num_exported; |
| 545 |
} |
| 546 |
|
| 547 |
sub export_marc_records_from_list { |
| 548 |
my ($record_type, $entries, $directory, $as_xml, $noxml, $records_deleted) = @_; |
| 549 |
|
| 550 |
my $num_exported = 0; |
| 551 |
open my $fh, '>:encoding(UTF-8)', "$directory/exported_records" or die $!; |
| 552 |
if (include_xml_wrapper($as_xml, $record_type)) { |
| 553 |
# include XML declaration and root element |
| 554 |
print {$fh} '<?xml version="1.0" encoding="UTF-8"?><collection>'; |
| 555 |
} |
| 556 |
my $i = 0; |
| 557 |
|
| 558 |
# Skip any deleted records. We check for this anyway, but this reduces error spam |
| 559 |
my %found = %$records_deleted; |
| 560 |
foreach my $record_number ( map { $_->{biblio_auth_number} } |
| 561 |
grep { !$found{ $_->{biblio_auth_number} }++ } |
| 562 |
@$entries ) { |
| 563 |
print "." if ( $verbose_logging ); |
| 564 |
print "\r$i" unless ($i++ %100 or !$verbose_logging); |
| 565 |
my ($marc) = get_corrected_marc_record($record_type, $record_number, $noxml); |
| 566 |
if (defined $marc) { |
| 567 |
eval { |
| 568 |
my $rec; |
| 569 |
if ($as_xml) { |
| 570 |
$rec = $marc->as_xml_record(C4::Context->preference('marcflavour')); |
| 571 |
$rec =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!; |
| 572 |
} else { |
| 573 |
$rec = $marc->as_usmarc(); |
| 574 |
} |
| 575 |
print {$fh} $rec; |
| 576 |
$num_exported++; |
| 577 |
}; |
| 578 |
if ($@) { |
| 579 |
warn "Error exporting record $record_number ($record_type) ".($noxml ? "not XML" : "XML"); |
| 580 |
} |
| 581 |
} |
| 582 |
} |
| 583 |
print "\nRecords exported: $num_exported\n" if ( $verbose_logging ); |
| 584 |
print {$fh} '</collection>' if (include_xml_wrapper($as_xml, $record_type)); |
| 585 |
close $fh; |
| 586 |
return $num_exported; |
| 587 |
} |
| 588 |
|
| 589 |
sub generate_deleted_marc_records { |
| 590 |
my ($record_type, $entries, $directory, $as_xml) = @_; |
| 591 |
|
| 592 |
my $records_deleted = {}; |
| 593 |
open my $fh, '>:encoding(UTF-8)', "$directory/exported_records" or die $!; |
| 594 |
if (include_xml_wrapper($as_xml, $record_type)) { |
| 595 |
# include XML declaration and root element |
| 596 |
print {$fh} '<?xml version="1.0" encoding="UTF-8"?><collection>'; |
| 597 |
} |
| 598 |
my $i = 0; |
| 599 |
foreach my $record_number (map { $_->{biblio_auth_number} } @$entries ) { |
| 600 |
print "\r$i" unless ($i++ %100 or !$verbose_logging); |
| 601 |
print "." if ( $verbose_logging ); |
| 602 |
|
| 603 |
my $marc = MARC::Record->new(); |
| 604 |
if ($record_type eq 'biblio') { |
| 605 |
fix_biblio_ids($marc, $record_number, $record_number); |
| 606 |
} else { |
| 607 |
fix_authority_id($marc, $record_number); |
| 608 |
} |
| 609 |
if (C4::Context->preference("marcflavour") eq "UNIMARC") { |
| 610 |
fix_unimarc_100($marc); |
| 611 |
} |
| 612 |
|
| 613 |
my $rec; |
| 614 |
if ($as_xml) { |
| 615 |
$rec = $marc->as_xml_record(C4::Context->preference('marcflavour')); |
| 616 |
$rec =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!; |
| 617 |
} else { |
| 618 |
$rec = $marc->as_usmarc(); |
| 619 |
} |
| 620 |
print {$fh} $rec; |
| 621 |
|
| 622 |
$records_deleted->{$record_number} = 1; |
| 623 |
} |
| 624 |
print "\nRecords exported: $i\n" if ( $verbose_logging ); |
| 625 |
print {$fh} '</collection>' if (include_xml_wrapper($as_xml, $record_type)); |
| 626 |
close $fh; |
| 627 |
return $records_deleted; |
| 628 |
|
| 629 |
|
| 630 |
} |
| 631 |
|
| 632 |
sub get_corrected_marc_record { |
| 633 |
my ($record_type, $record_number, $noxml) = @_; |
| 634 |
|
| 635 |
my $marc = get_raw_marc_record($record_type, $record_number, $noxml); |
| 636 |
|
| 637 |
if (defined $marc) { |
| 638 |
fix_leader($marc); |
| 639 |
if ($record_type eq 'authority') { |
| 640 |
fix_authority_id($marc, $record_number); |
| 641 |
} elsif ($record_type eq 'biblio' && C4::Context->preference('IncludeSeeFromInSearches')) { |
| 642 |
my $normalizer = Koha::RecordProcessor->new( { filters => 'EmbedSeeFromHeadings' } ); |
| 643 |
$marc = $normalizer->process($marc); |
| 644 |
} |
| 645 |
if (C4::Context->preference("marcflavour") eq "UNIMARC") { |
| 646 |
fix_unimarc_100($marc); |
| 647 |
} |
| 648 |
} |
| 649 |
|
| 650 |
return $marc; |
| 651 |
} |
| 652 |
|
| 653 |
sub get_raw_marc_record { |
| 654 |
my ($record_type, $record_number, $noxml) = @_; |
| 655 |
|
| 656 |
my $marc; |
| 657 |
if ($record_type eq 'biblio') { |
| 658 |
if ($noxml) { |
| 659 |
my $fetch_sth = $dbh->prepare_cached("SELECT marc FROM biblioitems WHERE biblionumber = ?"); |
| 660 |
$fetch_sth->execute($record_number); |
| 661 |
if (my ($blob) = $fetch_sth->fetchrow_array) { |
| 662 |
$marc = MARC::Record->new_from_usmarc($blob); |
| 663 |
unless ($marc) { |
| 664 |
warn "error creating MARC::Record from $blob"; |
| 665 |
} |
| 666 |
} |
| 667 |
# failure to find a bib is not a problem - |
| 668 |
# a delete could have been done before |
| 669 |
# trying to process a record update |
| 670 |
|
| 671 |
$fetch_sth->finish(); |
| 672 |
return unless $marc; |
| 673 |
} else { |
| 674 |
eval { $marc = GetMarcBiblio($record_number, 1); }; |
| 675 |
if ($@ || !$marc) { |
| 676 |
# here we do warn since catching an exception |
| 677 |
# means that the bib was found but failed |
| 678 |
# to be parsed |
| 679 |
warn "error retrieving biblio $record_number"; |
| 680 |
return; |
| 681 |
} |
| 682 |
} |
| 683 |
} else { |
| 684 |
eval { $marc = GetAuthority($record_number); }; |
| 685 |
if ($@) { |
| 686 |
warn "error retrieving authority $record_number"; |
| 687 |
return; |
| 688 |
} |
| 689 |
} |
| 690 |
return $marc; |
| 691 |
} |
| 692 |
|
| 693 |
sub fix_leader { |
| 694 |
# FIXME - this routine is suspect |
| 695 |
# It blanks the Leader/00-05 and Leader/12-16 to |
| 696 |
# force them to be recalculated correct when |
| 697 |
# the $marc->as_usmarc() or $marc->as_xml() is called. |
| 698 |
# But why is this necessary? It would be a serious bug |
| 699 |
# in MARC::Record (definitely) and MARC::File::XML (arguably) |
| 700 |
# if they are emitting incorrect leader values. |
| 701 |
my $marc = shift; |
| 702 |
|
| 703 |
my $leader = $marc->leader; |
| 704 |
substr($leader, 0, 5) = ' '; |
| 705 |
substr($leader, 10, 7) = '22 '; |
| 706 |
$marc->leader(substr($leader, 0, 24)); |
| 707 |
} |
| 708 |
|
| 709 |
sub fix_biblio_ids { |
| 710 |
# FIXME - it is essential to ensure that the biblionumber is present, |
| 711 |
# otherwise, Zebra will choke on the record. However, this |
| 712 |
# logic belongs in the relevant C4::Biblio APIs. |
| 713 |
my $marc = shift; |
| 714 |
my $biblionumber = shift; |
| 715 |
my $biblioitemnumber; |
| 716 |
if (@_) { |
| 717 |
$biblioitemnumber = shift; |
| 718 |
} else { |
| 719 |
my $sth = $dbh->prepare( |
| 720 |
"SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?"); |
| 721 |
$sth->execute($biblionumber); |
| 722 |
($biblioitemnumber) = $sth->fetchrow_array; |
| 723 |
$sth->finish; |
| 724 |
unless ($biblioitemnumber) { |
| 725 |
warn "failed to get biblioitemnumber for biblio $biblionumber"; |
| 726 |
return 0; |
| 727 |
} |
| 728 |
} |
| 729 |
|
| 730 |
# FIXME - this is cheating on two levels |
| 731 |
# 1. C4::Biblio::_koha_marc_update_bib_ids is meant to be an internal function |
| 732 |
# 2. Making sure that the biblionumber and biblioitemnumber are correct and |
| 733 |
# present in the MARC::Record object ought to be part of GetMarcBiblio. |
| 734 |
# |
| 735 |
# On the other hand, this better for now than what rebuild_zebra.pl used to |
| 736 |
# do, which was duplicate the code for inserting the biblionumber |
| 737 |
# and biblioitemnumber |
| 738 |
C4::Biblio::_koha_marc_update_bib_ids($marc, '', $biblionumber, $biblioitemnumber); |
| 739 |
|
| 740 |
return 1; |
| 741 |
} |
| 742 |
|
| 743 |
sub fix_authority_id { |
| 744 |
# FIXME - as with fix_biblio_ids, the authid must be present |
| 745 |
# for Zebra's sake. However, this really belongs |
| 746 |
# in C4::AuthoritiesMarc. |
| 747 |
my ($marc, $authid) = @_; |
| 748 |
unless ($marc->field('001') and $marc->field('001')->data() eq $authid){ |
| 749 |
$marc->delete_field($marc->field('001')); |
| 750 |
$marc->insert_fields_ordered(MARC::Field->new('001',$authid)); |
| 751 |
} |
| 752 |
} |
| 753 |
|
| 754 |
sub fix_unimarc_100 { |
| 755 |
# FIXME - again, if this is necessary, it belongs in C4::AuthoritiesMarc. |
| 756 |
my $marc = shift; |
| 757 |
|
| 758 |
my $string; |
| 759 |
if ( length($marc->subfield( 100, "a" )) == 36 ) { |
| 760 |
$string = $marc->subfield( 100, "a" ); |
| 761 |
my $f100 = $marc->field(100); |
| 762 |
$marc->delete_field($f100); |
| 763 |
} |
| 764 |
else { |
| 765 |
$string = POSIX::strftime( "%Y%m%d", localtime ); |
| 766 |
$string =~ s/\-//g; |
| 767 |
$string = sprintf( "%-*s", 35, $string ); |
| 768 |
} |
| 769 |
substr( $string, 22, 6, "frey50" ); |
| 770 |
unless ( length($marc->subfield( 100, "a" )) == 36 ) { |
| 771 |
$marc->delete_field($marc->field(100)); |
| 772 |
$marc->insert_grouped_field(MARC::Field->new( 100, "", "", "a" => $string )); |
| 773 |
} |
| 774 |
} |
| 775 |
|
| 776 |
sub do_indexing { |
| 777 |
my ($record_type, $op, $record_dir, $reset_index, $noshadow, $record_format, $zebraidx_log_opt) = @_; |
| 778 |
|
| 779 |
my $zebra_server = ($record_type eq 'biblio') ? 'biblioserver' : 'authorityserver'; |
| 780 |
my $zebra_db_name = ($record_type eq 'biblio') ? 'biblios' : 'authorities'; |
| 781 |
my $zebra_config = C4::Context->zebraconfig($zebra_server)->{'config'}; |
| 782 |
my $zebra_db_dir = C4::Context->zebraconfig($zebra_server)->{'directory'}; |
| 783 |
|
| 784 |
system("zebraidx -c $zebra_config $zebraidx_log_opt -g $record_format -d $zebra_db_name init") if $reset_index; |
| 785 |
system("zebraidx -c $zebra_config $zebraidx_log_opt $noshadow -g $record_format -d $zebra_db_name $op $record_dir"); |
| 786 |
system("zebraidx -c $zebra_config $zebraidx_log_opt -g $record_format -d $zebra_db_name commit") unless $noshadow; |
| 787 |
|
| 788 |
} |
| 789 |
|
444 |
|
| 790 |
sub _flock { |
445 |
sub _flock { |
| 791 |
# test if flock is present; if so, use it; if not, return true |
446 |
# test if flock is present; if so, use it; if not, return true |
| 792 |
- |
|
|