a54c75bb8ee4538805235d117d73c0bf1084f3e1
[koha.git] / misc / migration_tools / rebuild_zebra.pl
1 #!/usr/bin/perl
2
3 use strict;
4
5 use C4::Context;
6 use Getopt::Long;
7 use File::Temp qw/ tempdir /;
8 use File::Path;
9 use C4::Biblio;
10 use C4::AuthoritiesMarc;
11
12
13 # script that checks zebradir structure & create directories & mandatory files if needed
14 #
15 #
16
17 $|=1; # flushes output
18
19 # limit for database dumping
20 my $limit;# = "LIMIT 1";
21 my $directory;
22 my $skip_export;
23 my $keep_export;
24 my $reset;
25 my $biblios;
26 my $authorities;
27 my $noxml;
28 my $noshadow;
29 my $do_munge;
30 my $want_help;
31 my $as_xml;
32 my $result = GetOptions(
33     'd:s'           => \$directory,
34     'reset'         => \$reset,
35     's'             => \$skip_export,
36     'k'             => \$keep_export,
37     'b'             => \$biblios,
38     'noxml'         => \$noxml,
39     'w'             => \$noshadow,
40     'munge-config'  => \$do_munge,
41     'a'             => \$authorities,
42     'h|help'        => \$want_help,
43         'x'                             => \$as_xml,
44 );
45
46
47 if (not $result or $want_help) {
48     print_usage();
49     exit 0;
50 }
51
52 if (not $biblios and not $authorities) {
53     my $msg = "Must specify -b or -a to reindex bibs or authorites\n";
54     $msg   .= "Please do '$0 --help' to see usage.\n";
55     die $msg;
56 }
57
58 if ($noshadow) {
59     $noshadow = ' -n ';
60 }
61 my $use_tempdir = 0;
62 unless ($directory) {
63     $use_tempdir = 1;
64     $directory = tempdir(CLEANUP => ($keep_export ? 0 : 1));
65
66
67
68 my $biblioserverdir = C4::Context->zebraconfig('biblioserver')->{directory};
69 my $authorityserverdir = C4::Context->zebraconfig('authorityserver')->{directory};
70
71 my $kohadir = C4::Context->config('intranetdir');
72 my $dbh = C4::Context->dbh;
73 my ($biblionumbertagfield,$biblionumbertagsubfield) = &GetMarcFromKohaField("biblio.biblionumber","");
74 my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = &GetMarcFromKohaField("biblioitems.biblioitemnumber","");
75
76 print "Zebra configuration information\n";
77 print "================================\n";
78 print "Zebra biblio directory      = $biblioserverdir\n";
79 print "Zebra authorities directory = $authorityserverdir\n";
80 print "Koha directory              = $kohadir\n";
81 print "BIBLIONUMBER in :     $biblionumbertagfield\$$biblionumbertagsubfield\n";
82 print "BIBLIOITEMNUMBER in : $biblioitemnumbertagfield\$$biblioitemnumbertagsubfield\n";
83 print "================================\n";
84
85 if ($do_munge) {
86     munge_config();
87 }
88
89 if ($authorities) {
90     #
91     # exporting authorities
92     #
93     if ($skip_export) {
94         print "====================\n";
95         print "SKIPPING authorities export\n";
96         print "====================\n";
97     } else {
98         print "====================\n";
99         print "exporting authorities\n";
100         print "====================\n";
101         mkdir "$directory" unless (-d $directory);
102         mkdir "$directory/authorities" unless (-d "$directory/authorities");
103         open(OUT,">:utf8","$directory/authorities/authorities.iso2709") or die $!;
104         my $dbh=C4::Context->dbh;
105         my $sth;
106         $sth=$dbh->prepare("select authid,marc from auth_header $limit");
107         $sth->execute();
108         my $i=0;
109         while (my ($authid,$record) = $sth->fetchrow) {
110             # FIXME : we retrieve the iso2709 record. if the GetAuthority (that uses the XML) fails
111             # due to some MARC::File::XML failure, then try the iso2709, 
112             # (add authid & authtype if needed)
113             my $record;
114             eval {
115                 $record = GetAuthority($authid);
116             };
117             next unless $record;
118             # force authid in case it's not here, otherwise, zebra will die on this authority
119             unless ($record->field('001')->data() eq $authid){
120                 print "$authid don't exist for this authority :".$record->as_formatted;
121                 $record->delete_field($record->field('001'));
122                 $record->insert_fields_ordered(MARC::Field->new('001',$authid));
123             }
124             if($@){
125                 print "  There was some pb getting authority : ".$authid."\n";
126             next;
127             }
128         
129             print ".";
130             print "\r$i" unless ($i++ %100);
131 #            # remove leader length, that could be wrong, it will be calculated automatically by as_usmarc
132 #            # otherwise, if it's wron, zebra will fail miserabily (and never index what is after the failing record)
133             my $leader=$record->leader;
134             substr($leader,0,5)='     ';
135             substr($leader,10,7)='22     ';
136             $record->leader(substr($leader,0,24));
137             print OUT $record->as_usmarc;
138         }
139         close(OUT);
140     }
141     
142     #
143     # and reindexing everything
144     #
145     print "====================\n";
146     print "REINDEXING zebra\n";
147     print "====================\n";
148     system("zebraidx -c ".C4::Context->zebraconfig('authorityserver')->{config}." -g iso2709 -d authorities init") if ($reset);
149     system("zebraidx -c ".C4::Context->zebraconfig('authorityserver')->{config}." $noshadow -g iso2709 -d authorities update $directory/authorities");
150     system("zebraidx -c ".C4::Context->zebraconfig('authorityserver')->{config}." -g iso2709 -d authorities commit") unless $noshadow;
151 } else {
152     print "skipping authorities\n";
153 }
154 #################################################################################################################
155 #                        BIBLIOS 
156 #################################################################################################################
157
158 if ($biblios) {
159     # die;
160     #
161     # exporting biblios
162     #
163     if ($skip_export) {
164         print "====================\n";
165         print "SKIPPING biblio export\n";
166         print "====================\n";
167     } else {
168         print "====================\n";
169         print "exporting biblios\n";
170         print "====================\n";
171         mkdir "$directory" unless (-d $directory);
172         mkdir "$directory/biblios" unless (-d "$directory/biblios");
173         open(OUT,">:utf8 ","$directory/biblios/export") or die $!;
174                 my $dbh=C4::Context->dbh;
175         my $sth;
176     if ($noxml){
177         $sth=$dbh->prepare("select biblionumber,marc from biblioitems order by biblionumber $limit");
178         $sth->execute();
179         my $i=0;
180         while (my ($biblionumber,$marc) = $sth->fetchrow) {
181             my $record;
182             $record=MARC::Record->new_from_usmarc($marc);
183             my $record_correct=1;
184             # skip uncorrect records : isn't this bogus, as just after we reintroduce biblionumber if it's missing ?
185             # FIXME next unless $record->field($biblionumbertagfield);
186             # check if biblionumber is present, otherwise, add it on the fly
187             if ($biblionumbertagfield eq '001') {
188                 unless ($record->field($biblionumbertagfield)->data()) {
189                     $record_correct=0;
190                     my $field;
191                     # if the field where biblionumber is already exist, just update it, otherwise create it
192                 if ($record->field($biblionumbertagfield)) {
193                 $field =  $record->field($biblionumbertagfield);
194                 $field->update($biblionumber);
195                 } else {
196                 my $newfield;
197                 $newfield = MARC::Field->new( $biblionumbertagfield, $biblionumber);
198                 $record->append_fields($newfield);
199                 }
200             }
201             } else {
202             unless ($record->subfield($biblionumbertagfield,$biblionumbertagsubfield)) {
203                 $record_correct=0;
204                 my $field;
205                 # if the field where biblionumber is already exist, just update it, otherwise create it
206                 if ($record->field($biblionumbertagfield)) {
207                 $field =  $record->field($biblionumbertagfield);
208                 $field->add_subfields($biblionumbertagsubfield => $biblionumber);
209                 } else {
210                 my $newfield;
211                 $newfield = MARC::Field->new( $biblionumbertagfield,'','', $biblionumbertagsubfield => $biblionumber);
212                 $record->append_fields($newfield);
213                 }
214             }
215     #             warn "FIXED BIBLIONUMBER".$record->as_formatted;
216             }
217             unless ($record->subfield($biblioitemnumbertagfield,$biblioitemnumbertagsubfield)) {
218                 $record_correct=0;
219             #             warn "INCORRECT BIBLIOITEMNUMBER :".$record->as_formatted;
220             my $field;
221                 # if the field where biblionumber is already exist, just update it, otherwise create it
222                 if ($record->field($biblioitemnumbertagfield)) {
223                     $field =  $record->field($biblioitemnumbertagfield);
224                     if ($biblioitemnumbertagfield <10) {
225                     $field->update($biblionumber);
226                     } else {
227                     $field->add_subfields($biblioitemnumbertagsubfield => $biblionumber);
228                     }
229                 } else {
230                     my $newfield;
231                     if ($biblioitemnumbertagfield <10) {
232                     $newfield = MARC::Field->new( $biblioitemnumbertagfield, $biblionumber);
233                     } else {
234                     $newfield = MARC::Field->new( $biblioitemnumbertagfield,'','', $biblioitemnumbertagsubfield => $biblionumber);
235                     }
236                     $record->insert_grouped_field($newfield);
237             }
238         #             warn "FIXED BIBLIOITEMNUMBER".$record->as_formatted;
239             }
240             my $leader=$record->leader;
241             substr($leader,0,5)='     ';
242             substr($leader,10,7)='22     ';
243             $record->leader(substr($leader,0,24));
244                 print OUT $record->as_usmarc();
245         }
246         close (OUT);
247     } else {
248         $sth=$dbh->prepare("SELECT biblionumber FROM biblioitems ORDER BY biblionumber $limit");
249         $sth->execute();
250         my $i=0;
251         while (my ($biblionumber) = $sth->fetchrow) {
252             print ".";
253             print "\r$i" unless ($i++ %100);
254             my $record;
255             eval {
256                 $record = GetMarcBiblio($biblionumber);
257             };
258             if($@){
259                 print "  There was some pb getting biblio : #".$biblionumber."\n";
260                 next;
261             }
262             next unless $record;
263 # die if $record->subfield('090','9') eq 11;
264     #         print $record;
265             # check that biblionumber & biblioitemnumber are stored in the MARC record, otherwise, add them & update the biblioitems.marcxml data.
266             my $record_correct=1;
267             # skip uncorrect records : isn't this bogus, as just after we reintroduce biblionumber if it's missing ?
268             # FIXME next unless $record->field($biblionumbertagfield);
269             #
270             #
271             # CHECK  biblionumber
272             #
273             #
274         if ($biblionumbertagfield eq '001') {
275                 unless ($record->field($biblionumbertagfield) && $record->field($biblionumbertagfield)->data()) {
276                     $record_correct=0;
277                     my $field;
278                     # if the field where biblionumber is already exist, just update it, otherwise create it
279                     if ($record->field($biblionumbertagfield)) {
280                         $field =  $record->field($biblionumbertagfield);
281                         $field->update($biblionumber);
282                     } else {
283                         my $newfield;
284                         $newfield = MARC::Field->new( $biblionumbertagfield, $biblionumber);
285                         $record->append_fields($newfield);
286                     }
287                 }
288             } else {
289                 unless ($record->subfield($biblionumbertagfield,$biblionumbertagsubfield)) {
290 #                 warn "fixing biblionumber for $biblionumbertagfield,$biblionumbertagsubfield = $biblionumber";
291                     $record_correct=0;
292                     my $field;
293                     # if the field where biblionumber is already exist, just update it, otherwise create it
294                     if ($record->field($biblionumbertagfield)) {
295                         $field =  $record->field($biblionumbertagfield);
296                         $field->add_subfields($biblionumbertagsubfield => $biblionumber);
297                     } else {
298                         my $newfield;
299                         $newfield = MARC::Field->new( $biblionumbertagfield,'','', $biblionumbertagsubfield => $biblionumber);
300                         $record->append_fields($newfield);
301                     }
302                 }
303 #                 warn "FIXED BIBLIONUMBER".$record->as_formatted;
304             }
305             #
306             #
307             # CHECK BIBLIOITEMNUMBER
308             #
309             #
310             unless ($record->subfield($biblioitemnumbertagfield,$biblioitemnumbertagsubfield)) {
311 #                 warn "fixing biblioitemnumber for $biblioitemnumbertagfield,$biblioitemnumbertagsubfield = $biblionumber";
312                 $record_correct=0;
313                 my $field;
314                 # if the field where biblionumber is already exist, just update it, otherwise create it
315                 if ($record->field($biblioitemnumbertagfield)) {
316                     $field =  $record->field($biblioitemnumbertagfield);
317                     if ($biblioitemnumbertagfield <10) {
318                         $field->update($biblionumber);
319                     } else {
320                         $field->add_subfields($biblioitemnumbertagsubfield => $biblionumber);
321                     }
322                 } else {
323                     my $newfield;
324                     if ($biblioitemnumbertagfield <10) {
325                         $newfield = MARC::Field->new( $biblioitemnumbertagfield, $biblionumber);
326                     } else {
327                         $newfield = MARC::Field->new( $biblioitemnumbertagfield,'','', $biblioitemnumbertagsubfield => $biblionumber);
328                     }
329                     $record->insert_grouped_field($newfield);
330                 }
331     #             warn "FIXED BIBLIOITEMNUMBER".$record->as_formatted;
332             }
333             #
334             #
335             # CHECK FIELD 100
336             #
337             #
338             my $encoding = C4::Context->preference("marcflavour");
339             # deal with UNIMARC field 100 (encoding) : create it if needed & set encoding to unicode
340                         if ( $encoding eq "UNIMARC" ) {
341                 my $string;
342                 if ( length($record->subfield( 100, "a" )) == 35 ) {
343                     $string = $record->subfield( 100, "a" );
344                     my $f100 = $record->field(100);
345                     $record->delete_field($f100);
346                 }
347                 else {
348                     $string = POSIX::strftime( "%Y%m%d", localtime );
349                     $string =~ s/\-//g;
350                     $string = sprintf( "%-*s", 35, $string );
351                 }
352                 substr( $string, 22, 6, "frey50" );
353                 unless ( length($record->subfield( 100, "a" )) == 35 ) {
354                     $record->delete_field($record->field(100));
355                     $record->insert_grouped_field(
356                         MARC::Field->new( 100, "", "", "a" => $string ) );
357                 }
358             }
359             unless ($record_correct) {
360                 my $update_xml = $dbh->prepare("update biblioitems set marcxml=? where biblionumber=?");
361                 warn "UPDATING $biblionumber (missing biblionumber or biblioitemnumber in MARC record : ".$record->as_xml;
362                 $update_xml->execute($record->as_xml,$biblionumber);
363             }
364             # remove leader length, that could be wrong, it will be calculated automatically by as_usmarc
365             # otherwise, if it's wron, zebra will fail miserabily (and never index what is after the failing record)
366             my $leader=$record->leader;
367             substr($leader,0,5)='     ';
368             substr($leader,10,7)='22     ';
369             $record->leader(substr($leader,0,24));
370                         if($as_xml) {
371                                 print OUT $record->as_xml_record();
372                                 } else {
373                                 print OUT $record->as_usmarc();
374                         }
375                         }
376                 }
377         close(OUT);
378     }
379     
380     #
381     # and reindexing everything
382     #
383         print "====================\n";
384     print "REINDEXING zebra\n";
385     print "====================\n";
386         my $record_fmt = ($as_xml) ? 'marcxml' : 'iso2709' ;
387     system("zebraidx -g $record_fmt -c ".C4::Context->zebraconfig('biblioserver')->{config}." -d biblios init") if ($reset);
388     system("zebraidx -g $record_fmt -c ".C4::Context->zebraconfig('biblioserver')->{config}." $noshadow -d biblios update $directory/biblios");
389     system("zebraidx -g $record_fmt -c ".C4::Context->zebraconfig('biblioserver')->{config}." -d biblios commit") unless $noshadow;
390 } else {
391     print "skipping biblios\n";
392 }
393
394 print "====================\n";
395 print "CLEANING\n";
396 print "====================\n";
397 if ($keep_export) {
398     print "NOTHING cleaned : the export $directory has been kept.\n";
399     print "You can re-run this script with the -s ";
400     if ($use_tempdir) {
401         print " and -d $directory parameters";
402     } else {
403         print "parameter";
404     }
405     print "\n";
406     print "if you just want to rebuild zebra after changing the record.abs\n";
407     print "or another zebra config file\n";
408 } else {
409     unless ($use_tempdir) {
410         # if we're using a temporary directory
411         # created by File::Temp, it will be removed
412         # automatically.
413         rmtree($directory, 0, 1);
414         print "directory $directory deleted\n";
415     }
416 }
417
418 sub print_usage {
419     print <<_USAGE_;
420 $0: reindex MARC bibs and/or authorities in Zebra.
421
422 Use this batch job to reindex all biblio or authority
423 records in your Koha database.  This job is useful
424 only if you are using Zebra; if you are using the 'NoZebra'
425 mode, this job should not be used.
426
427 Parameters:
428     -b                      index bibliographic records
429
430     -a                      index authority records
431
432     -r                      clear Zebra index before
433                             adding records to index
434
435     -d                      Temporary directory for indexing.
436                             If not specified, one is automatically
437                             created.  The export directory
438                             is automatically deleted unless
439                             you supply the -k switch.
440
441     -k                      Do not delete export directory.
442
443     -s                      Skip export.  Used if you have
444                             already exported the records 
445                             in a previous run.
446
447     -noxml                  index from ISO MARC blob
448                             instead of MARC XML.  This
449                             option is recommended only
450                             for advanced user.
451
452     -x                      export and index as xml instead of is02709 (biblios only).
453                             use this if you might have records > 99,999 chars,
454                                                         
455     -w                      skip shadow indexing for this batch
456
457     -munge-config           Deprecated option to try
458                             to fix Zebra config files.
459     --help or -h            show this message.
460 _USAGE_
461 }
462
463 # FIXME: the following routines are deprecated and 
464 # will be removed once it is determined whether
465 # a script to fix Zebra configuration files is 
466 # actually needed.
467 sub munge_config {
468 #
469 # creating zebra-biblios.cfg depending on system
470 #
471
472 # getting zebraidx directory
473 my $zebraidxdir;
474 foreach (qw(/usr/local/bin/zebraidx
475         /opt/bin/zebraidx
476         /usr/bin/zebraidx
477         )) {
478     if ( -f $_ ) {
479         $zebraidxdir=$_;
480     }
481 }
482
483 unless ($zebraidxdir) {
484     print qq|
485     ERROR: could not find zebraidx directory
486     ERROR: Either zebra is not installed,
487     ERROR: or it's in a directory I don't checked.
488     ERROR: do a which zebraidx and edit this file to add the result you get
489 |;
490     exit;
491 }
492 $zebraidxdir =~ s/\/bin\/.*//;
493 print "Info : zebra is in $zebraidxdir \n";
494
495 # getting modules directory
496 my $modulesdir;
497 foreach (qw(/usr/local/lib/idzebra-2.0/modules/mod-grs-xml.so
498             /usr/local/lib/idzebra/modules/mod-grs-xml.so
499             /usr/lib/idzebra/modules/mod-grs-xml.so
500             /usr/lib/idzebra-2.0/modules/mod-grs-xml.so
501         )) {
502     if ( -f $_ ) {
503         $modulesdir=$_;
504     }
505 }
506
507 unless ($modulesdir) {
508     print qq|
509     ERROR: could not find mod-grs-xml.so directory
510     ERROR: Either zebra is not properly compiled (libxml2 is not setup and you don t have mod-grs-xml.so,
511     ERROR: or it's in a directory I don't checked.
512     ERROR: find where mod-grs-xml.so is and edit this file to add the result you get
513 |;
514     exit;
515 }
516 $modulesdir =~ s/\/modules\/.*//;
517 print "Info: zebra modules dir : $modulesdir\n";
518
519 # getting tab directory
520 my $tabdir;
521 foreach (qw(/usr/local/share/idzebra/tab/explain.att
522             /usr/local/share/idzebra-2.0/tab/explain.att
523             /usr/share/idzebra/tab/explain.att
524             /usr/share/idzebra-2.0/tab/explain.att
525         )) {
526     if ( -f $_ ) {
527         $tabdir=$_;
528     }
529 }
530
531 unless ($tabdir) {
532     print qq|
533     ERROR: could not find explain.att directory
534     ERROR: Either zebra is not properly compiled,
535     ERROR: or it's in a directory I don't checked.
536     ERROR: find where explain.att is and edit this file to add the result you get
537 |;
538     exit;
539 }
540 $tabdir =~ s/\/tab\/.*//;
541 print "Info: tab dir : $tabdir\n";
542
543 #
544 # AUTHORITIES creating directory structure
545 #
546 my $created_dir_or_file = 0;
547 if ($authorities) {
548     print "====================\n";
549     print "checking directories & files for authorities\n";
550     print "====================\n";
551     unless (-d "$authorityserverdir") {
552         system("mkdir -p $authorityserverdir");
553         print "Info: created $authorityserverdir\n";
554         $created_dir_or_file++;
555     }
556     unless (-d "$authorityserverdir/lock") {
557         mkdir "$authorityserverdir/lock";
558         print "Info: created $authorityserverdir/lock\n";
559         $created_dir_or_file++;
560     }
561     unless (-d "$authorityserverdir/register") {
562         mkdir "$authorityserverdir/register";
563         print "Info: created $authorityserverdir/register\n";
564         $created_dir_or_file++;
565     }
566     unless (-d "$authorityserverdir/shadow") {
567         mkdir "$authorityserverdir/shadow";
568         print "Info: created $authorityserverdir/shadow\n";
569         $created_dir_or_file++;
570     }
571     unless (-d "$authorityserverdir/tab") {
572         mkdir "$authorityserverdir/tab";
573         print "Info: created $authorityserverdir/tab\n";
574         $created_dir_or_file++;
575     }
576     unless (-d "$authorityserverdir/key") {
577         mkdir "$authorityserverdir/key";
578         print "Info: created $authorityserverdir/key\n";
579         $created_dir_or_file++;
580     }
581     
582     unless (-d "$authorityserverdir/etc") {
583         mkdir "$authorityserverdir/etc";
584         print "Info: created $authorityserverdir/etc\n";
585         $created_dir_or_file++;
586     }
587     
588     #
589     # AUTHORITIES : copying mandatory files
590     #
591     # the record model, depending on marc flavour
592     unless (-f "$authorityserverdir/tab/record.abs") {
593         if (C4::Context->preference("marcflavour") eq "UNIMARC") {
594             system("cp -f $kohadir/etc/zebradb/marc_defs/unimarc/authorities/record.abs $authorityserverdir/tab/record.abs");
595             print "Info: copied record.abs for UNIMARC\n";
596         } else {
597             system("cp -f $kohadir/etc/zebradb/marc_defs/marc21/authorities/record.abs $authorityserverdir/tab/record.abs");
598             print "Info: copied record.abs for USMARC\n";
599         }
600         $created_dir_or_file++;
601     }
602     unless (-f "$authorityserverdir/tab/sort-string-utf.chr") {
603         system("cp -f $kohadir/etc/zebradb/lang_defs/fr/sort-string-utf.chr $authorityserverdir/tab/sort-string-utf.chr");
604         print "Info: copied sort-string-utf.chr\n";
605         $created_dir_or_file++;
606     }
607     unless (-f "$authorityserverdir/tab/word-phrase-utf.chr") {
608         system("cp -f $kohadir/etc/zebradb/lang_defs/fr/sort-string-utf.chr $authorityserverdir/tab/word-phrase-utf.chr");
609         print "Info: copied word-phase-utf.chr\n";
610         $created_dir_or_file++;
611     }
612     unless (-f "$authorityserverdir/tab/auth1.att") {
613         system("cp -f $kohadir/etc/zebradb/authorities/etc/bib1.att $authorityserverdir/tab/auth1.att");
614         print "Info: copied auth1.att\n";
615         $created_dir_or_file++;
616     }
617     unless (-f "$authorityserverdir/tab/default.idx") {
618         system("cp -f $kohadir/etc/zebradb/etc/default.idx $authorityserverdir/tab/default.idx");
619         print "Info: copied default.idx\n";
620         $created_dir_or_file++;
621     }
622     
623     unless (-f "$authorityserverdir/etc/ccl.properties") {
624 #         system("cp -f $kohadir/etc/zebradb/ccl.properties ".C4::Context->zebraconfig('authorityserver')->{ccl2rpn});
625         system("cp -f $kohadir/etc/zebradb/ccl.properties $authorityserverdir/etc/ccl.properties");
626         print "Info: copied ccl.properties\n";
627         $created_dir_or_file++;
628     }
629     unless (-f "$authorityserverdir/etc/pqf.properties") {
630 #         system("cp -f $kohadir/etc/zebradb/pqf.properties ".C4::Context->zebraconfig('authorityserver')->{ccl2rpn});
631         system("cp -f $kohadir/etc/zebradb/pqf.properties $authorityserverdir/etc/pqf.properties");
632         print "Info: copied pqf.properties\n";
633         $created_dir_or_file++;
634     }
635     
636     #
637     # AUTHORITIES : copying mandatory files
638     #
639     unless (-f C4::Context->zebraconfig('authorityserver')->{config}) {
640     open ZD,">:utf8 ",C4::Context->zebraconfig('authorityserver')->{config};
641     print ZD "
642 # generated by KOHA/misc/migration_tools/rebuild_zebra.pl 
643 profilePath:\${srcdir:-.}:$authorityserverdir/tab/:$tabdir/tab/:\${srcdir:-.}/tab/
644
645 encoding: UTF-8
646 # Files that describe the attribute sets supported.
647 attset: auth1.att
648 attset: explain.att
649 attset: gils.att
650
651 modulePath:$modulesdir/modules/
652 # Specify record type
653 iso2709.recordType:grs.marcxml.record
654 recordType:grs.xml
655 recordId: (auth1,Local-Number)
656 storeKeys:1
657 storeData:1
658
659
660 # Lock File Area
661 lockDir: $authorityserverdir/lock
662 perm.anonymous:r
663 perm.kohaadmin:rw
664 register: $authorityserverdir/register:4G
665 shadow: $authorityserverdir/shadow:4G
666
667 # Temp File area for result sets
668 setTmpDir: $authorityserverdir/tmp
669
670 # Temp File area for index program
671 keyTmpDir: $authorityserverdir/key
672
673 # Approx. Memory usage during indexing
674 memMax: 40M
675 rank:rank-1
676     ";
677         print "Info: creating zebra-authorities.cfg\n";
678         $created_dir_or_file++;
679     }
680     
681     if ($created_dir_or_file) {
682         print "Info: created : $created_dir_or_file directories & files\n";
683     } else {
684         print "Info: file & directories OK\n";
685     }
686     
687 }
688 if ($biblios) {
689     print "====================\n";
690     print "checking directories & files for biblios\n";
691     print "====================\n";
692     
693     #
694     # BIBLIOS : creating directory structure
695     #
696     unless (-d "$biblioserverdir") {
697         system("mkdir -p $biblioserverdir");
698         print "Info: created $biblioserverdir\n";
699         $created_dir_or_file++;
700     }
701     unless (-d "$biblioserverdir/lock") {
702         mkdir "$biblioserverdir/lock";
703         print "Info: created $biblioserverdir/lock\n";
704         $created_dir_or_file++;
705     }
706     unless (-d "$biblioserverdir/register") {
707         mkdir "$biblioserverdir/register";
708         print "Info: created $biblioserverdir/register\n";
709         $created_dir_or_file++;
710     }
711     unless (-d "$biblioserverdir/shadow") {
712         mkdir "$biblioserverdir/shadow";
713         print "Info: created $biblioserverdir/shadow\n";
714         $created_dir_or_file++;
715     }
716     unless (-d "$biblioserverdir/tab") {
717         mkdir "$biblioserverdir/tab";
718         print "Info: created $biblioserverdir/tab\n";
719         $created_dir_or_file++;
720     }
721     unless (-d "$biblioserverdir/key") {
722         mkdir "$biblioserverdir/key";
723         print "Info: created $biblioserverdir/key\n";
724         $created_dir_or_file++;
725     }
726     unless (-d "$biblioserverdir/etc") {
727         mkdir "$biblioserverdir/etc";
728         print "Info: created $biblioserverdir/etc\n";
729         $created_dir_or_file++;
730     }
731     
732     #
733     # BIBLIOS : copying mandatory files
734     #
735     # the record model, depending on marc flavour
736     unless (-f "$biblioserverdir/tab/record.abs") {
737         if (C4::Context->preference("marcflavour") eq "UNIMARC") {
738             system("cp -f $kohadir/etc/zebradb/marc_defs/unimarc/biblios/record.abs $biblioserverdir/tab/record.abs");
739             print "Info: copied record.abs for UNIMARC\n";
740         } else {
741             system("cp -f $kohadir/etc/zebradb/marc_defs/marc21/biblios/record.abs $biblioserverdir/tab/record.abs");
742             print "Info: copied record.abs for USMARC\n";
743         }
744         $created_dir_or_file++;
745     }
746     unless (-f "$biblioserverdir/tab/sort-string-utf.chr") {
747         system("cp -f $kohadir/etc/zebradb/lang_defs/fr/sort-string-utf.chr $biblioserverdir/tab/sort-string-utf.chr");
748         print "Info: copied sort-string-utf.chr\n";
749         $created_dir_or_file++;
750     }
751     unless (-f "$biblioserverdir/tab/word-phrase-utf.chr") {
752         system("cp -f $kohadir/etc/zebradb/lang_defs/fr/sort-string-utf.chr $biblioserverdir/tab/word-phrase-utf.chr");
753         print "Info: copied word-phase-utf.chr\n";
754         $created_dir_or_file++;
755     }
756     unless (-f "$biblioserverdir/tab/bib1.att") {
757         system("cp -f $kohadir/etc/zebradb/biblios/etc/bib1.att $biblioserverdir/tab/bib1.att");
758         print "Info: copied bib1.att\n";
759         $created_dir_or_file++;
760     }
761     unless (-f "$biblioserverdir/tab/default.idx") {
762         system("cp -f $kohadir/etc/zebradb/etc/default.idx $biblioserverdir/tab/default.idx");
763         print "Info: copied default.idx\n";
764         $created_dir_or_file++;
765     }
766     unless (-f "$biblioserverdir/etc/ccl.properties") {
767 #         system("cp -f $kohadir/etc/zebradb/ccl.properties ".C4::Context->zebraconfig('biblioserver')->{ccl2rpn});
768         system("cp -f $kohadir/etc/zebradb/ccl.properties $biblioserverdir/etc/ccl.properties");
769         print "Info: copied ccl.properties\n";
770         $created_dir_or_file++;
771     }
772     unless (-f "$biblioserverdir/etc/pqf.properties") {
773 #         system("cp -f $kohadir/etc/zebradb/pqf.properties ".C4::Context->zebraconfig('biblioserver')->{ccl2rpn});
774         system("cp -f $kohadir/etc/zebradb/pqf.properties $biblioserverdir/etc/pqf.properties");
775         print "Info: copied pqf.properties\n";
776         $created_dir_or_file++;
777     }
778     
779     #
780     # BIBLIOS : copying mandatory files
781     #
782     unless (-f C4::Context->zebraconfig('biblioserver')->{config}) {
783     open ZD,">:utf8 ",C4::Context->zebraconfig('biblioserver')->{config};
784     print ZD "
785 # generated by KOHA/misc/migrtion_tools/rebuild_zebra.pl 
786 profilePath:\${srcdir:-.}:$biblioserverdir/tab/:$tabdir/tab/:\${srcdir:-.}/tab/
787
788 encoding: UTF-8
789 # Files that describe the attribute sets supported.
790 attset:bib1.att
791 attset:explain.att
792 attset:gils.att
793
794 modulePath:$modulesdir/modules/
795 # Specify record type
796 iso2709.recordType:grs.marcxml.record
797 recordType:grs.xml
798 recordId: (bib1,Local-Number)
799 storeKeys:1
800 storeData:1
801
802
803 # Lock File Area
804 lockDir: $biblioserverdir/lock
805 perm.anonymous:r
806 perm.kohaadmin:rw
807 register: $biblioserverdir/register:4G
808 shadow: $biblioserverdir/shadow:4G
809
810 # Temp File area for result sets
811 setTmpDir: $biblioserverdir/tmp
812
813 # Temp File area for index program
814 keyTmpDir: $biblioserverdir/key
815
816 # Approx. Memory usage during indexing
817 memMax: 40M
818 rank:rank-1
819     ";
820         print "Info: creating zebra-biblios.cfg\n";
821         $created_dir_or_file++;
822     }
823     
824     if ($created_dir_or_file) {
825         print "Info: created : $created_dir_or_file directories & files\n";
826     } else {
827         print "Info: file & directories OK\n";
828     }
829     
830 }
831 }