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