Bug 21722: Tidy up tests and increase coverage
[koha.git] / t / db_dependent / zebra_config.pl
bloba8a2ccbeb4536f7917ca52d963daa84902338d09
1 #!/usr/bin/perl
3 use Modern::Perl;
5 use File::Copy;
6 use File::Path qw(make_path);
7 use File::Find;
8 use File::Basename;
9 use File::Spec;
11 use C4::Context;
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';
18 $ENV{__ZEBRA_MARC_FORMAT__} = $marc_type;
19 $ENV{__ZEBRA_BIB_CFG__} = 'zebra-biblios-dom.cfg';
20 $ENV{__BIB_RETRIEVAL_CFG__} = 'retrieval-info-bib-dom.xml';
21 $ENV{__ZEBRA_AUTH_CFG__} = 'zebra-authorities-dom.cfg';
22 $ENV{__AUTH_RETRIEVAL_CFG__} = 'retrieval-info-auth-dom.xml';
24 make_path("$destination/var/lock/zebradb");
25 make_path("$destination/var/lock/zebradb/biblios");
26 make_path("$destination/var/lock/zebradb/authorities");
27 make_path("$destination/var/lock/zebradb/rebuild");
28 make_path("$destination/var/lib/zebradb");
29 make_path("$destination/var/lib/zebradb/biblios");
30 make_path("$destination/var/lib/zebradb/biblios/key");
31 make_path("$destination/var/lib/zebradb/biblios/register");
32 make_path("$destination/var/lib/zebradb/biblios/shadow");
33 make_path("$destination/var/lib/zebradb/biblios/tmp");
34 make_path("$destination/var/lib/zebradb/authorities");
35 make_path("$destination/var/lib/zebradb/authorities/key");
36 make_path("$destination/var/lib/zebradb/authorities/register");
37 make_path("$destination/var/lib/zebradb/authorities/shadow");
38 make_path("$destination/var/lib/zebradb/authorities/tmp");
39 make_path("$destination/var/run/zebradb");
41 $ENV{'INSTALL_BASE'} = $destination;
42 $ENV{'__INSTALL_BASE__'} = $destination;
44 $ENV{'__DB_TYPE__'} = C4::Context->config('db_scheme') // 'mysql';
45 $ENV{'__DB_NAME__'} = C4::Context->config('database') // 'koha';
46 $ENV{'__DB_HOST__'} = C4::Context->config('hostname') // 'localhost';
47 $ENV{'__DB_PORT__'} = C4::Context->config('port') // '3306';
48 $ENV{'__DB_USER__'} = C4::Context->config('user') // 'kohaadmin';
49 $ENV{'__DB_PASS__'} = C4::Context->config('pass') // 'katikoan';
51 my @files = ( "$source/etc/koha-conf.xml",
52 "$source/etc/searchengine/queryparser.yaml",
55 find(sub { push @files, $File::Find::name if ( -f $File::Find::name ); }, "$source/etc/zebradb");
57 foreach my $file (@files) {
58 my $target = "$file";
59 $target =~ s#$source#$destination#;
60 $target =~ s#etc/zebradb#etc/koha/zebradb#;
61 unlink($target);
62 make_path(dirname($target));
63 copy("$file", "$target");
64 system("perl $source/rewrite-config.PL $target");
65 if ($file =~ m/xml/) {
66 replace("$target", "$destination/intranet/templates", "$source/koha-tmpl/intranet-tmpl");
71 sub replace {
72 my ($file, $pattern, $replacement) = @_;
73 system("sed -i -e 's#$pattern#$replacement#' $file");