Bug 9259: Use is instead of is_deeply
[koha.git] / t / db_dependent / zebra_config.pl
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4
5 use File::Copy;
6 use File::Path qw(make_path);
7 use File::Find;
8 use File::Basename;
9 use File::Spec;
10
11 use C4::Context;
12
13 my $source = File::Spec->rel2abs('.');
14 my $destination = $ARGV[0];
15 my $marc_type = $ARGV[1] || 'marc21';
16 my $indexing_mode = $ARGV[2] || 'dom';
17
18 $ENV{__BIB_INDEX_MODE__} = $indexing_mode;
19 $ENV{__AUTH_INDEX_MODE__} = $indexing_mode;
20
21 $ENV{__ZEBRA_MARC_FORMAT__} = $marc_type;
22 if ($indexing_mode eq 'dom') {
23     $ENV{__ZEBRA_BIB_CFG__} = 'zebra-biblios-dom.cfg';
24     $ENV{__BIB_RETRIEVAL_CFG__} = 'retrieval-info-bib-dom.xml';
25     $ENV{__ZEBRA_AUTH_CFG__} = 'zebra-authorities-dom.cfg';
26     $ENV{__AUTH_RETRIEVAL_CFG__} = 'retrieval-info-auth-dom.xml';
27 } else {
28     $ENV{__ZEBRA_BIB_CFG__} = 'zebra-biblios.cfg';
29     $ENV{__BIB_RETRIEVAL_CFG__} = 'retrieval-info-bib-grs1.xml';
30     $ENV{__ZEBRA_AUTH_CFG__} = 'zebra-authorities.cfg';
31     $ENV{__AUTH_RETRIEVAL_CFG__} = 'retrieval-info-auth-grs1.xml';
32 }
33
34 make_path("$destination/var/lock/zebradb");
35 make_path("$destination/var/lock/zebradb/biblios");
36 make_path("$destination/var/lock/zebradb/authorities");
37 make_path("$destination/var/lock/zebradb/rebuild");
38 make_path("$destination/var/lib/zebradb");
39 make_path("$destination/var/lib/zebradb/biblios");
40 make_path("$destination/var/lib/zebradb/biblios/key");
41 make_path("$destination/var/lib/zebradb/biblios/register");
42 make_path("$destination/var/lib/zebradb/biblios/shadow");
43 make_path("$destination/var/lib/zebradb/biblios/tmp");
44 make_path("$destination/var/lib/zebradb/authorities");
45 make_path("$destination/var/lib/zebradb/authorities/key");
46 make_path("$destination/var/lib/zebradb/authorities/register");
47 make_path("$destination/var/lib/zebradb/authorities/shadow");
48 make_path("$destination/var/lib/zebradb/authorities/tmp");
49 make_path("$destination/var/run/zebradb");
50
51 $ENV{'INSTALL_BASE'} = $destination;
52 $ENV{'__INSTALL_BASE__'} = $destination;
53
54 $ENV{'__DB_TYPE__'} = C4::Context->config('db_scheme') // 'mysql';
55 $ENV{'__DB_NAME__'} = C4::Context->config('database')  // 'koha';
56 $ENV{'__DB_HOST__'} = C4::Context->config('hostname')  // 'localhost';
57 $ENV{'__DB_PORT__'} = C4::Context->config('port')      // '3306';
58 $ENV{'__DB_USER__'} = C4::Context->config('user')      // 'kohaadmin';
59 $ENV{'__DB_PASS__'} = C4::Context->config('pass')      // 'katikoan';
60
61 my @files = ( "$source/etc/koha-conf.xml",
62               "$source/etc/searchengine/queryparser.yaml",
63             );
64
65 find(sub { push @files, $File::Find::name if ( -f $File::Find::name ); }, "$source/etc/zebradb");
66
67 foreach my $file (@files) {
68     my $target = "$file";
69     $target =~ s#$source#$destination#;
70     $target =~ s#etc/zebradb#etc/koha/zebradb#;
71     unlink($target);
72     make_path(dirname($target));
73     copy("$file", "$target");
74     system("perl $source/rewrite-config.PL $target");
75     if ($file =~ m/xml/) {
76         replace("$target", "$destination/intranet/templates", "$source/koha-tmpl/intranet-tmpl");
77     }
78 }
79
80
81 sub replace {
82     my ($file, $pattern, $replacement) = @_;
83     system("sed -i -e 's#$pattern#$replacement#' $file");
84 }