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