4 #use warnings; FIXME - Bug 2505
8 use File::Temp qw/ tempdir /;
11 use C4::AuthoritiesMarc;
13 use Koha::RecordProcessor;
16 # script that checks zebradir structure & create directories & mandatory files if needed
20 $|=1; # flushes output
21 # If the cron job starts us in an unreadable dir, we will break without
23 chdir $ENV{HOME} if (!(-r '.'));
39 my $process_zebraqueue;
40 my $do_not_clear_zebraqueue;
45 my $run_user = (getpwuid($<))[0];
47 my $verbose_logging = 0;
48 my $zebraidx_log_opt = " -v none,fatal,warn ";
49 my $result = GetOptions(
50 'daemon' => \$daemon_mode,
51 'sleep:i' => \$daemon_sleep,
56 'I|skip-index' => \$skip_index,
57 'nosanitize' => \$nosanitize,
61 'munge-config' => \$do_munge,
63 'h|help' => \$want_help,
65 'y' => \$do_not_clear_zebraqueue,
66 'z' => \$process_zebraqueue,
68 'length:i' => \$length,
69 'offset:i' => \$offset,
70 'v+' => \$verbose_logging,
71 'run-as-root' => \$run_as_root,
74 if (not $result or $want_help) {
79 if( not defined $run_as_root and $run_user eq 'root') {
80 my $msg = "Warning: You are running this script as the user 'root'.\n";
81 $msg .= "If this is intentional you must explicitly specify this using the -run-as-root switch\n";
82 $msg .= "Please do '$0 --help' to see usage.\n";
86 if (not $biblios and not $authorities) {
87 my $msg = "Must specify -b or -a to reindex bibs or authorities\n";
88 $msg .= "Please do '$0 --help' to see usage.\n";
92 if ( !$as_xml and $nosanitize ) {
93 my $msg = "Cannot specify both -no_xml and -nosanitize\n";
94 $msg .= "Please do '$0 --help' to see usage.\n";
98 if ($process_zebraqueue and ($skip_export or $reset)) {
99 my $msg = "Cannot specify -r or -s if -z is specified\n";
100 $msg .= "Please do '$0 --help' to see usage.\n";
104 if ($process_zebraqueue and $do_not_clear_zebraqueue) {
105 my $msg = "Cannot specify both -y and -z\n";
106 $msg .= "Please do '$0 --help' to see usage.\n";
119 # incompatible flags handled above: help, reset, and do_not_clear_zebraqueue
120 if ($skip_export or $keep_export or $skip_index or
121 $where or $length or $offset) {
122 my $msg = "Cannot specify -s, -k, -I, -where, -length, or -offset with -daemon.\n";
123 $msg .= "Please do '$0 --help' to see usage.\n";
128 $process_zebraqueue = 1;
131 # -v is for verbose, which seems backwards here because of how logging is set
132 # on the CLI of zebraidx. It works this way. The default is to not log much
133 if ($verbose_logging >= 2) {
134 $zebraidx_log_opt = '-v none,fatal,warn,all';
138 unless ($directory) {
140 $directory = tempdir(CLEANUP => ($keep_export ? 0 : 1));
144 my $biblioserverdir = C4::Context->zebraconfig('biblioserver')->{directory};
145 my $authorityserverdir = C4::Context->zebraconfig('authorityserver')->{directory};
147 my $kohadir = C4::Context->config('intranetdir');
148 my $bib_index_mode = C4::Context->config('zebra_bib_index_mode') || 'grs1';
149 my $auth_index_mode = C4::Context->config('zebra_auth_index_mode') || 'dom';
151 my $dbh = C4::Context->dbh;
152 my ($biblionumbertagfield,$biblionumbertagsubfield) = &GetMarcFromKohaField("biblio.biblionumber","");
153 my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = &GetMarcFromKohaField("biblioitems.biblioitemnumber","");
155 if ( $verbose_logging ) {
156 print "Zebra configuration information\n";
157 print "================================\n";
158 print "Zebra biblio directory = $biblioserverdir\n";
159 print "Zebra authorities directory = $authorityserverdir\n";
160 print "Koha directory = $kohadir\n";
161 print "BIBLIONUMBER in : $biblionumbertagfield\$$biblionumbertagsubfield\n";
162 print "BIBLIOITEMNUMBER in : $biblioitemnumbertagfield\$$biblioitemnumbertagsubfield\n";
163 print "================================\n";
170 my $tester = XML::LibXML->new();
174 do_one_pass() if ( zebraqueue_not_empty() );
182 if ( $verbose_logging ) {
183 print "====================\n";
185 print "====================\n";
188 print "NOTHING cleaned : the export $directory has been kept.\n";
189 print "You can re-run this script with the -s ";
191 print " and -d $directory parameters";
196 print "if you just want to rebuild zebra after changing the record.abs\n";
197 print "or another zebra config file\n";
199 unless ($use_tempdir) {
200 # if we're using a temporary directory
201 # created by File::Temp, it will be removed
203 rmtree($directory, 0, 1);
204 print "directory $directory deleted\n";
210 index_records('authority', $directory, $skip_export, $skip_index, $process_zebraqueue, $as_xml, $noxml, $nosanitize, $do_not_clear_zebraqueue, $verbose_logging, $zebraidx_log_opt, $authorityserverdir);
212 print "skipping authorities\n" if ( $verbose_logging );
216 index_records('biblio', $directory, $skip_export, $skip_index, $process_zebraqueue, $as_xml, $noxml, $nosanitize, $do_not_clear_zebraqueue, $verbose_logging, $zebraidx_log_opt, $biblioserverdir);
218 print "skipping biblios\n" if ( $verbose_logging );
222 # Check the zebra update queue and return true if there are records to process
223 # This routine will handle each of -ab, -a, or -b, but in practice we force
224 # -ab when in daemon mode.
225 sub zebraqueue_not_empty {
228 if ($authorities && $biblios) {
229 $where_str = 'done = 0;';
231 $where_str = 'server = "biblioserver" AND done = 0;';
233 $where_str = 'server = "authorityserver" AND done = 0;';
236 $dbh->prepare( 'SELECT COUNT(*) FROM zebraqueue WHERE ' . $where_str );
239 my $count = $query->fetchrow_arrayref->[0];
240 print "queued records: $count\n" if $verbose_logging > 0;
244 # This checks to see if the zebra directories exist under the provided path.
245 # If they don't, then zebra is likely to spit the dummy. This returns true
246 # if the directories had to be created, false otherwise.
247 sub check_zebra_dirs {
248 my ($base) = shift() . '/';
249 my $needed_repairing = 0;
250 my @dirs = ( '', 'key', 'register', 'shadow', 'tmp' );
251 foreach my $dir (@dirs) {
252 my $bdir = $base . $dir;
254 $needed_repairing = 1;
255 mkdir $bdir || die "Unable to create '$bdir': $!\n";
256 print "$0: needed to create '$bdir'\n";
259 return $needed_repairing;
260 } # ---------- end of subroutine check_zebra_dirs ----------
263 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) = @_;
265 my $num_records_exported = 0;
267 my $need_reset = check_zebra_dirs($server_dir);
269 print "$0: found broken zebra server directories: forcing a rebuild\n";
272 if ($skip_export && $verbose_logging) {
273 print "====================\n";
274 print "SKIPPING $record_type export\n";
275 print "====================\n";
277 if ( $verbose_logging ) {
278 print "====================\n";
279 print "exporting $record_type\n";
280 print "====================\n";
282 mkdir "$directory" unless (-d $directory);
283 mkdir "$directory/$record_type" unless (-d "$directory/$record_type");
284 if ($process_zebraqueue) {
285 my $entries = select_zebraqueue_records($record_type, 'deleted');
286 mkdir "$directory/del_$record_type" unless (-d "$directory/del_$record_type");
287 $records_deleted = generate_deleted_marc_records($record_type, $entries, "$directory/del_$record_type", $as_xml);
288 mark_zebraqueue_batch_done($entries);
289 $entries = select_zebraqueue_records($record_type, 'updated');
290 mkdir "$directory/upd_$record_type" unless (-d "$directory/upd_$record_type");
291 $num_records_exported = export_marc_records_from_list($record_type,
292 $entries, "$directory/upd_$record_type", $as_xml, $noxml, $records_deleted);
293 mark_zebraqueue_batch_done($entries);
295 my $sth = select_all_records($record_type);
296 $num_records_exported = export_marc_records_from_sth($record_type, $sth, "$directory/$record_type", $as_xml, $noxml, $nosanitize);
297 unless ($do_not_clear_zebraqueue) {
298 mark_all_zebraqueue_done($record_type);
304 # and reindexing everything
307 if ($verbose_logging) {
308 print "====================\n";
309 print "SKIPPING $record_type indexing\n";
310 print "====================\n";
313 if ( $verbose_logging ) {
314 print "====================\n";
315 print "REINDEXING zebra\n";
316 print "====================\n";
318 my $record_fmt = ($as_xml) ? 'marcxml' : 'iso2709' ;
319 if ($process_zebraqueue) {
320 do_indexing($record_type, 'adelete', "$directory/del_$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt)
321 if %$records_deleted;
322 do_indexing($record_type, 'update', "$directory/upd_$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt)
323 if $num_records_exported;
325 do_indexing($record_type, 'update', "$directory/$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt)
326 if ($num_records_exported or $skip_export);
332 sub select_zebraqueue_records {
333 my ($record_type, $update_type) = @_;
335 my $server = ($record_type eq 'biblio') ? 'biblioserver' : 'authorityserver';
336 my $op = ($update_type eq 'deleted') ? 'recordDelete' : 'specialUpdate';
338 my $sth = $dbh->prepare("SELECT id, biblio_auth_number
344 $sth->execute($server, $op);
345 my $entries = $sth->fetchall_arrayref({});
348 sub mark_all_zebraqueue_done {
349 my ($record_type) = @_;
351 my $server = ($record_type eq 'biblio') ? 'biblioserver' : 'authorityserver';
353 my $sth = $dbh->prepare("UPDATE zebraqueue SET done = 1
356 $sth->execute($server);
359 sub mark_zebraqueue_batch_done {
362 $dbh->{AutoCommit} = 0;
363 my $sth = $dbh->prepare("UPDATE zebraqueue SET done = 1 WHERE id = ?");
365 foreach my $id (map { $_->{id} } @$entries) {
368 $dbh->{AutoCommit} = 1;
371 sub select_all_records {
372 my $record_type = shift;
373 return ($record_type eq 'biblio') ? select_all_biblios() : select_all_authorities();
376 sub select_all_authorities {
377 my $strsth=qq{SELECT authid FROM auth_header};
378 $strsth.=qq{ WHERE $where } if ($where);
379 $strsth.=qq{ LIMIT $length } if ($length && !$offset);
380 $strsth.=qq{ LIMIT $offset,$length } if ($length && $offset);
381 my $sth = $dbh->prepare($strsth);
386 sub select_all_biblios {
387 my $strsth = qq{ SELECT biblionumber FROM biblioitems };
388 $strsth.=qq{ WHERE $where } if ($where);
389 $strsth.=qq{ LIMIT $length } if ($length && !$offset);
390 $strsth.=qq{ LIMIT $offset,$length } if ($offset);
391 my $sth = $dbh->prepare($strsth);
396 sub include_xml_wrapper {
398 my $record_type = shift;
400 return 0 unless $as_xml;
401 return 1 if $record_type eq 'biblio' and $bib_index_mode eq 'dom';
402 return 1 if $record_type eq 'authority' and $auth_index_mode eq 'dom';
407 sub export_marc_records_from_sth {
408 my ($record_type, $sth, $directory, $as_xml, $noxml, $nosanitize) = @_;
410 my $num_exported = 0;
411 open my $fh, '>:encoding(UTF-8) ', "$directory/exported_records" or die $!;
412 if (include_xml_wrapper($as_xml, $record_type)) {
413 # include XML declaration and root element
414 print {$fh} '<?xml version="1.0" encoding="UTF-8"?><collection>';
417 my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",'');
418 while (my ($record_number) = $sth->fetchrow_array) {
419 print "." if ( $verbose_logging );
420 print "\r$i" unless ($i++ %100 or !$verbose_logging);
422 my $marcxml = $record_type eq 'biblio'
423 ? GetXmlBiblio( $record_number )
424 : GetAuthorityXML( $record_number );
425 if ($record_type eq 'biblio'){
426 my @items = GetItemsInfo($record_number);
428 my $record = MARC::Record->new;
429 $record->encoding('UTF-8');
431 foreach my $item (@items){
432 my $record = Item2Marc($item, $record_number);
433 push @itemsrecord, $record->field($itemtag);
435 $record->insert_fields_ordered(@itemsrecord);
436 my $itemsxml = $record->as_xml_record();
438 substr($marcxml, 0, length($marcxml)-10) .
439 substr($itemsxml, index($itemsxml, "</leader>\n", 0) + 10);
442 # extra test to ensure that result is valid XML; otherwise
443 # Zebra won't parse it in DOM mode
445 my $doc = $tester->parse_string($marcxml);
448 warn "Error exporting record $record_number ($record_type): $@\n";
452 $marcxml =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!;
453 print {$fh} $marcxml;
458 my ($marc) = get_corrected_marc_record($record_type, $record_number, $noxml);
463 $rec = $marc->as_xml_record(C4::Context->preference('marcflavour'));
465 my $doc = $tester->parse_string($rec);
468 die "invalid XML: $@";
470 $rec =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!;
472 $rec = $marc->as_usmarc();
478 warn "Error exporting record $record_number ($record_type) ".($noxml ? "not XML" : "XML");
479 warn "... specific error is $@" if $verbose_logging;
483 print "\nRecords exported: $num_exported\n" if ( $verbose_logging );
484 print {$fh} '</collection>' if (include_xml_wrapper($as_xml, $record_type));
486 return $num_exported;
489 sub export_marc_records_from_list {
490 my ($record_type, $entries, $directory, $as_xml, $noxml, $records_deleted) = @_;
492 my $num_exported = 0;
493 open my $fh, '>:encoding(UTF-8)', "$directory/exported_records" or die $!;
494 if (include_xml_wrapper($as_xml, $record_type)) {
495 # include XML declaration and root element
496 print {$fh} '<?xml version="1.0" encoding="UTF-8"?><collection>';
500 # Skip any deleted records. We check for this anyway, but this reduces error spam
501 my %found = %$records_deleted;
502 foreach my $record_number ( map { $_->{biblio_auth_number} }
503 grep { !$found{ $_->{biblio_auth_number} }++ }
505 print "." if ( $verbose_logging );
506 print "\r$i" unless ($i++ %100 or !$verbose_logging);
507 my ($marc) = get_corrected_marc_record($record_type, $record_number, $noxml);
512 $rec = $marc->as_xml_record(C4::Context->preference('marcflavour'));
513 $rec =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!;
515 $rec = $marc->as_usmarc();
521 warn "Error exporting record $record_number ($record_type) ".($noxml ? "not XML" : "XML");
525 print "\nRecords exported: $num_exported\n" if ( $verbose_logging );
526 print {$fh} '</collection>' if (include_xml_wrapper($as_xml, $record_type));
528 return $num_exported;
531 sub generate_deleted_marc_records {
532 my ($record_type, $entries, $directory, $as_xml) = @_;
534 my $records_deleted = {};
535 open my $fh, '>:encoding(UTF-8)', "$directory/exported_records" or die $!;
536 if (include_xml_wrapper($as_xml, $record_type)) {
537 # include XML declaration and root element
538 print {$fh} '<?xml version="1.0" encoding="UTF-8"?><collection>';
541 foreach my $record_number (map { $_->{biblio_auth_number} } @$entries ) {
542 print "\r$i" unless ($i++ %100 or !$verbose_logging);
543 print "." if ( $verbose_logging );
545 my $marc = MARC::Record->new();
546 if ($record_type eq 'biblio') {
547 fix_biblio_ids($marc, $record_number, $record_number);
549 fix_authority_id($marc, $record_number);
551 if (C4::Context->preference("marcflavour") eq "UNIMARC") {
552 fix_unimarc_100($marc);
557 $rec = $marc->as_xml_record(C4::Context->preference('marcflavour'));
558 $rec =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!;
560 $rec = $marc->as_usmarc();
564 $records_deleted->{$record_number} = 1;
566 print "\nRecords exported: $i\n" if ( $verbose_logging );
567 print {$fh} '</collection>' if (include_xml_wrapper($as_xml, $record_type));
569 return $records_deleted;
574 sub get_corrected_marc_record {
575 my ($record_type, $record_number, $noxml) = @_;
577 my $marc = get_raw_marc_record($record_type, $record_number, $noxml);
581 if ($record_type eq 'authority') {
582 fix_authority_id($marc, $record_number);
583 } elsif ($record_type eq 'biblio' && C4::Context->preference('IncludeSeeFromInSearches')) {
584 my $normalizer = Koha::RecordProcessor->new( { filters => 'EmbedSeeFromHeadings' } );
585 $marc = $normalizer->process($marc);
587 if (C4::Context->preference("marcflavour") eq "UNIMARC") {
588 fix_unimarc_100($marc);
595 sub get_raw_marc_record {
596 my ($record_type, $record_number, $noxml) = @_;
599 if ($record_type eq 'biblio') {
601 my $fetch_sth = $dbh->prepare_cached("SELECT marc FROM biblioitems WHERE biblionumber = ?");
602 $fetch_sth->execute($record_number);
603 if (my ($blob) = $fetch_sth->fetchrow_array) {
604 $marc = MARC::Record->new_from_usmarc($blob);
606 warn "error creating MARC::Record from $blob";
609 # failure to find a bib is not a problem -
610 # a delete could have been done before
611 # trying to process a record update
613 $fetch_sth->finish();
616 eval { $marc = GetMarcBiblio($record_number, 1); };
618 # here we do warn since catching an exception
619 # means that the bib was found but failed
621 warn "error retrieving biblio $record_number";
626 eval { $marc = GetAuthority($record_number); };
628 warn "error retrieving authority $record_number";
636 # FIXME - this routine is suspect
637 # It blanks the Leader/00-05 and Leader/12-16 to
638 # force them to be recalculated correct when
639 # the $marc->as_usmarc() or $marc->as_xml() is called.
640 # But why is this necessary? It would be a serious bug
641 # in MARC::Record (definitely) and MARC::File::XML (arguably)
642 # if they are emitting incorrect leader values.
645 my $leader = $marc->leader;
646 substr($leader, 0, 5) = ' ';
647 substr($leader, 10, 7) = '22 ';
648 $marc->leader(substr($leader, 0, 24));
652 # FIXME - it is essential to ensure that the biblionumber is present,
653 # otherwise, Zebra will choke on the record. However, this
654 # logic belongs in the relevant C4::Biblio APIs.
656 my $biblionumber = shift;
657 my $biblioitemnumber;
659 $biblioitemnumber = shift;
661 my $sth = $dbh->prepare(
662 "SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
663 $sth->execute($biblionumber);
664 ($biblioitemnumber) = $sth->fetchrow_array;
666 unless ($biblioitemnumber) {
667 warn "failed to get biblioitemnumber for biblio $biblionumber";
672 # FIXME - this is cheating on two levels
673 # 1. C4::Biblio::_koha_marc_update_bib_ids is meant to be an internal function
674 # 2. Making sure that the biblionumber and biblioitemnumber are correct and
675 # present in the MARC::Record object ought to be part of GetMarcBiblio.
677 # On the other hand, this better for now than what rebuild_zebra.pl used to
678 # do, which was duplicate the code for inserting the biblionumber
679 # and biblioitemnumber
680 C4::Biblio::_koha_marc_update_bib_ids($marc, '', $biblionumber, $biblioitemnumber);
685 sub fix_authority_id {
686 # FIXME - as with fix_biblio_ids, the authid must be present
687 # for Zebra's sake. However, this really belongs
688 # in C4::AuthoritiesMarc.
689 my ($marc, $authid) = @_;
690 unless ($marc->field('001') and $marc->field('001')->data() eq $authid){
691 $marc->delete_field($marc->field('001'));
692 $marc->insert_fields_ordered(MARC::Field->new('001',$authid));
696 sub fix_unimarc_100 {
697 # FIXME - again, if this is necessary, it belongs in C4::AuthoritiesMarc.
701 if ( length($marc->subfield( 100, "a" )) == 36 ) {
702 $string = $marc->subfield( 100, "a" );
703 my $f100 = $marc->field(100);
704 $marc->delete_field($f100);
707 $string = POSIX::strftime( "%Y%m%d", localtime );
709 $string = sprintf( "%-*s", 35, $string );
711 substr( $string, 22, 6, "frey50" );
712 unless ( length($marc->subfield( 100, "a" )) == 36 ) {
713 $marc->delete_field($marc->field(100));
714 $marc->insert_grouped_field(MARC::Field->new( 100, "", "", "a" => $string ));
719 my ($record_type, $op, $record_dir, $reset_index, $noshadow, $record_format, $zebraidx_log_opt) = @_;
721 my $zebra_server = ($record_type eq 'biblio') ? 'biblioserver' : 'authorityserver';
722 my $zebra_db_name = ($record_type eq 'biblio') ? 'biblios' : 'authorities';
723 my $zebra_config = C4::Context->zebraconfig($zebra_server)->{'config'};
724 my $zebra_db_dir = C4::Context->zebraconfig($zebra_server)->{'directory'};
726 system("zebraidx -c $zebra_config $zebraidx_log_opt -g $record_format -d $zebra_db_name init") if $reset_index;
727 system("zebraidx -c $zebra_config $zebraidx_log_opt $noshadow -g $record_format -d $zebra_db_name $op $record_dir");
728 system("zebraidx -c $zebra_config $zebraidx_log_opt -g $record_format -d $zebra_db_name commit") unless $noshadow;
734 $0: reindex MARC bibs and/or authorities in Zebra.
736 Use this batch job to reindex all biblio or authority
737 records in your Koha database.
741 -b index bibliographic records
743 -a index authority records
745 -daemon Run in daemon mode. The program will loop checking
746 for entries on the zebraqueue table, processing
747 them incrementally if present, and then sleep
748 for a few seconds before repeating the process
749 Checking the zebraqueue table is done with a cheap
750 SQL query. This allows for near realtime update of
751 the zebra search index with low system overhead.
752 Use -sleep to control the checking interval.
754 Daemon mode implies -z, -a, -b. The program will
755 refuse to start if options are present that do not
756 make sense while running as an incremental update
757 daemon (e.g. -r or -offset).
759 -sleep 10 Seconds to sleep between checks of the zebraqueue
760 table in daemon mode. The default is 5 seconds.
762 -z select only updated and deleted
763 records marked in the zebraqueue
764 table. Cannot be used with -r
767 -r clear Zebra index before
768 adding records to index. Implies -w.
770 -d Temporary directory for indexing.
771 If not specified, one is automatically
772 created. The export directory
773 is automatically deleted unless
774 you supply the -k switch.
776 -k Do not delete export directory.
778 -s Skip export. Used if you have
779 already exported the records
782 -noxml index from ISO MARC blob
783 instead of MARC XML. This
784 option is recommended only
787 -x export and index as xml instead of is02709 (biblios only).
788 use this if you might have records > 99,999 chars,
790 -nosanitize export biblio/authority records directly from DB marcxml
791 field without sanitizing records. It speed up
792 dump process but could fail if DB contains badly
793 encoded records. Works only with -x,
795 -w skip shadow indexing for this batch
797 -y do NOT clear zebraqueue after indexing; normally,
798 after doing batch indexing, zebraqueue should be
799 marked done for the affected record type(s) so that
800 a running zebraqueue_daemon doesn't try to reindex
801 the same records - specify -y to override this.
802 Cannot be used with -z.
804 -v increase the amount of logging. Normally only
805 warnings and errors from the indexing are shown.
806 Use log level 2 (-v -v) to include all Zebra logs.
808 --length 1234 how many biblio you want to export
809 --offset 1243 offset you want to start to
810 example: --offset 500 --length=500 will result in a LIMIT 500,1000 (exporting 1000 records, starting by the 500th one)
811 note that the numbers are NOT related to biblionumber, that's the intended behaviour.
812 --where let you specify a WHERE query, like itemtype='BOOK'
813 or something like that
815 --munge-config Deprecated option to try
816 to fix Zebra config files.
818 --run-as-root explicitily allow script to run as 'root' user
820 --help or -h show this message.
824 # FIXME: the following routines are deprecated and
825 # will be removed once it is determined whether
826 # a script to fix Zebra configuration files is
830 # creating zebra-biblios.cfg depending on system
833 # getting zebraidx directory
835 foreach (qw(/usr/local/bin/zebraidx
844 unless ($zebraidxdir) {
846 ERROR: could not find zebraidx directory
847 ERROR: Either zebra is not installed,
848 ERROR: or it's in a directory I don't checked.
849 ERROR: do a which zebraidx and edit this file to add the result you get
853 $zebraidxdir =~ s/\/bin\/.*//;
854 print "Info : zebra is in $zebraidxdir \n";
856 # getting modules directory
858 foreach (qw(/usr/local/lib/idzebra-2.0/modules/mod-grs-xml.so
859 /usr/local/lib/idzebra/modules/mod-grs-xml.so
860 /usr/lib/idzebra/modules/mod-grs-xml.so
861 /usr/lib/idzebra-2.0/modules/mod-grs-xml.so
868 unless ($modulesdir) {
870 ERROR: could not find mod-grs-xml.so directory
871 ERROR: Either zebra is not properly compiled (libxml2 is not setup and you don t have mod-grs-xml.so,
872 ERROR: or it's in a directory I don't checked.
873 ERROR: find where mod-grs-xml.so is and edit this file to add the result you get
877 $modulesdir =~ s/\/modules\/.*//;
878 print "Info: zebra modules dir : $modulesdir\n";
880 # getting tab directory
882 foreach (qw(/usr/local/share/idzebra/tab/explain.att
883 /usr/local/share/idzebra-2.0/tab/explain.att
884 /usr/share/idzebra/tab/explain.att
885 /usr/share/idzebra-2.0/tab/explain.att
894 ERROR: could not find explain.att directory
895 ERROR: Either zebra is not properly compiled,
896 ERROR: or it's in a directory I don't checked.
897 ERROR: find where explain.att is and edit this file to add the result you get
901 $tabdir =~ s/\/tab\/.*//;
902 print "Info: tab dir : $tabdir\n";
905 # AUTHORITIES creating directory structure
907 my $created_dir_or_file = 0;
909 if ( $verbose_logging ) {
910 print "====================\n";
911 print "checking directories & files for authorities\n";
912 print "====================\n";
914 unless (-d "$authorityserverdir") {
915 system("mkdir -p $authorityserverdir");
916 print "Info: created $authorityserverdir\n";
917 $created_dir_or_file++;
919 unless (-d "$authorityserverdir/lock") {
920 mkdir "$authorityserverdir/lock";
921 print "Info: created $authorityserverdir/lock\n";
922 $created_dir_or_file++;
924 unless (-d "$authorityserverdir/register") {
925 mkdir "$authorityserverdir/register";
926 print "Info: created $authorityserverdir/register\n";
927 $created_dir_or_file++;
929 unless (-d "$authorityserverdir/shadow") {
930 mkdir "$authorityserverdir/shadow";
931 print "Info: created $authorityserverdir/shadow\n";
932 $created_dir_or_file++;
934 unless (-d "$authorityserverdir/tab") {
935 mkdir "$authorityserverdir/tab";
936 print "Info: created $authorityserverdir/tab\n";
937 $created_dir_or_file++;
939 unless (-d "$authorityserverdir/key") {
940 mkdir "$authorityserverdir/key";
941 print "Info: created $authorityserverdir/key\n";
942 $created_dir_or_file++;
945 unless (-d "$authorityserverdir/etc") {
946 mkdir "$authorityserverdir/etc";
947 print "Info: created $authorityserverdir/etc\n";
948 $created_dir_or_file++;
952 # AUTHORITIES : copying mandatory files
954 # the record model, depending on marc flavour
955 unless (-f "$authorityserverdir/tab/record.abs") {
956 if (C4::Context->preference("marcflavour") eq "UNIMARC") {
957 system("cp -f $kohadir/etc/zebradb/marc_defs/unimarc/authorities/record.abs $authorityserverdir/tab/record.abs");
958 print "Info: copied record.abs for UNIMARC\n";
960 system("cp -f $kohadir/etc/zebradb/marc_defs/marc21/authorities/record.abs $authorityserverdir/tab/record.abs");
961 print "Info: copied record.abs for USMARC\n";
963 $created_dir_or_file++;
965 unless (-f "$authorityserverdir/tab/sort-string-utf.chr") {
966 system("cp -f $kohadir/etc/zebradb/lang_defs/fr/sort-string-utf.chr $authorityserverdir/tab/sort-string-utf.chr");
967 print "Info: copied sort-string-utf.chr\n";
968 $created_dir_or_file++;
970 unless (-f "$authorityserverdir/tab/word-phrase-utf.chr") {
971 system("cp -f $kohadir/etc/zebradb/lang_defs/fr/sort-string-utf.chr $authorityserverdir/tab/word-phrase-utf.chr");
972 print "Info: copied word-phase-utf.chr\n";
973 $created_dir_or_file++;
975 unless (-f "$authorityserverdir/tab/auth1.att") {
976 system("cp -f $kohadir/etc/zebradb/authorities/etc/bib1.att $authorityserverdir/tab/auth1.att");
977 print "Info: copied auth1.att\n";
978 $created_dir_or_file++;
980 unless (-f "$authorityserverdir/tab/default.idx") {
981 system("cp -f $kohadir/etc/zebradb/etc/default.idx $authorityserverdir/tab/default.idx");
982 print "Info: copied default.idx\n";
983 $created_dir_or_file++;
986 unless (-f "$authorityserverdir/etc/ccl.properties") {
987 # system("cp -f $kohadir/etc/zebradb/ccl.properties ".C4::Context->zebraconfig('authorityserver')->{ccl2rpn});
988 system("cp -f $kohadir/etc/zebradb/ccl.properties $authorityserverdir/etc/ccl.properties");
989 print "Info: copied ccl.properties\n";
990 $created_dir_or_file++;
992 unless (-f "$authorityserverdir/etc/pqf.properties") {
993 # system("cp -f $kohadir/etc/zebradb/pqf.properties ".C4::Context->zebraconfig('authorityserver')->{ccl2rpn});
994 system("cp -f $kohadir/etc/zebradb/pqf.properties $authorityserverdir/etc/pqf.properties");
995 print "Info: copied pqf.properties\n";
996 $created_dir_or_file++;
1000 # AUTHORITIES : copying mandatory files
1002 unless (-f C4::Context->zebraconfig('authorityserver')->{config}) {
1003 open my $zd, '>:encoding(UTF-8)' ,C4::Context->zebraconfig('authorityserver')->{config};
1005 # generated by KOHA/misc/migration_tools/rebuild_zebra.pl
1006 profilePath:\${srcdir:-.}:$authorityserverdir/tab/:$tabdir/tab/:\${srcdir:-.}/tab/
1009 # Files that describe the attribute sets supported.
1014 modulePath:$modulesdir/modules/
1015 # Specify record type
1016 iso2709.recordType:grs.marcxml.record
1018 recordId: (auth1,Local-Number)
1024 lockDir: $authorityserverdir/lock
1027 register: $authorityserverdir/register:4G
1028 shadow: $authorityserverdir/shadow:4G
1030 # Temp File area for result sets
1031 setTmpDir: $authorityserverdir/tmp
1033 # Temp File area for index program
1034 keyTmpDir: $authorityserverdir/key
1036 # Approx. Memory usage during indexing
1040 print "Info: creating zebra-authorities.cfg\n";
1041 $created_dir_or_file++;
1044 if ($created_dir_or_file) {
1045 print "Info: created : $created_dir_or_file directories & files\n";
1047 print "Info: file & directories OK\n";
1052 if ( $verbose_logging ) {
1053 print "====================\n";
1054 print "checking directories & files for biblios\n";
1055 print "====================\n";
1059 # BIBLIOS : creating directory structure
1061 unless (-d "$biblioserverdir") {
1062 system("mkdir -p $biblioserverdir");
1063 print "Info: created $biblioserverdir\n";
1064 $created_dir_or_file++;
1066 unless (-d "$biblioserverdir/lock") {
1067 mkdir "$biblioserverdir/lock";
1068 print "Info: created $biblioserverdir/lock\n";
1069 $created_dir_or_file++;
1071 unless (-d "$biblioserverdir/register") {
1072 mkdir "$biblioserverdir/register";
1073 print "Info: created $biblioserverdir/register\n";
1074 $created_dir_or_file++;
1076 unless (-d "$biblioserverdir/shadow") {
1077 mkdir "$biblioserverdir/shadow";
1078 print "Info: created $biblioserverdir/shadow\n";
1079 $created_dir_or_file++;
1081 unless (-d "$biblioserverdir/tab") {
1082 mkdir "$biblioserverdir/tab";
1083 print "Info: created $biblioserverdir/tab\n";
1084 $created_dir_or_file++;
1086 unless (-d "$biblioserverdir/key") {
1087 mkdir "$biblioserverdir/key";
1088 print "Info: created $biblioserverdir/key\n";
1089 $created_dir_or_file++;
1091 unless (-d "$biblioserverdir/etc") {
1092 mkdir "$biblioserverdir/etc";
1093 print "Info: created $biblioserverdir/etc\n";
1094 $created_dir_or_file++;
1098 # BIBLIOS : copying mandatory files
1100 # the record model, depending on marc flavour
1101 unless (-f "$biblioserverdir/tab/record.abs") {
1102 if (C4::Context->preference("marcflavour") eq "UNIMARC") {
1103 system("cp -f $kohadir/etc/zebradb/marc_defs/unimarc/biblios/record.abs $biblioserverdir/tab/record.abs");
1104 print "Info: copied record.abs for UNIMARC\n";
1106 system("cp -f $kohadir/etc/zebradb/marc_defs/marc21/biblios/record.abs $biblioserverdir/tab/record.abs");
1107 print "Info: copied record.abs for USMARC\n";
1109 $created_dir_or_file++;
1111 unless (-f "$biblioserverdir/tab/sort-string-utf.chr") {
1112 system("cp -f $kohadir/etc/zebradb/lang_defs/fr/sort-string-utf.chr $biblioserverdir/tab/sort-string-utf.chr");
1113 print "Info: copied sort-string-utf.chr\n";
1114 $created_dir_or_file++;
1116 unless (-f "$biblioserverdir/tab/word-phrase-utf.chr") {
1117 system("cp -f $kohadir/etc/zebradb/lang_defs/fr/sort-string-utf.chr $biblioserverdir/tab/word-phrase-utf.chr");
1118 print "Info: copied word-phase-utf.chr\n";
1119 $created_dir_or_file++;
1121 unless (-f "$biblioserverdir/tab/bib1.att") {
1122 system("cp -f $kohadir/etc/zebradb/biblios/etc/bib1.att $biblioserverdir/tab/bib1.att");
1123 print "Info: copied bib1.att\n";
1124 $created_dir_or_file++;
1126 unless (-f "$biblioserverdir/tab/default.idx") {
1127 system("cp -f $kohadir/etc/zebradb/etc/default.idx $biblioserverdir/tab/default.idx");
1128 print "Info: copied default.idx\n";
1129 $created_dir_or_file++;
1131 unless (-f "$biblioserverdir/etc/ccl.properties") {
1132 # system("cp -f $kohadir/etc/zebradb/ccl.properties ".C4::Context->zebraconfig('biblioserver')->{ccl2rpn});
1133 system("cp -f $kohadir/etc/zebradb/ccl.properties $biblioserverdir/etc/ccl.properties");
1134 print "Info: copied ccl.properties\n";
1135 $created_dir_or_file++;
1137 unless (-f "$biblioserverdir/etc/pqf.properties") {
1138 # system("cp -f $kohadir/etc/zebradb/pqf.properties ".C4::Context->zebraconfig('biblioserver')->{ccl2rpn});
1139 system("cp -f $kohadir/etc/zebradb/pqf.properties $biblioserverdir/etc/pqf.properties");
1140 print "Info: copied pqf.properties\n";
1141 $created_dir_or_file++;
1145 # BIBLIOS : copying mandatory files
1147 unless (-f C4::Context->zebraconfig('biblioserver')->{config}) {
1148 open my $zd, '>:encoding(UTF-8)', C4::Context->zebraconfig('biblioserver')->{config};
1150 # generated by KOHA/misc/migrtion_tools/rebuild_zebra.pl
1151 profilePath:\${srcdir:-.}:$biblioserverdir/tab/:$tabdir/tab/:\${srcdir:-.}/tab/
1154 # Files that describe the attribute sets supported.
1159 modulePath:$modulesdir/modules/
1160 # Specify record type
1161 iso2709.recordType:grs.marcxml.record
1163 recordId: (bib1,Local-Number)
1169 lockDir: $biblioserverdir/lock
1172 register: $biblioserverdir/register:4G
1173 shadow: $biblioserverdir/shadow:4G
1175 # Temp File area for result sets
1176 setTmpDir: $biblioserverdir/tmp
1178 # Temp File area for index program
1179 keyTmpDir: $biblioserverdir/key
1181 # Approx. Memory usage during indexing
1185 print "Info: creating zebra-biblios.cfg\n";
1186 $created_dir_or_file++;
1189 if ($created_dir_or_file) {
1190 print "Info: created : $created_dir_or_file directories & files\n";
1192 print "Info: file & directories OK\n";