Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
use Modern::Perl; |
4 |
|
5 |
use Test::More; #tests => XXX; |
6 |
use File::Find; |
7 |
use File::Slurp; |
8 |
use List::MoreUtils qw( uniq ); |
9 |
use t::lib::Mocks; |
10 |
use C4::Installer; |
11 |
|
12 |
my $db_name = 'koha_test_installer'; |
13 |
t::lib::Mocks::mock_config('database', $db_name); |
14 |
my $user = C4::Context->config('user'); |
15 |
my $pass = C4::Context->config('pass'); |
16 |
my $schema = Koha::Database->new->schema; |
17 |
|
18 |
my $sample_dir = C4::Context->config('intranetdir') . '/installer/data/mysql/'; |
19 |
my @global_files = ( |
20 |
$sample_dir . 'audio_alerts.sql', |
21 |
$sample_dir . 'sysprefs.sql', |
22 |
$sample_dir . 'userflags.sql', |
23 |
$sample_dir . 'userpermissions.sql', |
24 |
$sample_dir . 'mandatory/subtag_registry.sql', |
25 |
); |
26 |
my $kohastructure = $sample_dir . '/kohastructure.sql'; |
27 |
|
28 |
for my $lang ( qw ( de-DE en es-ES fr-CA fr-FR it-IT nb-NO pl-PL ru-RU uk-UA ) ) { |
29 |
next if $lang eq "ru-RU" or $lang eq "uk-UA"; # Some files are broken and need to be fixed |
30 |
|
31 |
next unless $lang eq 'uk-UA'; |
32 |
|
33 |
my $fr_pass = 1; |
34 |
for my $marcflavour ( qw( marc21 unimarc ) ) { |
35 |
say "loading kohastructure for $lang | not $marcflavour"; |
36 |
recreate_db( $db_name ); |
37 |
my $error = C4::Installer->new->load_sql( $kohastructure ); |
38 |
my @sample_files; |
39 |
|
40 |
find( sub { |
41 |
push @sample_files, $File::Find::name if $_ =~ m|\.sql$|; |
42 |
}, $sample_dir . '/mandatory/' |
43 |
); |
44 |
|
45 |
find( sub { |
46 |
my $filepath = $File::Find::name; |
47 |
if ( $lang eq 'fr-FR' and $filepath =~ m|/marcflavour/| and $marcflavour eq 'marc21') { |
48 |
if ( $fr_pass == 1 ) { |
49 |
push @sample_files, $filepath if $filepath =~ m|\.sql$| and $filepath =~ m|/unimarc_complet/|; |
50 |
} else { |
51 |
push @sample_files, $filepath if $filepath =~ m|\.sql$| and $filepath =~ m|/unimarc_lecture_pub/|; |
52 |
} |
53 |
$fr_pass++; |
54 |
} else { |
55 |
push @sample_files, $filepath if $filepath =~ m|\.sql$|; |
56 |
} |
57 |
}, $sample_dir . $lang . '/' |
58 |
); |
59 |
@sample_files = ( @global_files, sort @sample_files ); |
60 |
my $i = 1; |
61 |
for my $sql_file ( @sample_files ) { |
62 |
print $i++ . "/" . scalar @sample_files . "\r"; flush STDOUT; |
63 |
next if $sql_file =~ $marcflavour; |
64 |
my $error = C4::Installer->new->load_sql( $sql_file ); |
65 |
warn $error if $error; |
66 |
} |
67 |
} |
68 |
} |
69 |
|
70 |
sub recreate_db { |
71 |
my $dbname = shift; |
72 |
my $dbh = C4::Context->dbh; |
73 |
eval { $dbh->do(qq|DROP DATABASE $dbname|) }; |
74 |
|
75 |
$dbh->do(qq|CREATE DATABASE $dbname CHARACTER SET utf8 COLLATE utf8_bin|); |
76 |
|
77 |
# Force C4::Context to recreate a new db handler |
78 |
$dbh->disconnect; |
79 |
} |