improvements to the language of the installer
[koha.git] / misc / migration_tools / check_dirs.pl
1 #!/usr/bin/perl
2
3 use C4::Context;
4 use Getopt::Long;
5 use C4::Biblio;
6
7
8 # script that checks zebradir structure & create directories & mandatory files if needed
9 #
10 #
11
12 $|=1; # flushes output
13
14 print "Zebra directory =>".C4::Context->zebraconfig('biblioserver')->{directory}."\n";
15 print "Koha directory =>".C4::Context->config('intranetdir')."\n";
16
17 my $zebradir = C4::Context->zebraconfig('biblioserver')->{directory};
18 my $kohadir = C4::Context->config('intranetdir');
19 my $directory;
20 my $skip_export;
21 my $keep_export;
22 GetOptions(
23         'd:s'      => \$directory,
24         's'        => \$skip_export,
25         'k'        => \$keep_export,
26         );
27
28 $directory = "export" unless $directory;
29
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++;
38 }
39 unless (-d "$zebradir/lock") {
40     mkdir "$zebradir/lock";
41     print "created $zebradir/lock\n";
42     $created_dir_or_file++;
43 }
44 unless (-d "$zebradir/register") {
45     mkdir "$zebradir/register";
46     print "created $zebradir/register\n";
47     $created_dir_or_file++;
48 }
49 unless (-d "$zebradir/shadow") {
50     mkdir "$zebradir/shadow";
51     print "created $zebradir/shadow\n";
52     $created_dir_or_file++;
53 }
54 unless (-d "$zebradir/tab") {
55     mkdir "$zebradir/tab";
56     print "created $zebradir/tab\n";
57     $created_dir_or_file++;
58 }
59
60 unless (-d "$zebradir/etc") {
61     mkdir "$zebradir/etc";
62     print "created $zebradir/etc\n";
63     $created_dir_or_file++;
64 }
65
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++;
70 }
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++;
75 }
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++;
80 }
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++;
85 }
86
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++;
91 }
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++;
96 }
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++;
101 }
102
103 if ($created_dir_or_file) {
104     print "created : $created_dir_or_file directories & files\n";
105 } else {
106     print "file & directories OK\n";
107 }
108
109 if ($skip_export) {
110     print "====================\n";
111     print "SKIPPING biblio export\n";
112     print "====================\n";
113 } else {
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;
120     my $sth;
121     $sth=$dbh->prepare("select biblionumber from biblioitems order by biblionumber");
122     $sth->execute();
123     my $i=0;
124     while (my ($biblionumber) = $sth->fetchrow) {
125         my $record = MARCgetbiblio($dbh,$biblionumber);
126         print ".";
127         print "\r$i" unless ($i++ %100);
128         print OUT $record->as_usmarc();
129     }
130     close(OUT);
131 }
132
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");
138
139 print "====================\n";
140 print "CLEANING\n";
141 print "====================\n";
142 if ($k) {
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";
144 } else {
145     system("rm -rf $zebradir");
146     print "directory $zebradir deleted\n";
147 }
148 }