|
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 |
for my $marcflavour ( qw( marc21 unimarc ) ) { |
| 30 |
say "loading kohastructure for $lang | not $marcflavour"; |
| 31 |
recreate_db( $db_name ); |
| 32 |
my $error = C4::Installer->new->load_sql( $kohastructure ); |
| 33 |
my @sample_files = @global_files; |
| 34 |
|
| 35 |
find( sub { |
| 36 |
push @sample_files, $File::Find::name if $_ =~ m|\.sql$|; |
| 37 |
}, $sample_dir . '/' . $lang . '/' |
| 38 |
); |
| 39 |
my $i = 1; |
| 40 |
for my $sql_file ( @sample_files ) { |
| 41 |
print $i++ . "/" . scalar @sample_files . "\r"; flush STDOUT; |
| 42 |
next if $sql_file =~ $marcflavour; |
| 43 |
#my $content = read_file( $sql_file ); |
| 44 |
#my @tables = uniq map { $_ =~ s/insert\s*(ignore)?\s*into\s*`?(\w+)`?.*/$2/xmsi; $_ } grep {/insert\s*(ignore)?\s*into/xmsi} split '\n', $content; |
| 45 |
my $error = C4::Installer->new->load_sql( $sql_file ); |
| 46 |
warn $error if $error; |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
sub recreate_db { |
| 52 |
my $dbname = shift; |
| 53 |
my $dbh = C4::Context->dbh; |
| 54 |
eval { $dbh->do(qq|DROP DATABASE $dbname|) }; |
| 55 |
|
| 56 |
$dbh->do(qq|CREATE DATABASE $dbname CHARACTER SET utf8 COLLATE utf8_bin|); |
| 57 |
|
| 58 |
# Force C4::Context to recreate a new db handler |
| 59 |
$dbh->disconnect; |
| 60 |
} |