From 86742cb7ee2f6b76d1958e5fc5b059240f0bfea5 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 28 Dec 2012 09:55:13 +0100 Subject: [PATCH] Bug 7167 follow-up: allow Makefile.PL to work $dbh should not be declared at the package level unless one is *sure* that there will be a valid context. TODO: fix the following noise when running perl Makefile.PL: unable to locate Koha configuration file koha-conf.xml at /home/esi/koha/C4/Context.pm line 372. Signed-off-by: Jonathan Druart --- C4/Update/Database.pm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/C4/Update/Database.pm b/C4/Update/Database.pm index 5bbc950..eaeb288 100644 --- a/C4/Update/Database.pm +++ b/C4/Update/Database.pm @@ -41,8 +41,6 @@ C4::Update::Database.pm =cut -our $dbh = C4::Context->dbh; - =head2 get_versions_path return the path to the version files @@ -194,6 +192,7 @@ sub list_versions_available { sub list_versions_already_applied { # 1st check if tables exist, otherwise create them + my $dbh = C4::Context->dbh; $dbh->do(qq{ CREATE TABLE IF NOT EXISTS `updatedb_error` ( `version` varchar(32) DEFAULT NULL, `error` text ) ENGINE=InnoDB CHARSET=utf8; }); @@ -240,6 +239,7 @@ sub list_versions_already_applied { sub execute { my ( $queries ) = @_; my @errors; + my $dbh = C4::Context->dbh; for my $query ( @{$queries->{queries}} ) { eval { $dbh->do( $query ); @@ -257,6 +257,7 @@ sub execute { =cut sub get_tables_name { + my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("SHOW TABLES"); $sth->execute(); my @tables; @@ -344,6 +345,7 @@ my $tables; =cut sub get_error { + my $dbh = C4::Context->dbh; my @errors = $dbh->selectrow_array(qq{SHOW ERRORS}); # Get errors my @warnings = $dbh->selectrow_array(qq{SHOW WARNINGS}); # Get warnings if ( @errors ) { # Catch specifics errors @@ -429,6 +431,7 @@ sub get_queries { sub md5_already_exists { my ( $md5 ) = @_; my $query = qq/SELECT version, md5 FROM updatedb_report WHERE md5 = ?/; + my $dbh = C4::Context->dbh; my $sth = $dbh->prepare( $query ); $sth->execute( $md5 ); my @r; @@ -449,6 +452,7 @@ sub md5_already_exists { sub set_infos { my ( $version, $queries, $errors, $md5 ) = @_; SetVersion($version) if not -s $errors; + my $dbh = C4::Context->dbh; for my $query ( @{ $queries->{queries} } ) { my $sth = $dbh->prepare("INSERT INTO updatedb_query(version, query) VALUES (?, ?)"); $sth->execute( $version, $query ); @@ -477,6 +481,7 @@ sub set_infos { sub mark_as_ok { my ( $version ) = @_; + my $dbh = C4::Context->dbh; my $sth = $dbh->prepare( "UPDATE updatedb_report SET status = 2 WHERE version=?" ); my $affected = $sth->execute( $version ); if ( $affected < 1 ) { @@ -528,6 +533,7 @@ sub SetVersion { my $new_version = TransformToNum(shift); return unless $new_version =~ /\d\.\d+/; my $current_version = TransformToNum( C4::Context->preference('Version') ); + my $dbh = C4::Context->dbh; unless ( C4::Context->preference('Version') ) { my $finish = $dbh->prepare(qq{ INSERT IGNORE INTO systempreferences (variable,value,explanation) @@ -548,6 +554,7 @@ sub SetVersion { sub TableExists { my $table = shift; + my $dbh = C4::Context->dbh; eval { local $dbh->{PrintError} = 0; local $dbh->{RaiseError} = 0; -- 1.7.10.4