Slurp db update file in and do() it instead of calling mysql
This commit is contained in:
parent
899b1b82b9
commit
d24d151f53
|
@ -116,7 +116,7 @@ GetOptions(
|
||||||
'dir:s' =>\$updateDir
|
'dir:s' =>\$updateDir
|
||||||
) or pod2usage(-exitstatus => -1);
|
) or pod2usage(-exitstatus => -1);
|
||||||
|
|
||||||
my $dbh = zmDbConnect();
|
my $dbh = zmDbConnect(undef, { mysql_multi_statements=>1 } );
|
||||||
$Config{ZM_DB_USER} = $dbUser;
|
$Config{ZM_DB_USER} = $dbUser;
|
||||||
$Config{ZM_DB_PASS} = $dbPass;
|
$Config{ZM_DB_PASS} = $dbPass;
|
||||||
|
|
||||||
|
@ -449,47 +449,19 @@ if ( $version )
|
||||||
my $dbh = shift;
|
my $dbh = shift;
|
||||||
my $version = shift;
|
my $version = shift;
|
||||||
|
|
||||||
my ( $host, $port ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
|
my $file = ( $updateDir ? $updateDir : $Config{ZM_PATH_DATA}.'/db' ) . "/zm_update-$version.sql";
|
||||||
my $command = "mysql -h".$host;
|
|
||||||
$command .= " -P".$port if defined($port);
|
|
||||||
if ( $dbUser )
|
|
||||||
{
|
|
||||||
$command .= " -u".$dbUser;
|
|
||||||
$command .= ' -p"'.$dbPass.'"' if $dbPass;
|
|
||||||
}
|
|
||||||
$command .= " ".$Config{ZM_DB_NAME}." < ";
|
|
||||||
if ( $updateDir )
|
|
||||||
{
|
|
||||||
$command .= $updateDir;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$command .= $Config{ZM_PATH_DATA}."/db";
|
|
||||||
}
|
|
||||||
$command .= "/zm_update-".$version.".sql";
|
|
||||||
|
|
||||||
print( "Executing '$command'\n" ) if ( logDebugging() );
|
open( my $fh, '<', $file ) or die "Unable to open $file $!";
|
||||||
my $output = qx($command);
|
$/ = undef;
|
||||||
my $status = $? >> 8;
|
my $sql = <$fh>;
|
||||||
if ( $status || logDebugging() )
|
close $fh;
|
||||||
{
|
$dbh->do($sql) or die $dbh->errstr();
|
||||||
chomp( $output );
|
print( "\nDatabase successfully upgraded to version $version.\n" );
|
||||||
print( "Output: $output\n" );
|
my $sql = "update Config set Value = ? where Name = 'ZM_DYN_DB_VERSION'";
|
||||||
}
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
if ( $status )
|
my $res = $sth->execute( $version ) or die( "Can't execute: ".$sth->errstr() );
|
||||||
{
|
|
||||||
die( "Command '$command' exited with status: $status\n" );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print( "\nDatabase successfully upgraded to version $version.\n" );
|
|
||||||
my $sql = "update Config set Value = ? where Name = 'ZM_DYN_DB_VERSION'";
|
|
||||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
|
||||||
my $res = $sth->execute( $version ) or die( "Can't execute: ".$sth->errstr() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
print( "\nUpgrading database to version ".ZM_VERSION."\n" );
|
print( "\nUpgrading database to version ".ZM_VERSION."\n" );
|
||||||
|
|
||||||
# Update config first of all
|
# Update config first of all
|
||||||
|
|
Loading…
Reference in New Issue