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 '.'));
37 my $process_zebraqueue;
38 my $do_not_clear_zebraqueue;
42 my $verbose_logging = 0;
43 my $zebraidx_log_opt = " -v none,fatal,warn ";
44 my $result = GetOptions(
49 'I|skip-index' => \$skip_index,
50 'nosanitize' => \$nosanitize,
54 'munge-config' => \$do_munge,
56 'h|help' => \$want_help,
58 'y' => \$do_not_clear_zebraqueue,
59 'z' => \$process_zebraqueue,
61 'length:i' => \$length,
62 'offset:i' => \$offset,
63 'v+' => \$verbose_logging,
67 if (not $result or $want_help) {
72 if (not $biblios and not $authorities) {
73 my $msg = "Must specify -b or -a to reindex bibs or authorities\n";
74 $msg .= "Please do '$0 --help' to see usage.\n";
78 if ( !$as_xml and $nosanitize ) {
79 my $msg = "Cannot specify both -no_xml and -nosanitize\n";
80 $msg .= "Please do '$0 --help' to see usage.\n";
84 if ($process_zebraqueue and ($skip_export or $reset)) {
85 my $msg = "Cannot specify -r or -s if -z is specified\n";
86 $msg .= "Please do '$0 --help' to see usage.\n";
90 if ($process_zebraqueue and $do_not_clear_zebraqueue) {
91 my $msg = "Cannot specify both -y and -z\n";
92 $msg .= "Please do '$0 --help' to see usage.\n";
104 # -v is for verbose, which seems backwards here because of how logging is set
105 # on the CLI of zebraidx. It works this way. The default is to not log much
106 if ($verbose_logging >= 2) {
107 $zebraidx_log_opt = '-v none,fatal,warn,all';
111 unless ($directory) {
113 $directory = tempdir(CLEANUP => ($keep_export ? 0 : 1));
117 my $biblioserverdir = C4::Context->zebraconfig('biblioserver')->{directory};
118 my $authorityserverdir = C4::Context->zebraconfig('authorityserver')->{directory};
120 my $kohadir = C4::Context->config('intranetdir');
121 my $bib_index_mode = C4::Context->config('zebra_bib_index_mode') || 'grs1';
122 my $auth_index_mode = C4::Context->config('zebra_auth_index_mode') || 'dom';
124 my $dbh = C4::Context->dbh;
125 my ($biblionumbertagfield,$biblionumbertagsubfield) = &GetMarcFromKohaField("biblio.biblionumber","");
126 my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = &GetMarcFromKohaField("biblioitems.biblioitemnumber","");
128 if ( $verbose_logging ) {
129 print "Zebra configuration information\n";
130 print "================================\n";
131 print "Zebra biblio directory = $biblioserverdir\n";
132 print "Zebra authorities directory = $authorityserverdir\n";
133 print "Koha directory = $kohadir\n";
134 print "BIBLIONUMBER in : $biblionumbertagfield\$$biblionumbertagsubfield\n";
135 print "BIBLIOITEMNUMBER in : $biblioitemnumbertagfield\$$biblioitemnumbertagsubfield\n";
136 print "================================\n";
144 index_records('authority', $directory, $skip_export, $skip_index, $process_zebraqueue, $as_xml, $noxml, $nosanitize, $do_not_clear_zebraqueue, $verbose_logging, $zebraidx_log_opt, $authorityserverdir);
146 print "skipping authorities\n" if ( $verbose_logging );
150 index_records('biblio', $directory, $skip_export, $skip_index, $process_zebraqueue, $as_xml, $noxml, $nosanitize, $do_not_clear_zebraqueue, $verbose_logging, $zebraidx_log_opt, $biblioserverdir);
152 print "skipping biblios\n" if ( $verbose_logging );
156 if ( $verbose_logging ) {
157 print "====================\n";
159 print "====================\n";
162 print "NOTHING cleaned : the export $directory has been kept.\n";
163 print "You can re-run this script with the -s ";
165 print " and -d $directory parameters";
170 print "if you just want to rebuild zebra after changing the record.abs\n";
171 print "or another zebra config file\n";
173 unless ($use_tempdir) {
174 # if we're using a temporary directory
175 # created by File::Temp, it will be removed
177 rmtree($directory, 0, 1);
178 print "directory $directory deleted\n";
182 # This checks to see if the zebra directories exist under the provided path.
183 # If they don't, then zebra is likely to spit the dummy. This returns true
184 # if the directories had to be created, false otherwise.
185 sub check_zebra_dirs {
186 my ($base) = shift() . '/';
187 my $needed_repairing = 0;
188 my @dirs = ( '', 'key', 'register', 'shadow', 'tmp' );
189 foreach my $dir (@dirs) {
190 my $bdir = $base . $dir;
192 $needed_repairing = 1;
193 mkdir $bdir || die "Unable to create '$bdir': $!\n";
194 print "$0: needed to create '$bdir'\n";
197 return $needed_repairing;
198 } # ---------- end of subroutine check_zebra_dirs ----------
201 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) = @_;
203 my $num_records_exported = 0;
205 my $need_reset = check_zebra_dirs($server_dir);
207 print "$0: found broken zebra server directories: forcing a rebuild\n";
210 if ($skip_export && $verbose_logging) {
211 print "====================\n";
212 print "SKIPPING $record_type export\n";
213 print "====================\n";
215 if ( $verbose_logging ) {
216 print "====================\n";
217 print "exporting $record_type\n";
218 print "====================\n";
220 mkdir "$directory" unless (-d $directory);
221 mkdir "$directory/$record_type" unless (-d "$directory/$record_type");
222 if ($process_zebraqueue) {
223 my $entries = select_zebraqueue_records($record_type, 'deleted');
224 mkdir "$directory/del_$record_type" unless (-d "$directory/del_$record_type");
225 $records_deleted = generate_deleted_marc_records($record_type, $entries, "$directory/del_$record_type", $as_xml);
226 mark_zebraqueue_batch_done($entries);
227 $entries = select_zebraqueue_records($record_type, 'updated');
228 mkdir "$directory/upd_$record_type" unless (-d "$directory/upd_$record_type");
229 $num_records_exported = export_marc_records_from_list($record_type,
230 $entries, "$directory/upd_$record_type", $as_xml, $noxml, $records_deleted);
231 mark_zebraqueue_batch_done($entries);
233 my $sth = select_all_records($record_type);
234 $num_records_exported = export_marc_records_from_sth($record_type, $sth, "$directory/$record_type", $as_xml, $noxml, $nosanitize);
235 unless ($do_not_clear_zebraqueue) {
236 mark_all_zebraqueue_done($record_type);
242 # and reindexing everything
245 if ($verbose_logging) {
246 print "====================\n";
247 print "SKIPPING $record_type indexing\n";
248 print "====================\n";
251 if ( $verbose_logging ) {
252 print "====================\n";
253 print "REINDEXING zebra\n";
254 print "====================\n";
256 my $record_fmt = ($as_xml) ? 'marcxml' : 'iso2709' ;
257 if ($process_zebraqueue) {
258 do_indexing($record_type, 'adelete', "$directory/del_$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt)
259 if %$records_deleted;
260 do_indexing($record_type, 'update', "$directory/upd_$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt)
261 if $num_records_exported;
263 do_indexing($record_type, 'update', "$directory/$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt)
264 if ($num_records_exported or $skip_export);
270 sub select_zebraqueue_records {
271 my ($record_type, $update_type) = @_;
273 my $server = ($record_type eq 'biblio') ? 'biblioserver' : 'authorityserver';
274 my $op = ($update_type eq 'deleted') ? 'recordDelete' : 'specialUpdate';
276 my $sth = $dbh->prepare("SELECT id, biblio_auth_number
282 $sth->execute($server, $op);
283 my $entries = $sth->fetchall_arrayref({});
286 sub mark_all_zebraqueue_done {
287 my ($record_type) = @_;
289 my $server = ($record_type eq 'biblio') ? 'biblioserver' : 'authorityserver';
291 my $sth = $dbh->prepare("UPDATE zebraqueue SET done = 1
294 $sth->execute($server);
297 sub mark_zebraqueue_batch_done {
300 $dbh->{AutoCommit} = 0;
301 my $sth = $dbh->prepare("UPDATE zebraqueue SET done = 1 WHERE id = ?");
303 foreach my $id (map { $_->{id} } @$entries) {
306 $dbh->{AutoCommit} = 1;
309 sub select_all_records {
310 my $record_type = shift;
311 return ($record_type eq 'biblio') ? select_all_biblios() : select_all_authorities();
314 sub select_all_authorities {
315 my $strsth=qq{SELECT authid FROM auth_header};
316 $strsth.=qq{ WHERE $where } if ($where);
317 $strsth.=qq{ LIMIT $length } if ($length && !$offset);
318 $strsth.=qq{ LIMIT $offset,$length } if ($length && $offset);
319 my $sth = $dbh->prepare($strsth);
324 sub select_all_biblios {
325 my $strsth = qq{ SELECT biblionumber FROM biblioitems };
326 $strsth.=qq{ WHERE $where } if ($where);
327 $strsth.=qq{ LIMIT $length } if ($length && !$offset);
328 $strsth.=qq{ LIMIT $offset,$length } if ($offset);
329 my $sth = $dbh->prepare($strsth);
334 sub include_xml_wrapper {
336 my $record_type = shift;
338 return 0 unless $as_xml;
339 return 1 if $record_type eq 'biblio' and $bib_index_mode eq 'dom';
340 return 1 if $record_type eq 'authority' and $auth_index_mode eq 'dom';
345 sub export_marc_records_from_sth {
346 my ($record_type, $sth, $directory, $as_xml, $noxml, $nosanitize) = @_;
348 my $num_exported = 0;
349 open my $fh, '>:encoding(UTF-8) ', "$directory/exported_records" or die $!;
350 if (include_xml_wrapper($as_xml, $record_type)) {
351 # include XML declaration and root element
352 print {$fh} '<?xml version="1.0" encoding="UTF-8"?><collection>';
355 my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",'');
356 while (my ($record_number) = $sth->fetchrow_array) {
357 print "." if ( $verbose_logging );
358 print "\r$i" unless ($i++ %100 or !$verbose_logging);
360 my $marcxml = $record_type eq 'biblio'
361 ? GetXmlBiblio( $record_number )
362 : GetAuthorityXML( $record_number );
363 if ($record_type eq 'biblio'){
364 my @items = GetItemsInfo($record_number);
366 my $record = MARC::Record->new;
367 $record->encoding('UTF-8');
369 foreach my $item (@items){
370 my $record = Item2Marc($item, $record_number);
371 push @itemsrecord, $record->field($itemtag);
373 $record->insert_fields_ordered(@itemsrecord);
374 my $itemsxml = $record->as_xml_record();
376 substr($marcxml, 0, length($marcxml)-10) .
377 substr($itemsxml, index($itemsxml, "</leader>\n", 0) + 10);
381 print {$fh} $marcxml if $marcxml;
386 my ($marc) = get_corrected_marc_record($record_type, $record_number, $noxml);
391 $rec = $marc->as_xml_record(C4::Context->preference('marcflavour'));
392 $rec =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!;
394 $rec = $marc->as_usmarc();
400 warn "Error exporting record $record_number ($record_type) ".($noxml ? "not XML" : "XML");
404 print "\nRecords exported: $num_exported\n" if ( $verbose_logging );
405 print {$fh} '</collection>' if (include_xml_wrapper($as_xml, $record_type));
407 return $num_exported;
410 sub export_marc_records_from_list {
411 my ($record_type, $entries, $directory, $as_xml, $noxml, $records_deleted) = @_;
413 my $num_exported = 0;
414 open my $fh, '>:encoding(UTF-8)', "$directory/exported_records" or die $!;
415 if (include_xml_wrapper($as_xml, $record_type)) {
416 # include XML declaration and root element
417 print {$fh} '<?xml version="1.0" encoding="UTF-8"?><collection>';
421 # Skip any deleted records. We check for this anyway, but this reduces error spam
422 my %found = %$records_deleted;
423 foreach my $record_number ( map { $_->{biblio_auth_number} }
424 grep { !$found{ $_->{biblio_auth_number} }++ }
426 print "." if ( $verbose_logging );
427 print "\r$i" unless ($i++ %100 or !$verbose_logging);
428 my ($marc) = get_corrected_marc_record($record_type, $record_number, $noxml);
433 $rec = $marc->as_xml_record(C4::Context->preference('marcflavour'));
434 $rec =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!;
436 $rec = $marc->as_usmarc();
442 warn "Error exporting record $record_number ($record_type) ".($noxml ? "not XML" : "XML");
447 print "\nRecords exported: $num_exported\n" if ( $verbose_logging );
448 print {$fh} '</collection>' if (include_xml_wrapper($as_xml, $record_type));
450 return $num_exported;
453 sub generate_deleted_marc_records {
454 my ($record_type, $entries, $directory, $as_xml) = @_;
456 my $records_deleted = {};
457 open my $fh, '>:encoding(UTF-8)', "$directory/exported_records" or die $!;
458 if (include_xml_wrapper($as_xml, $record_type)) {
459 # include XML declaration and root element
460 print {$fh} '<?xml version="1.0" encoding="UTF-8"?><collection>';
463 foreach my $record_number (map { $_->{biblio_auth_number} } @$entries ) {
464 print "\r$i" unless ($i++ %100 or !$verbose_logging);
465 print "." if ( $verbose_logging );
467 my $marc = MARC::Record->new();
468 if ($record_type eq 'biblio') {
469 fix_biblio_ids($marc, $record_number, $record_number);
471 fix_authority_id($marc, $record_number);
473 if (C4::Context->preference("marcflavour") eq "UNIMARC") {
474 fix_unimarc_100($marc);
479 $rec = $marc->as_xml_record(C4::Context->preference('marcflavour'));
480 $rec =~ s!<\?xml version="1.0" encoding="UTF-8"\?>\n!!;
482 $rec = $marc->as_usmarc();
486 $records_deleted->{$record_number} = 1;
488 print "\nRecords exported: $i\n" if ( $verbose_logging );
489 print {$fh} '</collection>' if (include_xml_wrapper($as_xml, $record_type));
491 return $records_deleted;
496 sub get_corrected_marc_record {
497 my ($record_type, $record_number, $noxml) = @_;
499 my $marc = get_raw_marc_record($record_type, $record_number, $noxml);
503 if ($record_type eq 'authority') {
504 fix_authority_id($marc, $record_number);
505 } elsif ($record_type eq 'biblio' && C4::Context->preference('IncludeSeeFromInSearches')) {
506 my $normalizer = Koha::RecordProcessor->new( { filters => 'EmbedSeeFromHeadings' } );
507 $marc = $normalizer->process($marc);
509 if (C4::Context->preference("marcflavour") eq "UNIMARC") {
510 fix_unimarc_100($marc);
517 sub get_raw_marc_record {
518 my ($record_type, $record_number, $noxml) = @_;
521 if ($record_type eq 'biblio') {
523 my $fetch_sth = $dbh->prepare_cached("SELECT marc FROM biblioitems WHERE biblionumber = ?");
524 $fetch_sth->execute($record_number);
525 if (my ($blob) = $fetch_sth->fetchrow_array) {
526 $marc = MARC::Record->new_from_usmarc($blob);
528 warn "error creating MARC::Record from $blob";
531 # failure to find a bib is not a problem -
532 # a delete could have been done before
533 # trying to process a record update
535 $fetch_sth->finish();
538 eval { $marc = GetMarcBiblio($record_number, 1); };
540 # here we do warn since catching an exception
541 # means that the bib was found but failed
543 warn "error retrieving biblio $record_number";
548 eval { $marc = GetAuthority($record_number); };
550 warn "error retrieving authority $record_number";
558 # FIXME - this routine is suspect
559 # It blanks the Leader/00-05 and Leader/12-16 to
560 # force them to be recalculated correct when
561 # the $marc->as_usmarc() or $marc->as_xml() is called.
562 # But why is this necessary? It would be a serious bug
563 # in MARC::Record (definitely) and MARC::File::XML (arguably)
564 # if they are emitting incorrect leader values.
567 my $leader = $marc->leader;
568 substr($leader, 0, 5) = ' ';
569 substr($leader, 10, 7) = '22 ';
570 $marc->leader(substr($leader, 0, 24));
574 # FIXME - it is essential to ensure that the biblionumber is present,
575 # otherwise, Zebra will choke on the record. However, this
576 # logic belongs in the relevant C4::Biblio APIs.
578 my $biblionumber = shift;
579 my $biblioitemnumber;
581 $biblioitemnumber = shift;
583 my $sth = $dbh->prepare(
584 "SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
585 $sth->execute($biblionumber);
586 ($biblioitemnumber) = $sth->fetchrow_array;
588 unless ($biblioitemnumber) {
589 warn "failed to get biblioitemnumber for biblio $biblionumber";
594 # FIXME - this is cheating on two levels
595 # 1. C4::Biblio::_koha_marc_update_bib_ids is meant to be an internal function
596 # 2. Making sure that the biblionumber and biblioitemnumber are correct and
597 # present in the MARC::Record object ought to be part of GetMarcBiblio.
599 # On the other hand, this better for now than what rebuild_zebra.pl used to
600 # do, which was duplicate the code for inserting the biblionumber
601 # and biblioitemnumber
602 C4::Biblio::_koha_marc_update_bib_ids($marc, '', $biblionumber, $biblioitemnumber);
607 sub fix_authority_id {
608 # FIXME - as with fix_biblio_ids, the authid must be present
609 # for Zebra's sake. However, this really belongs
610 # in C4::AuthoritiesMarc.
611 my ($marc, $authid) = @_;
612 unless ($marc->field('001') and $marc->field('001')->data() eq $authid){
613 $marc->delete_field($marc->field('001'));
614 $marc->insert_fields_ordered(MARC::Field->new('001',$authid));
618 sub fix_unimarc_100 {
619 # FIXME - again, if this is necessary, it belongs in C4::AuthoritiesMarc.
623 if ( length($marc->subfield( 100, "a" )) == 36 ) {
624 $string = $marc->subfield( 100, "a" );
625 my $f100 = $marc->field(100);
626 $marc->delete_field($f100);
629 $string = POSIX::strftime( "%Y%m%d", localtime );
631 $string = sprintf( "%-*s", 35, $string );
633 substr( $string, 22, 6, "frey50" );
634 unless ( length($marc->subfield( 100, "a" )) == 36 ) {
635 $marc->delete_field($marc->field(100));
636 $marc->insert_grouped_field(MARC::Field->new( 100, "", "", "a" => $string ));
641 my ($record_type, $op, $record_dir, $reset_index, $noshadow, $record_format, $zebraidx_log_opt) = @_;
643 my $zebra_server = ($record_type eq 'biblio') ? 'biblioserver' : 'authorityserver';
644 my $zebra_db_name = ($record_type eq 'biblio') ? 'biblios' : 'authorities';
645 my $zebra_config = C4::Context->zebraconfig($zebra_server)->{'config'};
646 my $zebra_db_dir = C4::Context->zebraconfig($zebra_server)->{'directory'};
648 system("zebraidx -c $zebra_config $zebraidx_log_opt -g $record_format -d $zebra_db_name init") if $reset_index;
649 system("zebraidx -c $zebra_config $zebraidx_log_opt $noshadow -g $record_format -d $zebra_db_name $op $record_dir");
650 system("zebraidx -c $zebra_config $zebraidx_log_opt -g $record_format -d $zebra_db_name commit") unless $noshadow;
656 $0: reindex MARC bibs and/or authorities in Zebra.
658 Use this batch job to reindex all biblio or authority
659 records in your Koha database. This job is useful
660 only if you are using Zebra; if you are using the 'NoZebra'
661 mode, this job should not be used.
664 -b index bibliographic records
666 -a index authority records
668 -z select only updated and deleted
669 records marked in the zebraqueue
670 table. Cannot be used with -r
673 -r clear Zebra index before
674 adding records to index. Implies -w.
676 -d Temporary directory for indexing.
677 If not specified, one is automatically
678 created. The export directory
679 is automatically deleted unless
680 you supply the -k switch.
682 -k Do not delete export directory.
684 -s Skip export. Used if you have
685 already exported the records
688 -noxml index from ISO MARC blob
689 instead of MARC XML. This
690 option is recommended only
693 -x export and index as xml instead of is02709 (biblios only).
694 use this if you might have records > 99,999 chars,
696 -nosanitize export biblio/authority records directly from DB marcxml
697 field without sanitizing records. It speed up
698 dump process but could fail if DB contains badly
699 encoded records. Works only with -x,
701 -w skip shadow indexing for this batch
703 -y do NOT clear zebraqueue after indexing; normally,
704 after doing batch indexing, zebraqueue should be
705 marked done for the affected record type(s) so that
706 a running zebraqueue_daemon doesn't try to reindex
707 the same records - specify -y to override this.
708 Cannot be used with -z.
710 -v increase the amount of logging. Normally only
711 warnings and errors from the indexing are shown.
712 Use log level 2 (-v -v) to include all Zebra logs.
714 --length 1234 how many biblio you want to export
715 --offset 1243 offset you want to start to
716 example: --offset 500 --length=500 will result in a LIMIT 500,1000 (exporting 1000 records, starting by the 500th one)
717 note that the numbers are NOT related to biblionumber, that's the intended behaviour.
718 --where let you specify a WHERE query, like itemtype='BOOK'
719 or something like that
721 --munge-config Deprecated option to try
722 to fix Zebra config files.
723 --help or -h show this message.
727 # FIXME: the following routines are deprecated and
728 # will be removed once it is determined whether
729 # a script to fix Zebra configuration files is
733 # creating zebra-biblios.cfg depending on system
736 # getting zebraidx directory
738 foreach (qw(/usr/local/bin/zebraidx
747 unless ($zebraidxdir) {
749 ERROR: could not find zebraidx directory
750 ERROR: Either zebra is not installed,
751 ERROR: or it's in a directory I don't checked.
752 ERROR: do a which zebraidx and edit this file to add the result you get
756 $zebraidxdir =~ s/\/bin\/.*//;
757 print "Info : zebra is in $zebraidxdir \n";
759 # getting modules directory
761 foreach (qw(/usr/local/lib/idzebra-2.0/modules/mod-grs-xml.so
762 /usr/local/lib/idzebra/modules/mod-grs-xml.so
763 /usr/lib/idzebra/modules/mod-grs-xml.so
764 /usr/lib/idzebra-2.0/modules/mod-grs-xml.so
771 unless ($modulesdir) {
773 ERROR: could not find mod-grs-xml.so directory
774 ERROR: Either zebra is not properly compiled (libxml2 is not setup and you don t have mod-grs-xml.so,
775 ERROR: or it's in a directory I don't checked.
776 ERROR: find where mod-grs-xml.so is and edit this file to add the result you get
780 $modulesdir =~ s/\/modules\/.*//;
781 print "Info: zebra modules dir : $modulesdir\n";
783 # getting tab directory
785 foreach (qw(/usr/local/share/idzebra/tab/explain.att
786 /usr/local/share/idzebra-2.0/tab/explain.att
787 /usr/share/idzebra/tab/explain.att
788 /usr/share/idzebra-2.0/tab/explain.att
797 ERROR: could not find explain.att directory
798 ERROR: Either zebra is not properly compiled,
799 ERROR: or it's in a directory I don't checked.
800 ERROR: find where explain.att is and edit this file to add the result you get
804 $tabdir =~ s/\/tab\/.*//;
805 print "Info: tab dir : $tabdir\n";
808 # AUTHORITIES creating directory structure
810 my $created_dir_or_file = 0;
812 if ( $verbose_logging ) {
813 print "====================\n";
814 print "checking directories & files for authorities\n";
815 print "====================\n";
817 unless (-d "$authorityserverdir") {
818 system("mkdir -p $authorityserverdir");
819 print "Info: created $authorityserverdir\n";
820 $created_dir_or_file++;
822 unless (-d "$authorityserverdir/lock") {
823 mkdir "$authorityserverdir/lock";
824 print "Info: created $authorityserverdir/lock\n";
825 $created_dir_or_file++;
827 unless (-d "$authorityserverdir/register") {
828 mkdir "$authorityserverdir/register";
829 print "Info: created $authorityserverdir/register\n";
830 $created_dir_or_file++;
832 unless (-d "$authorityserverdir/shadow") {
833 mkdir "$authorityserverdir/shadow";
834 print "Info: created $authorityserverdir/shadow\n";
835 $created_dir_or_file++;
837 unless (-d "$authorityserverdir/tab") {
838 mkdir "$authorityserverdir/tab";
839 print "Info: created $authorityserverdir/tab\n";
840 $created_dir_or_file++;
842 unless (-d "$authorityserverdir/key") {
843 mkdir "$authorityserverdir/key";
844 print "Info: created $authorityserverdir/key\n";
845 $created_dir_or_file++;
848 unless (-d "$authorityserverdir/etc") {
849 mkdir "$authorityserverdir/etc";
850 print "Info: created $authorityserverdir/etc\n";
851 $created_dir_or_file++;
855 # AUTHORITIES : copying mandatory files
857 # the record model, depending on marc flavour
858 unless (-f "$authorityserverdir/tab/record.abs") {
859 if (C4::Context->preference("marcflavour") eq "UNIMARC") {
860 system("cp -f $kohadir/etc/zebradb/marc_defs/unimarc/authorities/record.abs $authorityserverdir/tab/record.abs");
861 print "Info: copied record.abs for UNIMARC\n";
863 system("cp -f $kohadir/etc/zebradb/marc_defs/marc21/authorities/record.abs $authorityserverdir/tab/record.abs");
864 print "Info: copied record.abs for USMARC\n";
866 $created_dir_or_file++;
868 unless (-f "$authorityserverdir/tab/sort-string-utf.chr") {
869 system("cp -f $kohadir/etc/zebradb/lang_defs/fr/sort-string-utf.chr $authorityserverdir/tab/sort-string-utf.chr");
870 print "Info: copied sort-string-utf.chr\n";
871 $created_dir_or_file++;
873 unless (-f "$authorityserverdir/tab/word-phrase-utf.chr") {
874 system("cp -f $kohadir/etc/zebradb/lang_defs/fr/sort-string-utf.chr $authorityserverdir/tab/word-phrase-utf.chr");
875 print "Info: copied word-phase-utf.chr\n";
876 $created_dir_or_file++;
878 unless (-f "$authorityserverdir/tab/auth1.att") {
879 system("cp -f $kohadir/etc/zebradb/authorities/etc/bib1.att $authorityserverdir/tab/auth1.att");
880 print "Info: copied auth1.att\n";
881 $created_dir_or_file++;
883 unless (-f "$authorityserverdir/tab/default.idx") {
884 system("cp -f $kohadir/etc/zebradb/etc/default.idx $authorityserverdir/tab/default.idx");
885 print "Info: copied default.idx\n";
886 $created_dir_or_file++;
889 unless (-f "$authorityserverdir/etc/ccl.properties") {
890 # system("cp -f $kohadir/etc/zebradb/ccl.properties ".C4::Context->zebraconfig('authorityserver')->{ccl2rpn});
891 system("cp -f $kohadir/etc/zebradb/ccl.properties $authorityserverdir/etc/ccl.properties");
892 print "Info: copied ccl.properties\n";
893 $created_dir_or_file++;
895 unless (-f "$authorityserverdir/etc/pqf.properties") {
896 # system("cp -f $kohadir/etc/zebradb/pqf.properties ".C4::Context->zebraconfig('authorityserver')->{ccl2rpn});
897 system("cp -f $kohadir/etc/zebradb/pqf.properties $authorityserverdir/etc/pqf.properties");
898 print "Info: copied pqf.properties\n";
899 $created_dir_or_file++;
903 # AUTHORITIES : copying mandatory files
905 unless (-f C4::Context->zebraconfig('authorityserver')->{config}) {
906 open my $zd, '>:encoding(UTF-8)' ,C4::Context->zebraconfig('authorityserver')->{config};
908 # generated by KOHA/misc/migration_tools/rebuild_zebra.pl
909 profilePath:\${srcdir:-.}:$authorityserverdir/tab/:$tabdir/tab/:\${srcdir:-.}/tab/
912 # Files that describe the attribute sets supported.
917 modulePath:$modulesdir/modules/
918 # Specify record type
919 iso2709.recordType:grs.marcxml.record
921 recordId: (auth1,Local-Number)
927 lockDir: $authorityserverdir/lock
930 register: $authorityserverdir/register:4G
931 shadow: $authorityserverdir/shadow:4G
933 # Temp File area for result sets
934 setTmpDir: $authorityserverdir/tmp
936 # Temp File area for index program
937 keyTmpDir: $authorityserverdir/key
939 # Approx. Memory usage during indexing
943 print "Info: creating zebra-authorities.cfg\n";
944 $created_dir_or_file++;
947 if ($created_dir_or_file) {
948 print "Info: created : $created_dir_or_file directories & files\n";
950 print "Info: file & directories OK\n";
955 if ( $verbose_logging ) {
956 print "====================\n";
957 print "checking directories & files for biblios\n";
958 print "====================\n";
962 # BIBLIOS : creating directory structure
964 unless (-d "$biblioserverdir") {
965 system("mkdir -p $biblioserverdir");
966 print "Info: created $biblioserverdir\n";
967 $created_dir_or_file++;
969 unless (-d "$biblioserverdir/lock") {
970 mkdir "$biblioserverdir/lock";
971 print "Info: created $biblioserverdir/lock\n";
972 $created_dir_or_file++;
974 unless (-d "$biblioserverdir/register") {
975 mkdir "$biblioserverdir/register";
976 print "Info: created $biblioserverdir/register\n";
977 $created_dir_or_file++;
979 unless (-d "$biblioserverdir/shadow") {
980 mkdir "$biblioserverdir/shadow";
981 print "Info: created $biblioserverdir/shadow\n";
982 $created_dir_or_file++;
984 unless (-d "$biblioserverdir/tab") {
985 mkdir "$biblioserverdir/tab";
986 print "Info: created $biblioserverdir/tab\n";
987 $created_dir_or_file++;
989 unless (-d "$biblioserverdir/key") {
990 mkdir "$biblioserverdir/key";
991 print "Info: created $biblioserverdir/key\n";
992 $created_dir_or_file++;
994 unless (-d "$biblioserverdir/etc") {
995 mkdir "$biblioserverdir/etc";
996 print "Info: created $biblioserverdir/etc\n";
997 $created_dir_or_file++;
1001 # BIBLIOS : copying mandatory files
1003 # the record model, depending on marc flavour
1004 unless (-f "$biblioserverdir/tab/record.abs") {
1005 if (C4::Context->preference("marcflavour") eq "UNIMARC") {
1006 system("cp -f $kohadir/etc/zebradb/marc_defs/unimarc/biblios/record.abs $biblioserverdir/tab/record.abs");
1007 print "Info: copied record.abs for UNIMARC\n";
1009 system("cp -f $kohadir/etc/zebradb/marc_defs/marc21/biblios/record.abs $biblioserverdir/tab/record.abs");
1010 print "Info: copied record.abs for USMARC\n";
1012 $created_dir_or_file++;
1014 unless (-f "$biblioserverdir/tab/sort-string-utf.chr") {
1015 system("cp -f $kohadir/etc/zebradb/lang_defs/fr/sort-string-utf.chr $biblioserverdir/tab/sort-string-utf.chr");
1016 print "Info: copied sort-string-utf.chr\n";
1017 $created_dir_or_file++;
1019 unless (-f "$biblioserverdir/tab/word-phrase-utf.chr") {
1020 system("cp -f $kohadir/etc/zebradb/lang_defs/fr/sort-string-utf.chr $biblioserverdir/tab/word-phrase-utf.chr");
1021 print "Info: copied word-phase-utf.chr\n";
1022 $created_dir_or_file++;
1024 unless (-f "$biblioserverdir/tab/bib1.att") {
1025 system("cp -f $kohadir/etc/zebradb/biblios/etc/bib1.att $biblioserverdir/tab/bib1.att");
1026 print "Info: copied bib1.att\n";
1027 $created_dir_or_file++;
1029 unless (-f "$biblioserverdir/tab/default.idx") {
1030 system("cp -f $kohadir/etc/zebradb/etc/default.idx $biblioserverdir/tab/default.idx");
1031 print "Info: copied default.idx\n";
1032 $created_dir_or_file++;
1034 unless (-f "$biblioserverdir/etc/ccl.properties") {
1035 # system("cp -f $kohadir/etc/zebradb/ccl.properties ".C4::Context->zebraconfig('biblioserver')->{ccl2rpn});
1036 system("cp -f $kohadir/etc/zebradb/ccl.properties $biblioserverdir/etc/ccl.properties");
1037 print "Info: copied ccl.properties\n";
1038 $created_dir_or_file++;
1040 unless (-f "$biblioserverdir/etc/pqf.properties") {
1041 # system("cp -f $kohadir/etc/zebradb/pqf.properties ".C4::Context->zebraconfig('biblioserver')->{ccl2rpn});
1042 system("cp -f $kohadir/etc/zebradb/pqf.properties $biblioserverdir/etc/pqf.properties");
1043 print "Info: copied pqf.properties\n";
1044 $created_dir_or_file++;
1048 # BIBLIOS : copying mandatory files
1050 unless (-f C4::Context->zebraconfig('biblioserver')->{config}) {
1051 open my $zd, '>:encoding(UTF-8)', C4::Context->zebraconfig('biblioserver')->{config};
1053 # generated by KOHA/misc/migrtion_tools/rebuild_zebra.pl
1054 profilePath:\${srcdir:-.}:$biblioserverdir/tab/:$tabdir/tab/:\${srcdir:-.}/tab/
1057 # Files that describe the attribute sets supported.
1062 modulePath:$modulesdir/modules/
1063 # Specify record type
1064 iso2709.recordType:grs.marcxml.record
1066 recordId: (bib1,Local-Number)
1072 lockDir: $biblioserverdir/lock
1075 register: $biblioserverdir/register:4G
1076 shadow: $biblioserverdir/shadow:4G
1078 # Temp File area for result sets
1079 setTmpDir: $biblioserverdir/tmp
1081 # Temp File area for index program
1082 keyTmpDir: $biblioserverdir/key
1084 # Approx. Memory usage during indexing
1088 print "Info: creating zebra-biblios.cfg\n";
1089 $created_dir_or_file++;
1092 if ($created_dir_or_file) {
1093 print "Info: created : $created_dir_or_file directories & files\n";
1095 print "Info: file & directories OK\n";