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