|
Lines 10-17
use File::Path;
Link Here
|
| 10 |
use C4::Biblio; |
10 |
use C4::Biblio; |
| 11 |
use C4::AuthoritiesMarc; |
11 |
use C4::AuthoritiesMarc; |
| 12 |
use C4::Items; |
12 |
use C4::Items; |
| 13 |
use Koha::RecordProcessor; |
13 |
use C4::ZebraIndex; |
| 14 |
use XML::LibXML; |
|
|
| 15 |
|
14 |
|
| 16 |
# script that checks zebradir structure & create directories & mandatory files if needed |
15 |
# script that checks zebradir structure & create directories & mandatory files if needed |
| 17 |
# |
16 |
# |
|
Lines 181-192
if ( $verbose_logging ) {
Link Here
|
| 181 |
} |
180 |
} |
| 182 |
if ($keep_export) { |
181 |
if ($keep_export) { |
| 183 |
print "NOTHING cleaned : the export $directory has been kept.\n"; |
182 |
print "NOTHING cleaned : the export $directory has been kept.\n"; |
| 184 |
print "You can re-run this script with the -s "; |
183 |
print "You can re-run this script with the -s and -d $directory parameters"; |
| 185 |
if ($use_tempdir) { |
|
|
| 186 |
print " and -d $directory parameters"; |
| 187 |
} else { |
| 188 |
print "parameter"; |
| 189 |
} |
| 190 |
print "\n"; |
184 |
print "\n"; |
| 191 |
print "if you just want to rebuild zebra after changing the record.abs\n"; |
185 |
print "if you just want to rebuild zebra after changing the record.abs\n"; |
| 192 |
print "or another zebra config file\n"; |
186 |
print "or another zebra config file\n"; |
|
Lines 257-324
sub check_zebra_dirs {
Link Here
|
| 257 |
sub index_records { |
251 |
sub index_records { |
| 258 |
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) = @_; |
252 |
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) = @_; |
| 259 |
|
253 |
|
| 260 |
my $num_records_exported = 0; |
|
|
| 261 |
my $records_deleted; |
| 262 |
my $need_reset = check_zebra_dirs($server_dir); |
254 |
my $need_reset = check_zebra_dirs($server_dir); |
| 263 |
if ($need_reset) { |
255 |
if ($need_reset) { |
| 264 |
print "$0: found broken zebra server directories: forcing a rebuild\n"; |
256 |
print "$0: found broken zebra server directories: forcing a rebuild\n"; |
| 265 |
$reset = 1; |
257 |
$reset = 1; |
| 266 |
} |
258 |
} |
| 267 |
if ($skip_export && $verbose_logging) { |
259 |
|
|
|
260 |
if ( $verbose_logging ) { |
| 268 |
print "====================\n"; |
261 |
print "====================\n"; |
| 269 |
print "SKIPPING $record_type export\n"; |
262 |
print "REINDEXING zebra\n"; |
| 270 |
print "====================\n"; |
263 |
print "====================\n"; |
| 271 |
} else { |
|
|
| 272 |
if ( $verbose_logging ) { |
| 273 |
print "====================\n"; |
| 274 |
print "exporting $record_type\n"; |
| 275 |
print "====================\n"; |
| 276 |
} |
| 277 |
mkdir "$directory" unless (-d $directory); |
| 278 |
mkdir "$directory/$record_type" unless (-d "$directory/$record_type"); |
| 279 |
if ($process_zebraqueue) { |
| 280 |
my $entries = select_zebraqueue_records($record_type, 'deleted'); |
| 281 |
mkdir "$directory/del_$record_type" unless (-d "$directory/del_$record_type"); |
| 282 |
$records_deleted = generate_deleted_marc_records($record_type, $entries, "$directory/del_$record_type", $as_xml); |
| 283 |
mark_zebraqueue_batch_done($entries); |
| 284 |
$entries = select_zebraqueue_records($record_type, 'updated'); |
| 285 |
mkdir "$directory/upd_$record_type" unless (-d "$directory/upd_$record_type"); |
| 286 |
$num_records_exported = export_marc_records_from_list($record_type, |
| 287 |
$entries, "$directory/upd_$record_type", $as_xml, $noxml, $records_deleted); |
| 288 |
mark_zebraqueue_batch_done($entries); |
| 289 |
} else { |
| 290 |
my $sth = select_all_records($record_type); |
| 291 |
$num_records_exported = export_marc_records_from_sth($record_type, $sth, "$directory/$record_type", $as_xml, $noxml, $nosanitize); |
| 292 |
unless ($do_not_clear_zebraqueue) { |
| 293 |
mark_all_zebraqueue_done($record_type); |
| 294 |
} |
| 295 |
} |
| 296 |
} |
264 |
} |
| 297 |
|
265 |
|
| 298 |
# |
266 |
my $record_fmt = ($as_xml) ? 'marcxml' : 'iso2709' ; |
| 299 |
# and reindexing everything |
267 |
if ($process_zebraqueue) { |
| 300 |
# |
268 |
# Process 'deleted' records |
| 301 |
if ($skip_index) { |
269 |
my $entries = select_zebraqueue_records( $record_type, 'deleted' ); |
| 302 |
if ($verbose_logging) { |
270 |
my @entries_to_delete = map { $_->{biblio_auth_id} } @$entries; |
| 303 |
print "====================\n"; |
271 |
|
| 304 |
print "SKIPPING $record_type indexing\n"; |
272 |
C4::ZebraIndex::DeleteRecordIndex($record_type, \@entries_to_delete, { |
| 305 |
print "====================\n"; |
273 |
as_xml => $as_xml, noshadow => $noshadow, record_format => $record_fmt, |
| 306 |
} |
274 |
zebraidx_log_opt => $zebraidx_log_opt, verbose => $verbose_logging, |
|
|
275 |
skip_export => $skip_export, skip_index => $skip_index, |
| 276 |
keep_export => $keep_export, directory => $directory |
| 277 |
}); |
| 278 |
|
| 279 |
mark_zebraqueue_batch_done($entries); |
| 280 |
|
| 281 |
# Process 'updated' records' |
| 282 |
$entries = select_zebraqueue_records( $record_type, 'updated' ); |
| 283 |
my @entries_to_update = map { |
| 284 |
my $id = $_->{biblio_auth_id}; |
| 285 |
# do not try to update deleted records |
| 286 |
(0 == grep { $id == $_ } @entries_to_delete) ? $id : () |
| 287 |
} @$entries; |
| 288 |
|
| 289 |
C4::ZebraIndex::IndexRecord($record_type, \@entries_to_update, { |
| 290 |
as_xml => $as_xml, noxml => $noxml, reset_index => $reset, |
| 291 |
noshadow => $noshadow, record_format => $record_fmt, |
| 292 |
zebraidx_log_opt => $zebraidx_log_opt, verbose => $verbose_logging, |
| 293 |
skip_export => $skip_export, skip_index => $skip_index, |
| 294 |
keep_export => $keep_export, directory => $directory |
| 295 |
}); |
| 296 |
|
| 297 |
mark_zebraqueue_batch_done($entries); |
| 307 |
} else { |
298 |
} else { |
| 308 |
if ( $verbose_logging ) { |
299 |
my $sth = select_all_records($record_type); |
| 309 |
print "====================\n"; |
300 |
my $entries = $sth->fetchall_arrayref([]); |
| 310 |
print "REINDEXING zebra\n"; |
301 |
my @entries_to_update = map { $_->[0] } @$entries; |
| 311 |
print "====================\n"; |
302 |
|
| 312 |
} |
303 |
C4::ZebraIndex::IndexRecord($record_type, \@entries_to_update, { |
| 313 |
my $record_fmt = ($as_xml) ? 'marcxml' : 'iso2709' ; |
304 |
as_xml => $as_xml, noxml => $noxml, reset_index => $reset, |
| 314 |
if ($process_zebraqueue) { |
305 |
noshadow => $noshadow, record_format => $record_fmt, |
| 315 |
do_indexing($record_type, 'adelete', "$directory/del_$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt) |
306 |
zebraidx_log_opt => $zebraidx_log_opt, nosanitize => $nosanitize, |
| 316 |
if %$records_deleted; |
307 |
verbose => $verbose_logging, skip_export => $skip_export, |
| 317 |
do_indexing($record_type, 'update', "$directory/upd_$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt) |
308 |
skip_index => $skip_index, keep_export => $keep_export, |
| 318 |
if $num_records_exported; |
309 |
directory => $directory |
| 319 |
} else { |
310 |
}); |
| 320 |
do_indexing($record_type, 'update', "$directory/$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt) |
311 |
|
| 321 |
if ($num_records_exported or $skip_export); |
312 |
unless ($do_not_clear_zebraqueue) { |
|
|
313 |
mark_all_zebraqueue_done($record_type); |
| 322 |
} |
314 |
} |
| 323 |
} |
315 |
} |
| 324 |
} |
316 |
} |
|
Lines 388-728
sub select_all_biblios {
Link Here
|
| 388 |
return $sth; |
380 |
return $sth; |
| 389 |
} |
381 |
} |
| 390 |
|
382 |
|
| 391 |
sub include_xml_wrapper { |
|
|
| 392 |
my $as_xml = shift; |
| 393 |
my $record_type = shift; |
| 394 |
|
| 395 |
return 0 unless $as_xml; |
| 396 |
return 1 if $record_type eq 'biblio' and $bib_index_mode eq 'dom'; |
| 397 |
return 1 if $record_type eq 'authority' and $auth_index_mode eq 'dom'; |
| 398 |
return 0; |
| 399 |
|
| 400 |
} |
| 401 |
|
| 402 |
sub export_marc_records_from_sth { |
| 403 |
my ($record_type, $sth, $directory, $as_xml, $noxml, $nosanitize) = @_; |
| 404 |
|
| 405 |
my $num_exported = 0; |
| 406 |
open my $fh, '>:encoding(UTF-8) ', "$directory/exported_records" or die $!; |
| 407 |
if (include_xml_wrapper($as_xml, $record_type)) { |
| 408 |
# include XML declaration and root element |
| 409 |
print {$fh} '<?xml version="1.0" encoding="UTF-8"?><collection>'; |
| 410 |
} |
| 411 |
my $i = 0; |
| 412 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",''); |
| 413 |
while (my ($record_number) = $sth->fetchrow_array) { |
| 414 |
print "." if ( $verbose_logging ); |
| 415 |
print "\r$i" unless ($i++ %100 or !$verbose_logging); |
| 416 |
if ( $nosanitize ) { |
| 417 |
my $marcxml = $record_type eq 'biblio' |
| 418 |
? GetXmlBiblio( $record_number ) |
| 419 |
: GetAuthorityXML( $record_number ); |
| 420 |
if ($record_type eq 'biblio'){ |
| 421 |
my @items = GetItemsInfo($record_number); |
| 422 |
if (@items){ |
| 423 |
my $record = MARC::Record->new; |
| 424 |
$record->encoding('UTF-8'); |
| 425 |
my @itemsrecord; |
| 426 |
foreach my $item (@items){ |
| 427 |
my $record = Item2Marc($item, $record_number); |
| 428 |
push @itemsrecord, $record->field($itemtag); |
| 429 |
} |
| 430 |
$record->insert_fields_ordered(@itemsrecord); |
| 431 |
my $itemsxml = $record->as_xml_record(); |
| 432 |
$marcxml = |
| 433 |
substr($marcxml, 0, length($marcxml)-10) . |
| 434 |
substr($itemsxml, index($itemsxml, "</leader>\n", 0) + 10); |
| 435 |
} |
| 436 |
} |
| 437 |
# extra test to ensure that result is valid XML; otherwise |
| 438 |
# Zebra won't parse it in DOM mode |
| 439 |
eval { |
| 440 |
my $doc = $tester->parse_string($marcxml); |
| 441 |
}; |
| 442 |
if ($@) { |
| 443 |
warn "Error exporting record $record_number ($record_type): $@\n"; |
| 444 |
next; |
| 445 |
} |
| 446 |
if ( $marcxml ) { |
| 447 |
$marcxml =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!; |
| 448 |
print {$fh} $marcxml; |
| 449 |
$num_exported++; |
| 450 |
} |
| 451 |
next; |
| 452 |
} |
| 453 |
my ($marc) = get_corrected_marc_record($record_type, $record_number, $noxml); |
| 454 |
if (defined $marc) { |
| 455 |
eval { |
| 456 |
my $rec; |
| 457 |
if ($as_xml) { |
| 458 |
$rec = $marc->as_xml_record(C4::Context->preference('marcflavour')); |
| 459 |
eval { |
| 460 |
my $doc = $tester->parse_string($rec); |
| 461 |
}; |
| 462 |
if ($@) { |
| 463 |
die "invalid XML: $@"; |
| 464 |
} |
| 465 |
$rec =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!; |
| 466 |
} else { |
| 467 |
$rec = $marc->as_usmarc(); |
| 468 |
} |
| 469 |
print {$fh} $rec; |
| 470 |
$num_exported++; |
| 471 |
}; |
| 472 |
if ($@) { |
| 473 |
warn "Error exporting record $record_number ($record_type) ".($noxml ? "not XML" : "XML"); |
| 474 |
warn "... specific error is $@" if $verbose_logging; |
| 475 |
} |
| 476 |
} |
| 477 |
} |
| 478 |
print "\nRecords exported: $num_exported\n" if ( $verbose_logging ); |
| 479 |
print {$fh} '</collection>' if (include_xml_wrapper($as_xml, $record_type)); |
| 480 |
close $fh; |
| 481 |
return $num_exported; |
| 482 |
} |
| 483 |
|
| 484 |
sub export_marc_records_from_list { |
| 485 |
my ($record_type, $entries, $directory, $as_xml, $noxml, $records_deleted) = @_; |
| 486 |
|
| 487 |
my $num_exported = 0; |
| 488 |
open my $fh, '>:encoding(UTF-8)', "$directory/exported_records" or die $!; |
| 489 |
if (include_xml_wrapper($as_xml, $record_type)) { |
| 490 |
# include XML declaration and root element |
| 491 |
print {$fh} '<?xml version="1.0" encoding="UTF-8"?><collection>'; |
| 492 |
} |
| 493 |
my $i = 0; |
| 494 |
|
| 495 |
# Skip any deleted records. We check for this anyway, but this reduces error spam |
| 496 |
my %found = %$records_deleted; |
| 497 |
foreach my $record_number ( map { $_->{biblio_auth_number} } |
| 498 |
grep { !$found{ $_->{biblio_auth_number} }++ } |
| 499 |
@$entries ) { |
| 500 |
print "." if ( $verbose_logging ); |
| 501 |
print "\r$i" unless ($i++ %100 or !$verbose_logging); |
| 502 |
my ($marc) = get_corrected_marc_record($record_type, $record_number, $noxml); |
| 503 |
if (defined $marc) { |
| 504 |
eval { |
| 505 |
my $rec; |
| 506 |
if ($as_xml) { |
| 507 |
$rec = $marc->as_xml_record(C4::Context->preference('marcflavour')); |
| 508 |
$rec =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!; |
| 509 |
} else { |
| 510 |
$rec = $marc->as_usmarc(); |
| 511 |
} |
| 512 |
print {$fh} $rec; |
| 513 |
$num_exported++; |
| 514 |
}; |
| 515 |
if ($@) { |
| 516 |
warn "Error exporting record $record_number ($record_type) ".($noxml ? "not XML" : "XML"); |
| 517 |
} |
| 518 |
} |
| 519 |
} |
| 520 |
print "\nRecords exported: $num_exported\n" if ( $verbose_logging ); |
| 521 |
print {$fh} '</collection>' if (include_xml_wrapper($as_xml, $record_type)); |
| 522 |
close $fh; |
| 523 |
return $num_exported; |
| 524 |
} |
| 525 |
|
| 526 |
sub generate_deleted_marc_records { |
| 527 |
my ($record_type, $entries, $directory, $as_xml) = @_; |
| 528 |
|
| 529 |
my $records_deleted = {}; |
| 530 |
open my $fh, '>:encoding(UTF-8)', "$directory/exported_records" or die $!; |
| 531 |
if (include_xml_wrapper($as_xml, $record_type)) { |
| 532 |
# include XML declaration and root element |
| 533 |
print {$fh} '<?xml version="1.0" encoding="UTF-8"?><collection>'; |
| 534 |
} |
| 535 |
my $i = 0; |
| 536 |
foreach my $record_number (map { $_->{biblio_auth_number} } @$entries ) { |
| 537 |
print "\r$i" unless ($i++ %100 or !$verbose_logging); |
| 538 |
print "." if ( $verbose_logging ); |
| 539 |
|
| 540 |
my $marc = MARC::Record->new(); |
| 541 |
if ($record_type eq 'biblio') { |
| 542 |
fix_biblio_ids($marc, $record_number, $record_number); |
| 543 |
} else { |
| 544 |
fix_authority_id($marc, $record_number); |
| 545 |
} |
| 546 |
if (C4::Context->preference("marcflavour") eq "UNIMARC") { |
| 547 |
fix_unimarc_100($marc); |
| 548 |
} |
| 549 |
|
| 550 |
my $rec; |
| 551 |
if ($as_xml) { |
| 552 |
$rec = $marc->as_xml_record(C4::Context->preference('marcflavour')); |
| 553 |
$rec =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!; |
| 554 |
} else { |
| 555 |
$rec = $marc->as_usmarc(); |
| 556 |
} |
| 557 |
print {$fh} $rec; |
| 558 |
|
| 559 |
$records_deleted->{$record_number} = 1; |
| 560 |
} |
| 561 |
print "\nRecords exported: $i\n" if ( $verbose_logging ); |
| 562 |
print {$fh} '</collection>' if (include_xml_wrapper($as_xml, $record_type)); |
| 563 |
close $fh; |
| 564 |
return $records_deleted; |
| 565 |
|
| 566 |
|
| 567 |
} |
| 568 |
|
| 569 |
sub get_corrected_marc_record { |
| 570 |
my ($record_type, $record_number, $noxml) = @_; |
| 571 |
|
| 572 |
my $marc = get_raw_marc_record($record_type, $record_number, $noxml); |
| 573 |
|
| 574 |
if (defined $marc) { |
| 575 |
fix_leader($marc); |
| 576 |
if ($record_type eq 'authority') { |
| 577 |
fix_authority_id($marc, $record_number); |
| 578 |
} elsif ($record_type eq 'biblio' && C4::Context->preference('IncludeSeeFromInSearches')) { |
| 579 |
my $normalizer = Koha::RecordProcessor->new( { filters => 'EmbedSeeFromHeadings' } ); |
| 580 |
$marc = $normalizer->process($marc); |
| 581 |
} |
| 582 |
if (C4::Context->preference("marcflavour") eq "UNIMARC") { |
| 583 |
fix_unimarc_100($marc); |
| 584 |
} |
| 585 |
} |
| 586 |
|
| 587 |
return $marc; |
| 588 |
} |
| 589 |
|
| 590 |
sub get_raw_marc_record { |
| 591 |
my ($record_type, $record_number, $noxml) = @_; |
| 592 |
|
| 593 |
my $marc; |
| 594 |
if ($record_type eq 'biblio') { |
| 595 |
if ($noxml) { |
| 596 |
my $fetch_sth = $dbh->prepare_cached("SELECT marc FROM biblioitems WHERE biblionumber = ?"); |
| 597 |
$fetch_sth->execute($record_number); |
| 598 |
if (my ($blob) = $fetch_sth->fetchrow_array) { |
| 599 |
$marc = MARC::Record->new_from_usmarc($blob); |
| 600 |
unless ($marc) { |
| 601 |
warn "error creating MARC::Record from $blob"; |
| 602 |
} |
| 603 |
} |
| 604 |
# failure to find a bib is not a problem - |
| 605 |
# a delete could have been done before |
| 606 |
# trying to process a record update |
| 607 |
|
| 608 |
$fetch_sth->finish(); |
| 609 |
return unless $marc; |
| 610 |
} else { |
| 611 |
eval { $marc = GetMarcBiblio($record_number, 1); }; |
| 612 |
if ($@ || !$marc) { |
| 613 |
# here we do warn since catching an exception |
| 614 |
# means that the bib was found but failed |
| 615 |
# to be parsed |
| 616 |
warn "error retrieving biblio $record_number"; |
| 617 |
return; |
| 618 |
} |
| 619 |
} |
| 620 |
} else { |
| 621 |
eval { $marc = GetAuthority($record_number); }; |
| 622 |
if ($@) { |
| 623 |
warn "error retrieving authority $record_number"; |
| 624 |
return; |
| 625 |
} |
| 626 |
} |
| 627 |
return $marc; |
| 628 |
} |
| 629 |
|
| 630 |
sub fix_leader { |
| 631 |
# FIXME - this routine is suspect |
| 632 |
# It blanks the Leader/00-05 and Leader/12-16 to |
| 633 |
# force them to be recalculated correct when |
| 634 |
# the $marc->as_usmarc() or $marc->as_xml() is called. |
| 635 |
# But why is this necessary? It would be a serious bug |
| 636 |
# in MARC::Record (definitely) and MARC::File::XML (arguably) |
| 637 |
# if they are emitting incorrect leader values. |
| 638 |
my $marc = shift; |
| 639 |
|
| 640 |
my $leader = $marc->leader; |
| 641 |
substr($leader, 0, 5) = ' '; |
| 642 |
substr($leader, 10, 7) = '22 '; |
| 643 |
$marc->leader(substr($leader, 0, 24)); |
| 644 |
} |
| 645 |
|
| 646 |
sub fix_biblio_ids { |
| 647 |
# FIXME - it is essential to ensure that the biblionumber is present, |
| 648 |
# otherwise, Zebra will choke on the record. However, this |
| 649 |
# logic belongs in the relevant C4::Biblio APIs. |
| 650 |
my $marc = shift; |
| 651 |
my $biblionumber = shift; |
| 652 |
my $biblioitemnumber; |
| 653 |
if (@_) { |
| 654 |
$biblioitemnumber = shift; |
| 655 |
} else { |
| 656 |
my $sth = $dbh->prepare( |
| 657 |
"SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?"); |
| 658 |
$sth->execute($biblionumber); |
| 659 |
($biblioitemnumber) = $sth->fetchrow_array; |
| 660 |
$sth->finish; |
| 661 |
unless ($biblioitemnumber) { |
| 662 |
warn "failed to get biblioitemnumber for biblio $biblionumber"; |
| 663 |
return 0; |
| 664 |
} |
| 665 |
} |
| 666 |
|
| 667 |
# FIXME - this is cheating on two levels |
| 668 |
# 1. C4::Biblio::_koha_marc_update_bib_ids is meant to be an internal function |
| 669 |
# 2. Making sure that the biblionumber and biblioitemnumber are correct and |
| 670 |
# present in the MARC::Record object ought to be part of GetMarcBiblio. |
| 671 |
# |
| 672 |
# On the other hand, this better for now than what rebuild_zebra.pl used to |
| 673 |
# do, which was duplicate the code for inserting the biblionumber |
| 674 |
# and biblioitemnumber |
| 675 |
C4::Biblio::_koha_marc_update_bib_ids($marc, '', $biblionumber, $biblioitemnumber); |
| 676 |
|
| 677 |
return 1; |
| 678 |
} |
| 679 |
|
| 680 |
sub fix_authority_id { |
| 681 |
# FIXME - as with fix_biblio_ids, the authid must be present |
| 682 |
# for Zebra's sake. However, this really belongs |
| 683 |
# in C4::AuthoritiesMarc. |
| 684 |
my ($marc, $authid) = @_; |
| 685 |
unless ($marc->field('001') and $marc->field('001')->data() eq $authid){ |
| 686 |
$marc->delete_field($marc->field('001')); |
| 687 |
$marc->insert_fields_ordered(MARC::Field->new('001',$authid)); |
| 688 |
} |
| 689 |
} |
| 690 |
|
| 691 |
sub fix_unimarc_100 { |
| 692 |
# FIXME - again, if this is necessary, it belongs in C4::AuthoritiesMarc. |
| 693 |
my $marc = shift; |
| 694 |
|
| 695 |
my $string; |
| 696 |
if ( length($marc->subfield( 100, "a" )) == 36 ) { |
| 697 |
$string = $marc->subfield( 100, "a" ); |
| 698 |
my $f100 = $marc->field(100); |
| 699 |
$marc->delete_field($f100); |
| 700 |
} |
| 701 |
else { |
| 702 |
$string = POSIX::strftime( "%Y%m%d", localtime ); |
| 703 |
$string =~ s/\-//g; |
| 704 |
$string = sprintf( "%-*s", 35, $string ); |
| 705 |
} |
| 706 |
substr( $string, 22, 6, "frey50" ); |
| 707 |
unless ( length($marc->subfield( 100, "a" )) == 36 ) { |
| 708 |
$marc->delete_field($marc->field(100)); |
| 709 |
$marc->insert_grouped_field(MARC::Field->new( 100, "", "", "a" => $string )); |
| 710 |
} |
| 711 |
} |
| 712 |
|
| 713 |
sub do_indexing { |
| 714 |
my ($record_type, $op, $record_dir, $reset_index, $noshadow, $record_format, $zebraidx_log_opt) = @_; |
| 715 |
|
| 716 |
my $zebra_server = ($record_type eq 'biblio') ? 'biblioserver' : 'authorityserver'; |
| 717 |
my $zebra_db_name = ($record_type eq 'biblio') ? 'biblios' : 'authorities'; |
| 718 |
my $zebra_config = C4::Context->zebraconfig($zebra_server)->{'config'}; |
| 719 |
my $zebra_db_dir = C4::Context->zebraconfig($zebra_server)->{'directory'}; |
| 720 |
|
| 721 |
system("zebraidx -c $zebra_config $zebraidx_log_opt -g $record_format -d $zebra_db_name init") if $reset_index; |
| 722 |
system("zebraidx -c $zebra_config $zebraidx_log_opt $noshadow -g $record_format -d $zebra_db_name $op $record_dir"); |
| 723 |
system("zebraidx -c $zebra_config $zebraidx_log_opt -g $record_format -d $zebra_db_name commit") unless $noshadow; |
| 724 |
|
| 725 |
} |
| 726 |
|
383 |
|
| 727 |
sub print_usage { |
384 |
sub print_usage { |
| 728 |
print <<_USAGE_; |
385 |
print <<_USAGE_; |
| 729 |
- |
|
|