From cfd25f0ed73f7b7cc14e7abba3cbb55d934eb78c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 2 Nov 2018 11:00:01 -0300 Subject: [PATCH] Bug 19821: Require database_test != database To prevent developpers to drop their database. Signed-off-by: Martin Renvoize Signed-off-by: Bouzid Fergani Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- t/lib/Bootstrap.pm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/t/lib/Bootstrap.pm b/t/lib/Bootstrap.pm index fbba437591..dd749149d8 100644 --- a/t/lib/Bootstrap.pm +++ b/t/lib/Bootstrap.pm @@ -6,7 +6,7 @@ use DBI; use File::Temp qw( tempfile ); use XML::LibXML; -our $database; +our ( $database, $database_test ); sub import { my ($self, %args) = @_; @@ -15,7 +15,10 @@ sub import { my $host = C4::Context->config('hostname'); my $port = C4::Context->config('port'); - $database = C4::Context->config("database_test") || C4::Context->config('database'); + $database_test = C4::Context->config("database_test") or die "Config entry 'database_test' does not exist"; + $database = C4::Context->config('database'); + die "Entries 'database_test' and 'database' have the same value in your config" + if $database_test eq $database; my $user = C4::Context->config('user'); my $pass = C4::Context->config('pass'); @@ -24,14 +27,15 @@ sub import { PrintError => 0, }); - $dbh->do("DROP DATABASE IF EXISTS $database"); - $dbh->do("CREATE DATABASE $database"); + $dbh->do("DROP DATABASE IF EXISTS $database_test"); + $dbh->do("CREATE DATABASE $database_test"); } END { my $dbh = C4::Context->dbh; - $dbh->do("DROP DATABASE IF EXISTS $database") if $database; + $dbh->do("DROP DATABASE IF EXISTS $database_test") + if $database_test && $database_test ne $database; Koha::Caches->get_instance()->flush_all; Koha::Caches->get_instance('config')->flush_all; }; -- 2.39.5