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";
118 # -v is for verbose, which seems backwards here because of how logging is set
119 # on the CLI of zebraidx. It works this way. The default is to not log much
120 if ($verbose_logging >= 2) {
121 $zebraidx_log_opt = '-v none,fatal,warn,all';
125 unless ($directory) {
127 $directory = tempdir(CLEANUP => ($keep_export ? 0 : 1));
131 my $biblioserverdir = C4::Context->zebraconfig('biblioserver')->{directory};
132 my $authorityserverdir = C4::Context->zebraconfig('authorityserver')->{directory};
134 my $kohadir = C4::Context->config('intranetdir');
135 my $bib_index_mode = C4::Context->config('zebra_bib_index_mode') || 'grs1';
136 my $auth_index_mode = C4::Context->config('zebra_auth_index_mode') || 'dom';
138 my $dbh = C4::Context->dbh;
139 my ($biblionumbertagfield,$biblionumbertagsubfield) = &GetMarcFromKohaField("biblio.biblionumber","");
140 my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = &GetMarcFromKohaField("biblioitems.biblioitemnumber","");
142 if ( $verbose_logging ) {
143 print "Zebra configuration information\n";
144 print "================================\n";
145 print "Zebra biblio directory = $biblioserverdir\n";
146 print "Zebra authorities directory = $authorityserverdir\n";
147 print "Koha directory = $kohadir\n";
148 print "BIBLIONUMBER in : $biblionumbertagfield\$$biblionumbertagsubfield\n";
149 print "BIBLIOITEMNUMBER in : $biblioitemnumbertagfield\$$biblioitemnumbertagsubfield\n";
150 print "================================\n";
157 my $tester = XML::LibXML->new();
161 do_one_pass() if ( zebraqueue_not_empty() );
169 if ( $verbose_logging ) {
170 print "====================\n";
172 print "====================\n";
175 print "NOTHING cleaned : the export $directory has been kept.\n";
176 print "You can re-run this script with the -s ";
178 print " and -d $directory parameters";
183 print "if you just want to rebuild zebra after changing the record.abs\n";
184 print "or another zebra config file\n";
186 unless ($use_tempdir) {
187 # if we're using a temporary directory
188 # created by File::Temp, it will be removed
190 rmtree($directory, 0, 1);
191 print "directory $directory deleted\n";
197 index_records('authority', $directory, $skip_export, $skip_index, $process_zebraqueue, $as_xml, $noxml, $nosanitize, $do_not_clear_zebraqueue, $verbose_logging, $zebraidx_log_opt, $authorityserverdir);
199 print "skipping authorities\n" if ( $verbose_logging );
203 index_records('biblio', $directory, $skip_export, $skip_index, $process_zebraqueue, $as_xml, $noxml, $nosanitize, $do_not_clear_zebraqueue, $verbose_logging, $zebraidx_log_opt, $biblioserverdir);
205 print "skipping biblios\n" if ( $verbose_logging );
209 # Check the zebra update queue and return true if there are records to process
210 sub zebraqueue_not_empty {
213 if ($authorities && $biblios) {
214 $where_str = 'done = 0;';
216 $where_str = 'server = "biblioserver" AND done = 0;';
218 $where_str = 'server = "authorityserver" AND done = 0;';
221 $dbh->prepare( 'SELECT COUNT(*) FROM zebraqueue WHERE ' . $where_str );
224 my $count = $query->fetchrow_arrayref->[0];
225 print "queued records: $count\n" if $verbose_logging > 0;
229 # This checks to see if the zebra directories exist under the provided path.
230 # If they don't, then zebra is likely to spit the dummy. This returns true
231 # if the directories had to be created, false otherwise.
232 sub check_zebra_dirs {
233 my ($base) = shift() . '/';
234 my $needed_repairing = 0;
235 my @dirs = ( '', 'key', 'register', 'shadow', 'tmp' );
236 foreach my $dir (@dirs) {
237 my $bdir = $base . $dir;
239 $needed_repairing = 1;
240 mkdir $bdir || die "Unable to create '$bdir': $!\n";
241 print "$0: needed to create '$bdir'\n";
244 return $needed_repairing;
245 } # ---------- end of subroutine check_zebra_dirs ----------
248 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) = @_;
250 my $num_records_exported = 0;
252 my $need_reset = check_zebra_dirs($server_dir);
254 print "$0: found broken zebra server directories: forcing a rebuild\n";
257 if ($skip_export && $verbose_logging) {
258 print "====================\n";
259 print "SKIPPING $record_type export\n";
260 print "====================\n";
262 if ( $verbose_logging ) {
263 print "====================\n";
264 print "exporting $record_type\n";
265 print "====================\n";
267 mkdir "$directory" unless (-d $directory);
268 mkdir "$directory/$record_type" unless (-d "$directory/$record_type");
269 if ($process_zebraqueue) {
270 my $entries = select_zebraqueue_records($record_type, 'deleted');
271 mkdir "$directory/del_$record_type" unless (-d "$directory/del_$record_type");
272 $records_deleted = generate_deleted_marc_records($record_type, $entries, "$directory/del_$record_type", $as_xml);
273 mark_zebraqueue_batch_done($entries);
274 $entries = select_zebraqueue_records($record_type, 'updated');
275 mkdir "$directory/upd_$record_type" unless (-d "$directory/upd_$record_type");
276 $num_records_exported = export_marc_records_from_list($record_type,
277 $entries, "$directory/upd_$record_type", $as_xml, $noxml, $records_deleted);
278 mark_zebraqueue_batch_done($entries);
280 my $sth = select_all_records($record_type);
281 $num_records_exported = export_marc_records_from_sth($record_type, $sth, "$directory/$record_type", $as_xml, $noxml, $nosanitize);
282 unless ($do_not_clear_zebraqueue) {
283 mark_all_zebraqueue_done($record_type);
289 # and reindexing everything
292 if ($verbose_logging) {
293 print "====================\n";
294 print "SKIPPING $record_type indexing\n";
295 print "====================\n";
298 if ( $verbose_logging ) {
299 print "====================\n";
300 print "REINDEXING zebra\n";
301 print "====================\n";
303 my $record_fmt = ($as_xml) ? 'marcxml' : 'iso2709' ;
304 if ($process_zebraqueue) {
305 do_indexing($record_type, 'adelete', "$directory/del_$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt)
306 if %$records_deleted;
307 do_indexing($record_type, 'update', "$directory/upd_$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt)
308 if $num_records_exported;
310 do_indexing($record_type, 'update', "$directory/$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt)
311 if ($num_records_exported or $skip_export);
317 sub select_zebraqueue_records {
318 my ($record_type, $update_type) = @_;
320 my $server = ($record_type eq 'biblio') ? 'biblioserver' : 'authorityserver';
321 my $op = ($update_type eq 'deleted') ? 'recordDelete' : 'specialUpdate';
323 my $sth = $dbh->prepare("SELECT id, biblio_auth_number
329 $sth->execute($server, $op);
330 my $entries = $sth->fetchall_arrayref({});
333 sub mark_all_zebraqueue_done {
334 my ($record_type) = @_;
336 my $server = ($record_type eq 'biblio') ? 'biblioserver' : 'authorityserver';
338 my $sth = $dbh->prepare("UPDATE zebraqueue SET done = 1
341 $sth->execute($server);
344 sub mark_zebraqueue_batch_done {
347 $dbh->{AutoCommit} = 0;
348 my $sth = $dbh->prepare("UPDATE zebraqueue SET done = 1 WHERE id = ?");
350 foreach my $id (map { $_->{id} } @$entries) {
353 $dbh->{AutoCommit} = 1;
356 sub select_all_records {
357 my $record_type = shift;
358 return ($record_type eq 'biblio') ? select_all_biblios() : select_all_authorities();
361 sub select_all_authorities {
362 my $strsth=qq{SELECT authid FROM auth_header};
363 $strsth.=qq{ WHERE $where } if ($where);
364 $strsth.=qq{ LIMIT $length } if ($length && !$offset);
365 $strsth.=qq{ LIMIT $offset,$length } if ($length && $offset);
366 my $sth = $dbh->prepare($strsth);
371 sub select_all_biblios {
372 my $strsth = qq{ SELECT biblionumber FROM biblioitems };
373 $strsth.=qq{ WHERE $where } if ($where);
374 $strsth.=qq{ LIMIT $length } if ($length && !$offset);
375 $strsth.=qq{ LIMIT $offset,$length } if ($offset);
376 my $sth = $dbh->prepare($strsth);
381 sub include_xml_wrapper {
383 my $record_type = shift;
385 return 0 unless $as_xml;
386 return 1 if $record_type eq 'biblio' and $bib_index_mode eq 'dom';
387 return 1 if $record_type eq 'authority' and $auth_index_mode eq 'dom';
392 sub export_marc_records_from_sth {
393 my ($record_type, $sth, $directory, $as_xml, $noxml, $nosanitize) = @_;
395 my $num_exported = 0;
396 open my $fh, '>:encoding(UTF-8) ', "$directory/exported_records" or die $!;
397 if (include_xml_wrapper($as_xml, $record_type)) {
398 # include XML declaration and root element
399 print {$fh} '<?xml version="1.0" encoding="UTF-8"?><collection>';
402 my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",'');
403 while (my ($record_number) = $sth->fetchrow_array) {
404 print "." if ( $verbose_logging );
405 print "\r$i" unless ($i++ %100 or !$verbose_logging);
407 my $marcxml = $record_type eq 'biblio'
408 ? GetXmlBiblio( $record_number )
409 : GetAuthorityXML( $record_number );
410 if ($record_type eq 'biblio'){
411 my @items = GetItemsInfo($record_number);
413 my $record = MARC::Record->new;
414 $record->encoding('UTF-8');
416 foreach my $item (@items){
417 my $record = Item2Marc($item, $record_number);
418 push @itemsrecord, $record->field($itemtag);
420 $record->insert_fields_ordered(@itemsrecord);
421 my $itemsxml = $record->as_xml_record();
423 substr($marcxml, 0, length($marcxml)-10) .
424 substr($itemsxml, index($itemsxml, "</leader>\n", 0) + 10);
427 # extra test to ensure that result is valid XML; otherwise
428 # Zebra won't parse it in DOM mode
430 my $doc = $tester->parse_string($marcxml);
433 warn "Error exporting record $record_number ($record_type): $@\n";
437 $marcxml =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!;
438 print {$fh} $marcxml;
443 my ($marc) = get_corrected_marc_record($record_type, $record_number, $noxml);
448 $rec = $marc->as_xml_record(C4::Context->preference('marcflavour'));
450 my $doc = $tester->parse_string($rec);
453 die "invalid XML: $@";
455 $rec =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!;
457 $rec = $marc->as_usmarc();
463 warn "Error exporting record $record_number ($record_type) ".($noxml ? "not XML" : "XML");
464 warn "... specific error is $@" if $verbose_logging;
468 print "\nRecords exported: $num_exported\n" if ( $verbose_logging );
469 print {$fh} '</collection>' if (include_xml_wrapper($as_xml, $record_type));
471 return $num_exported;
474 sub export_marc_records_from_list {
475 my ($record_type, $entries, $directory, $as_xml, $noxml, $records_deleted) = @_;
477 my $num_exported = 0;
478 open my $fh, '>:encoding(UTF-8)', "$directory/exported_records" or die $!;
479 if (include_xml_wrapper($as_xml, $record_type)) {
480 # include XML declaration and root element
481 print {$fh} '<?xml version="1.0" encoding="UTF-8"?><collection>';
485 # Skip any deleted records. We check for this anyway, but this reduces error spam
486 my %found = %$records_deleted;
487 foreach my $record_number ( map { $_->{biblio_auth_number} }
488 grep { !$found{ $_->{biblio_auth_number} }++ }
490 print "." if ( $verbose_logging );
491 print "\r$i" unless ($i++ %100 or !$verbose_logging);
492 my ($marc) = get_corrected_marc_record($record_type, $record_number, $noxml);
497 $rec = $marc->as_xml_record(C4::Context->preference('marcflavour'));
498 $rec =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!;
500 $rec = $marc->as_usmarc();
506 warn "Error exporting record $record_number ($record_type) ".($noxml ? "not XML" : "XML");
510 print "\nRecords exported: $num_exported\n" if ( $verbose_logging );
511 print {$fh} '</collection>' if (include_xml_wrapper($as_xml, $record_type));
513 return $num_exported;
516 sub generate_deleted_marc_records {
517 my ($record_type, $entries, $directory, $as_xml) = @_;
519 my $records_deleted = {};
520 open my $fh, '>:encoding(UTF-8)', "$directory/exported_records" or die $!;
521 if (include_xml_wrapper($as_xml, $record_type)) {
522 # include XML declaration and root element
523 print {$fh} '<?xml version="1.0" encoding="UTF-8"?><collection>';
526 foreach my $record_number (map { $_->{biblio_auth_number} } @$entries ) {
527 print "\r$i" unless ($i++ %100 or !$verbose_logging);
528 print "." if ( $verbose_logging );
530 my $marc = MARC::Record->new();
531 if ($record_type eq 'biblio') {
532 fix_biblio_ids($marc, $record_number, $record_number);
534 fix_authority_id($marc, $record_number);
536 if (C4::Context->preference("marcflavour") eq "UNIMARC") {
537 fix_unimarc_100($marc);
542 $rec = $marc->as_xml_record(C4::Context->preference('marcflavour'));
543 $rec =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!;
545 $rec = $marc->as_usmarc();
549 $records_deleted->{$record_number} = 1;
551 print "\nRecords exported: $i\n" if ( $verbose_logging );
552 print {$fh} '</collection>' if (include_xml_wrapper($as_xml, $record_type));
554 return $records_deleted;
559 sub get_corrected_marc_record {
560 my ($record_type, $record_number, $noxml) = @_;
562 my $marc = get_raw_marc_record($record_type, $record_number, $noxml);
566 if ($record_type eq 'authority') {
567 fix_authority_id($marc, $record_number);
568 } elsif ($record_type eq 'biblio' && C4::Context->preference('IncludeSeeFromInSearches')) {
569 my $normalizer = Koha::RecordProcessor->new( { filters => 'EmbedSeeFromHeadings' } );
570 $marc = $normalizer->process($marc);
572 if (C4::Context->preference("marcflavour") eq "UNIMARC") {
573 fix_unimarc_100($marc);
580 sub get_raw_marc_record {
581 my ($record_type, $record_number, $noxml) = @_;
584 if ($record_type eq 'biblio') {
586 my $fetch_sth = $dbh->prepare_cached("SELECT marc FROM biblioitems WHERE biblionumber = ?");
587 $fetch_sth->execute($record_number);
588 if (my ($blob) = $fetch_sth->fetchrow_array) {
589 $marc = MARC::Record->new_from_usmarc($blob);
591 warn "error creating MARC::Record from $blob";
594 # failure to find a bib is not a problem -
595 # a delete could have been done before
596 # trying to process a record update
598 $fetch_sth->finish();
601 eval { $marc = GetMarcBiblio($record_number, 1); };
603 # here we do warn since catching an exception
604 # means that the bib was found but failed
606 warn "error retrieving biblio $record_number";
611 eval { $marc = GetAuthority($record_number); };
613 warn "error retrieving authority $record_number";
621 # FIXME - this routine is suspect
622 # It blanks the Leader/00-05 and Leader/12-16 to
623 # force them to be recalculated correct when
624 # the $marc->as_usmarc() or $marc->as_xml() is called.
625 # But why is this necessary? It would be a serious bug
626 # in MARC::Record (definitely) and MARC::File::XML (arguably)
627 # if they are emitting incorrect leader values.
630 my $leader = $marc->leader;
631 substr($leader, 0, 5) = ' ';
632 substr($leader, 10, 7) = '22 ';
633 $marc->leader(substr($leader, 0, 24));
637 # FIXME - it is essential to ensure that the biblionumber is present,
638 # otherwise, Zebra will choke on the record. However, this
639 # logic belongs in the relevant C4::Biblio APIs.
641 my $biblionumber = shift;
642 my $biblioitemnumber;
644 $biblioitemnumber = shift;
646 my $sth = $dbh->prepare(
647 "SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
648 $sth->execute($biblionumber);
649 ($biblioitemnumber) = $sth->fetchrow_array;
651 unless ($biblioitemnumber) {
652 warn "failed to get biblioitemnumber for biblio $biblionumber";
657 # FIXME - this is cheating on two levels
658 # 1. C4::Biblio::_koha_marc_update_bib_ids is meant to be an internal function
659 # 2. Making sure that the biblionumber and biblioitemnumber are correct and
660 # present in the MARC::Record object ought to be part of GetMarcBiblio.
662 # On the other hand, this better for now than what rebuild_zebra.pl used to
663 # do, which was duplicate the code for inserting the biblionumber
664 # and biblioitemnumber
665 C4::Biblio::_koha_marc_update_bib_ids($marc, '', $biblionumber, $biblioitemnumber);
670 sub fix_authority_id {
671 # FIXME - as with fix_biblio_ids, the authid must be present
672 # for Zebra's sake. However, this really belongs
673 # in C4::AuthoritiesMarc.
674 my ($marc, $authid) = @_;
675 unless ($marc->field('001') and $marc->field('001')->data() eq $authid){
676 $marc->delete_field($marc->field('001'));
677 $marc->insert_fields_ordered(MARC::Field->new('001',$authid));
681 sub fix_unimarc_100 {
682 # FIXME - again, if this is necessary, it belongs in C4::AuthoritiesMarc.
686 if ( length($marc->subfield( 100, "a" )) == 36 ) {
687 $string = $marc->subfield( 100, "a" );
688 my $f100 = $marc->field(100);
689 $marc->delete_field($f100);
692 $string = POSIX::strftime( "%Y%m%d", localtime );
694 $string = sprintf( "%-*s", 35, $string );
696 substr( $string, 22, 6, "frey50" );
697 unless ( length($marc->subfield( 100, "a" )) == 36 ) {
698 $marc->delete_field($marc->field(100));
699 $marc->insert_grouped_field(MARC::Field->new( 100, "", "", "a" => $string ));
704 my ($record_type, $op, $record_dir, $reset_index, $noshadow, $record_format, $zebraidx_log_opt) = @_;
706 my $zebra_server = ($record_type eq 'biblio') ? 'biblioserver' : 'authorityserver';
707 my $zebra_db_name = ($record_type eq 'biblio') ? 'biblios' : 'authorities';
708 my $zebra_config = C4::Context->zebraconfig($zebra_server)->{'config'};
709 my $zebra_db_dir = C4::Context->zebraconfig($zebra_server)->{'directory'};
711 system("zebraidx -c $zebra_config $zebraidx_log_opt -g $record_format -d $zebra_db_name init") if $reset_index;
712 system("zebraidx -c $zebra_config $zebraidx_log_opt $noshadow -g $record_format -d $zebra_db_name $op $record_dir");
713 system("zebraidx -c $zebra_config $zebraidx_log_opt -g $record_format -d $zebra_db_name commit") unless $noshadow;
719 $0: reindex MARC bibs and/or authorities in Zebra.
721 Use this batch job to reindex all biblio or authority
722 records in your Koha database.
726 -b index bibliographic records
728 -a index authority records
730 -daemon Run in daemon mode. The program will loop checking
731 for entries on the zebraqueue table, processing
732 them incrementally if present, and then sleep
733 for a few seconds before repeating the process
734 Checking the zebraqueue table is done with a cheap
735 SQL query. This allows for near realtime update of
736 the zebra search index with low system overhead.
737 Use -sleep to control the checking interval.
739 -sleep 10 Seconds to sleep between checks of the zebraqueue
740 table in daemon mode. The default is 5 seconds.
742 -z select only updated and deleted
743 records marked in the zebraqueue
744 table. Cannot be used with -r
747 -r clear Zebra index before
748 adding records to index. Implies -w.
750 -d Temporary directory for indexing.
751 If not specified, one is automatically
752 created. The export directory
753 is automatically deleted unless
754 you supply the -k switch.
756 -k Do not delete export directory.
758 -s Skip export. Used if you have
759 already exported the records
762 -noxml index from ISO MARC blob
763 instead of MARC XML. This
764 option is recommended only
767 -x export and index as xml instead of is02709 (biblios only).
768 use this if you might have records > 99,999 chars,
770 -nosanitize export biblio/authority records directly from DB marcxml
771 field without sanitizing records. It speed up
772 dump process but could fail if DB contains badly
773 encoded records. Works only with -x,
775 -w skip shadow indexing for this batch
777 -y do NOT clear zebraqueue after indexing; normally,
778 after doing batch indexing, zebraqueue should be
779 marked done for the affected record type(s) so that
780 a running zebraqueue_daemon doesn't try to reindex
781 the same records - specify -y to override this.
782 Cannot be used with -z.
784 -v increase the amount of logging. Normally only
785 warnings and errors from the indexing are shown.
786 Use log level 2 (-v -v) to include all Zebra logs.
788 --length 1234 how many biblio you want to export
789 --offset 1243 offset you want to start to
790 example: --offset 500 --length=500 will result in a LIMIT 500,1000 (exporting 1000 records, starting by the 500th one)
791 note that the numbers are NOT related to biblionumber, that's the intended behaviour.
792 --where let you specify a WHERE query, like itemtype='BOOK'
793 or something like that
795 --munge-config Deprecated option to try
796 to fix Zebra config files.
798 --run-as-root explicitily allow script to run as 'root' user
800 --help or -h show this message.
804 # FIXME: the following routines are deprecated and
805 # will be removed once it is determined whether
806 # a script to fix Zebra configuration files is
810 # creating zebra-biblios.cfg depending on system
813 # getting zebraidx directory
815 foreach (qw(/usr/local/bin/zebraidx
824 unless ($zebraidxdir) {
826 ERROR: could not find zebraidx directory
827 ERROR: Either zebra is not installed,
828 ERROR: or it's in a directory I don't checked.
829 ERROR: do a which zebraidx and edit this file to add the result you get
833 $zebraidxdir =~ s/\/bin\/.*//;
834 print "Info : zebra is in $zebraidxdir \n";
836 # getting modules directory
838 foreach (qw(/usr/local/lib/idzebra-2.0/modules/mod-grs-xml.so
839 /usr/local/lib/idzebra/modules/mod-grs-xml.so
840 /usr/lib/idzebra/modules/mod-grs-xml.so
841 /usr/lib/idzebra-2.0/modules/mod-grs-xml.so
848 unless ($modulesdir) {
850 ERROR: could not find mod-grs-xml.so directory
851 ERROR: Either zebra is not properly compiled (libxml2 is not setup and you don t have mod-grs-xml.so,
852 ERROR: or it's in a directory I don't checked.
853 ERROR: find where mod-grs-xml.so is and edit this file to add the result you get
857 $modulesdir =~ s/\/modules\/.*//;
858 print "Info: zebra modules dir : $modulesdir\n";
860 # getting tab directory
862 foreach (qw(/usr/local/share/idzebra/tab/explain.att
863 /usr/local/share/idzebra-2.0/tab/explain.att
864 /usr/share/idzebra/tab/explain.att
865 /usr/share/idzebra-2.0/tab/explain.att
874 ERROR: could not find explain.att directory
875 ERROR: Either zebra is not properly compiled,
876 ERROR: or it's in a directory I don't checked.
877 ERROR: find where explain.att is and edit this file to add the result you get
881 $tabdir =~ s/\/tab\/.*//;
882 print "Info: tab dir : $tabdir\n";
885 # AUTHORITIES creating directory structure
887 my $created_dir_or_file = 0;
889 if ( $verbose_logging ) {
890 print "====================\n";
891 print "checking directories & files for authorities\n";
892 print "====================\n";
894 unless (-d "$authorityserverdir") {
895 system("mkdir -p $authorityserverdir");
896 print "Info: created $authorityserverdir\n";
897 $created_dir_or_file++;
899 unless (-d "$authorityserverdir/lock") {
900 mkdir "$authorityserverdir/lock";
901 print "Info: created $authorityserverdir/lock\n";
902 $created_dir_or_file++;
904 unless (-d "$authorityserverdir/register") {
905 mkdir "$authorityserverdir/register";
906 print "Info: created $authorityserverdir/register\n";
907 $created_dir_or_file++;
909 unless (-d "$authorityserverdir/shadow") {
910 mkdir "$authorityserverdir/shadow";
911 print "Info: created $authorityserverdir/shadow\n";
912 $created_dir_or_file++;
914 unless (-d "$authorityserverdir/tab") {
915 mkdir "$authorityserverdir/tab";
916 print "Info: created $authorityserverdir/tab\n";
917 $created_dir_or_file++;
919 unless (-d "$authorityserverdir/key") {
920 mkdir "$authorityserverdir/key";
921 print "Info: created $authorityserverdir/key\n";
922 $created_dir_or_file++;
925 unless (-d "$authorityserverdir/etc") {
926 mkdir "$authorityserverdir/etc";
927 print "Info: created $authorityserverdir/etc\n";
928 $created_dir_or_file++;
932 # AUTHORITIES : copying mandatory files
934 # the record model, depending on marc flavour
935 unless (-f "$authorityserverdir/tab/record.abs") {
936 if (C4::Context->preference("marcflavour") eq "UNIMARC") {
937 system("cp -f $kohadir/etc/zebradb/marc_defs/unimarc/authorities/record.abs $authorityserverdir/tab/record.abs");
938 print "Info: copied record.abs for UNIMARC\n";
940 system("cp -f $kohadir/etc/zebradb/marc_defs/marc21/authorities/record.abs $authorityserverdir/tab/record.abs");
941 print "Info: copied record.abs for USMARC\n";
943 $created_dir_or_file++;
945 unless (-f "$authorityserverdir/tab/sort-string-utf.chr") {
946 system("cp -f $kohadir/etc/zebradb/lang_defs/fr/sort-string-utf.chr $authorityserverdir/tab/sort-string-utf.chr");
947 print "Info: copied sort-string-utf.chr\n";
948 $created_dir_or_file++;
950 unless (-f "$authorityserverdir/tab/word-phrase-utf.chr") {
951 system("cp -f $kohadir/etc/zebradb/lang_defs/fr/sort-string-utf.chr $authorityserverdir/tab/word-phrase-utf.chr");
952 print "Info: copied word-phase-utf.chr\n";
953 $created_dir_or_file++;
955 unless (-f "$authorityserverdir/tab/auth1.att") {
956 system("cp -f $kohadir/etc/zebradb/authorities/etc/bib1.att $authorityserverdir/tab/auth1.att");
957 print "Info: copied auth1.att\n";
958 $created_dir_or_file++;
960 unless (-f "$authorityserverdir/tab/default.idx") {
961 system("cp -f $kohadir/etc/zebradb/etc/default.idx $authorityserverdir/tab/default.idx");
962 print "Info: copied default.idx\n";
963 $created_dir_or_file++;
966 unless (-f "$authorityserverdir/etc/ccl.properties") {
967 # system("cp -f $kohadir/etc/zebradb/ccl.properties ".C4::Context->zebraconfig('authorityserver')->{ccl2rpn});
968 system("cp -f $kohadir/etc/zebradb/ccl.properties $authorityserverdir/etc/ccl.properties");
969 print "Info: copied ccl.properties\n";
970 $created_dir_or_file++;
972 unless (-f "$authorityserverdir/etc/pqf.properties") {
973 # system("cp -f $kohadir/etc/zebradb/pqf.properties ".C4::Context->zebraconfig('authorityserver')->{ccl2rpn});
974 system("cp -f $kohadir/etc/zebradb/pqf.properties $authorityserverdir/etc/pqf.properties");
975 print "Info: copied pqf.properties\n";
976 $created_dir_or_file++;
980 # AUTHORITIES : copying mandatory files
982 unless (-f C4::Context->zebraconfig('authorityserver')->{config}) {
983 open my $zd, '>:encoding(UTF-8)' ,C4::Context->zebraconfig('authorityserver')->{config};
985 # generated by KOHA/misc/migration_tools/rebuild_zebra.pl
986 profilePath:\${srcdir:-.}:$authorityserverdir/tab/:$tabdir/tab/:\${srcdir:-.}/tab/
989 # Files that describe the attribute sets supported.
994 modulePath:$modulesdir/modules/
995 # Specify record type
996 iso2709.recordType:grs.marcxml.record
998 recordId: (auth1,Local-Number)
1004 lockDir: $authorityserverdir/lock
1007 register: $authorityserverdir/register:4G
1008 shadow: $authorityserverdir/shadow:4G
1010 # Temp File area for result sets
1011 setTmpDir: $authorityserverdir/tmp
1013 # Temp File area for index program
1014 keyTmpDir: $authorityserverdir/key
1016 # Approx. Memory usage during indexing
1020 print "Info: creating zebra-authorities.cfg\n";
1021 $created_dir_or_file++;
1024 if ($created_dir_or_file) {
1025 print "Info: created : $created_dir_or_file directories & files\n";
1027 print "Info: file & directories OK\n";
1032 if ( $verbose_logging ) {
1033 print "====================\n";
1034 print "checking directories & files for biblios\n";
1035 print "====================\n";
1039 # BIBLIOS : creating directory structure
1041 unless (-d "$biblioserverdir") {
1042 system("mkdir -p $biblioserverdir");
1043 print "Info: created $biblioserverdir\n";
1044 $created_dir_or_file++;
1046 unless (-d "$biblioserverdir/lock") {
1047 mkdir "$biblioserverdir/lock";
1048 print "Info: created $biblioserverdir/lock\n";
1049 $created_dir_or_file++;
1051 unless (-d "$biblioserverdir/register") {
1052 mkdir "$biblioserverdir/register";
1053 print "Info: created $biblioserverdir/register\n";
1054 $created_dir_or_file++;
1056 unless (-d "$biblioserverdir/shadow") {
1057 mkdir "$biblioserverdir/shadow";
1058 print "Info: created $biblioserverdir/shadow\n";
1059 $created_dir_or_file++;
1061 unless (-d "$biblioserverdir/tab") {
1062 mkdir "$biblioserverdir/tab";
1063 print "Info: created $biblioserverdir/tab\n";
1064 $created_dir_or_file++;
1066 unless (-d "$biblioserverdir/key") {
1067 mkdir "$biblioserverdir/key";
1068 print "Info: created $biblioserverdir/key\n";
1069 $created_dir_or_file++;
1071 unless (-d "$biblioserverdir/etc") {
1072 mkdir "$biblioserverdir/etc";
1073 print "Info: created $biblioserverdir/etc\n";
1074 $created_dir_or_file++;
1078 # BIBLIOS : copying mandatory files
1080 # the record model, depending on marc flavour
1081 unless (-f "$biblioserverdir/tab/record.abs") {
1082 if (C4::Context->preference("marcflavour") eq "UNIMARC") {
1083 system("cp -f $kohadir/etc/zebradb/marc_defs/unimarc/biblios/record.abs $biblioserverdir/tab/record.abs");
1084 print "Info: copied record.abs for UNIMARC\n";
1086 system("cp -f $kohadir/etc/zebradb/marc_defs/marc21/biblios/record.abs $biblioserverdir/tab/record.abs");
1087 print "Info: copied record.abs for USMARC\n";
1089 $created_dir_or_file++;
1091 unless (-f "$biblioserverdir/tab/sort-string-utf.chr") {
1092 system("cp -f $kohadir/etc/zebradb/lang_defs/fr/sort-string-utf.chr $biblioserverdir/tab/sort-string-utf.chr");
1093 print "Info: copied sort-string-utf.chr\n";
1094 $created_dir_or_file++;
1096 unless (-f "$biblioserverdir/tab/word-phrase-utf.chr") {
1097 system("cp -f $kohadir/etc/zebradb/lang_defs/fr/sort-string-utf.chr $biblioserverdir/tab/word-phrase-utf.chr");
1098 print "Info: copied word-phase-utf.chr\n";
1099 $created_dir_or_file++;
1101 unless (-f "$biblioserverdir/tab/bib1.att") {
1102 system("cp -f $kohadir/etc/zebradb/biblios/etc/bib1.att $biblioserverdir/tab/bib1.att");
1103 print "Info: copied bib1.att\n";
1104 $created_dir_or_file++;
1106 unless (-f "$biblioserverdir/tab/default.idx") {
1107 system("cp -f $kohadir/etc/zebradb/etc/default.idx $biblioserverdir/tab/default.idx");
1108 print "Info: copied default.idx\n";
1109 $created_dir_or_file++;
1111 unless (-f "$biblioserverdir/etc/ccl.properties") {
1112 # system("cp -f $kohadir/etc/zebradb/ccl.properties ".C4::Context->zebraconfig('biblioserver')->{ccl2rpn});
1113 system("cp -f $kohadir/etc/zebradb/ccl.properties $biblioserverdir/etc/ccl.properties");
1114 print "Info: copied ccl.properties\n";
1115 $created_dir_or_file++;
1117 unless (-f "$biblioserverdir/etc/pqf.properties") {
1118 # system("cp -f $kohadir/etc/zebradb/pqf.properties ".C4::Context->zebraconfig('biblioserver')->{ccl2rpn});
1119 system("cp -f $kohadir/etc/zebradb/pqf.properties $biblioserverdir/etc/pqf.properties");
1120 print "Info: copied pqf.properties\n";
1121 $created_dir_or_file++;
1125 # BIBLIOS : copying mandatory files
1127 unless (-f C4::Context->zebraconfig('biblioserver')->{config}) {
1128 open my $zd, '>:encoding(UTF-8)', C4::Context->zebraconfig('biblioserver')->{config};
1130 # generated by KOHA/misc/migrtion_tools/rebuild_zebra.pl
1131 profilePath:\${srcdir:-.}:$biblioserverdir/tab/:$tabdir/tab/:\${srcdir:-.}/tab/
1134 # Files that describe the attribute sets supported.
1139 modulePath:$modulesdir/modules/
1140 # Specify record type
1141 iso2709.recordType:grs.marcxml.record
1143 recordId: (bib1,Local-Number)
1149 lockDir: $biblioserverdir/lock
1152 register: $biblioserverdir/register:4G
1153 shadow: $biblioserverdir/shadow:4G
1155 # Temp File area for result sets
1156 setTmpDir: $biblioserverdir/tmp
1158 # Temp File area for index program
1159 keyTmpDir: $biblioserverdir/key
1161 # Approx. Memory usage during indexing
1165 print "Info: creating zebra-biblios.cfg\n";
1166 $created_dir_or_file++;
1169 if ($created_dir_or_file) {
1170 print "Info: created : $created_dir_or_file directories & files\n";
1172 print "Info: file & directories OK\n";