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