8 # script that checks zebradir structure & create directories & mandatory files if needed
12 $|=1; # flushes output
14 print "Zebra directory =>".C4::Context->zebraconfig('biblioserver')->{directory}."\n";
15 print "Koha directory =>".C4::Context->config('intranetdir')."\n";
17 my $zebradir = C4::Context->zebraconfig('biblioserver')->{directory};
18 my $kohadir = C4::Context->config('intranetdir');
28 $directory = "export" unless $directory;
30 my $created_dir_or_file = 0;
31 print "====================\n";
32 print "checking directories & files\n";
33 print "====================\n";
34 unless (-d "$zebradir") {
35 system("mkdir -p $zebradir");
36 print "created $zebradir\n";
37 $created_dir_or_file++;
39 unless (-d "$zebradir/lock") {
40 mkdir "$zebradir/lock";
41 print "created $zebradir/lock\n";
42 $created_dir_or_file++;
44 unless (-d "$zebradir/register") {
45 mkdir "$zebradir/register";
46 print "created $zebradir/register\n";
47 $created_dir_or_file++;
49 unless (-d "$zebradir/shadow") {
50 mkdir "$zebradir/shadow";
51 print "created $zebradir/shadow\n";
52 $created_dir_or_file++;
54 unless (-d "$zebradir/tab") {
55 mkdir "$zebradir/tab";
56 print "created $zebradir/tab\n";
57 $created_dir_or_file++;
60 unless (-d "$zebradir/etc") {
61 mkdir "$zebradir/etc";
62 print "created $zebradir/etc\n";
63 $created_dir_or_file++;
66 unless (-f "$zebradir/tab/record.abs") {
67 system("cp -f $kohadir/zebraplugin/zebradb/biblios/tab/record_for_unimarc.abs $zebradir/tab/record.abs");
68 print "copied record.abs\n";
69 $created_dir_or_file++;
71 unless (-f "$zebradir/tab/sort-string-utf.chr") {
72 system("cp -f $kohadir/zebraplugin/zebradb/biblios/tab/sort-string-utf.chr $zebradir/tab/sort-string-utf.chr");
73 print "copied sort-string-utf.chr\n";
74 $created_dir_or_file++;
76 unless (-f "$zebradir/tab/word-phrase-utf.chr") {
77 system("cp -f $kohadir/zebraplugin/zebradb/biblios/tab/word-phrase-utf.chr $zebradir/tab/word-phrase-utf.chr");
78 print "copied word-phase-utf.chr\n";
79 $created_dir_or_file++;
81 unless (-f "$zebradir/tab/bib1.att") {
82 system("cp -f $kohadir/zebraplugin/zebradb/biblios/tab/bib1.att $zebradir/tab/bib1.att");
83 print "copied bib1.att\n";
84 $created_dir_or_file++;
87 unless (-f "$zebradir/etc/zebra-biblios.cfg") {
88 system("cp -f $kohadir/zebraplugin/etc/zebra-biblios.cfg $zebradir/etc/zebra-biblios.cfg");
89 print "copied zebra-biblios.cfg\n";
90 $created_dir_or_file++;
92 unless (-f "$zebradir/etc/ccl.properties") {
93 system("cp -f $kohadir/zebraplugin/etc/ccl.properties $zebradir/etc/ccl.properties");
94 print "copied ccl.properties\n";
95 $created_dir_or_file++;
97 unless (-f "$zebradir/etc/pqf.properties") {
98 system("cp -f $kohadir/zebraplugin/etc/pqf.properties $zebradir/etc/pqf.properties");
99 print "copied pqf.properties\n";
100 $created_dir_or_file++;
103 if ($created_dir_or_file) {
104 print "created : $created_dir_or_file directories & files\n";
106 print "file & directories OK\n";
110 print "====================\n";
111 print "SKIPPING biblio export\n";
112 print "====================\n";
114 print "====================\n";
115 print "exporting biblios\n";
116 print "====================\n";
117 mkdir "$directory" unless (-d $directory);
118 open(OUT,">:utf8","$directory/export") or die $!;
119 my $dbh=C4::Context->dbh;
121 $sth=$dbh->prepare("select biblionumber from biblioitems order by biblionumber");
124 while (my ($biblionumber) = $sth->fetchrow) {
125 my $record = MARCgetbiblio($dbh,$biblionumber);
127 print "\r$i" unless ($i++ %100);
128 print OUT $record->as_usmarc();
133 print "====================\n";
134 print "REINDEXING zebra\n";
135 print "====================\n";
136 system("zebraidx -g iso2709 -c $zebradir/etc/zebra-biblios.cfg -d biblios update $directory");
137 system("zebraidx -g iso2709 -c $zebradir/etc/zebra-biblios.cfg -d biblios commit");
139 print "====================\n";
141 print "====================\n";
143 print "NOTHING cleaned : the $directory has been kept. You can re-run this script with the -s parameter if you just want to rebuild zebra after changing the record.abs or another zebra config file\n";
145 system("rm -rf $zebradir");
146 print "directory $zebradir deleted\n";