From 29e2cdf56167c24b80d6387917fcf8836baf3570 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 13 Nov 2013 09:42:10 -0500 Subject: [PATCH] split the innoDB upgrade out of the version section, so that it always checked for MyISAM tables and if found, offers to update them. --- scripts/zmupdate.pl.in | 79 +++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/scripts/zmupdate.pl.in b/scripts/zmupdate.pl.in index d80209885..2595d8655 100644 --- a/scripts/zmupdate.pl.in +++ b/scripts/zmupdate.pl.in @@ -335,6 +335,49 @@ if ( $freshen ) loadConfigFromDB(); saveConfigToDB(); } + +sub getMyISAMTables { + my $dbh = shift; + my $sql = "SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema='zm' AND engine = 'MyISAM'"; + my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); + my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() ); + + my @dbTables; + while( my $dbTable = $sth->fetchrow() ) { + push( @dbTables, $dbTable ); + } + $sth->finish(); +} # end sub getInnoDBTables + +sub toInnoDB { + my ( $dbh, @dbTables ) = @_; + if (@dbTables) { + print "\nConverting MyISAM tables to InnoDB. Please wait.\n"; + foreach (@dbTables) { + my $sql = "ALTER TABLE $_ ENGINE = InnoDB"; + my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); + my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() ); + $sth->finish(); + } + } else { + print "\nNo MyISAM tables found. Skipping...\n"; + } +} # end sub toInnoDB + +# Now check for MyISAM Tables +my $dbh = zmDbConnect(); +my @Tables = getMyISAMTables( $dbh ); +if ( @Tables ) { + print( "\nPrevious versions of ZoneMinder used the MyISAM database engine.\nHowever, the recommended database engine is InnoDB.\n"); + print( "\nHint: InnoDB tables are much less likely to be corrupted during an unclean shutdown.\n\nPress 'y' to convert your tables to InnoDB or 'n' to skip : "); + my $response = ; + chomp( $response ); + if ( $response =~ /^[yY]$/ ) { + toInnoDB($dbh); + } +} +$dbh->disconnect(); + if ( $version ) { my ( $detaint_version ) = $version =~ /^([\w.]+)$/; @@ -454,34 +497,6 @@ if ( $version ) } } - sub toInnoDB - { - my $dbh = shift; - my $sql = "SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema='zm' AND engine = 'MyISAM'"; - my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() ); - - my @dbTables; - while( my $dbTable = $sth->fetchrow() ) - { - push( @dbTables, $dbTable ); - } - $sth->finish(); - - if (@dbTables) - { - print "\nConverting MyISAM tables to InnoDB. Please wait.\n"; - foreach (@dbTables) - { - my $sql = "ALTER TABLE $_ ENGINE = InnoDB"; - my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() ); - } - $sth->finish(); - } else { - print "\nNo MyISAM tables found. Skipping...\n"; - } - } print( "\nUpgrading database to version ".ZM_VERSION."\n" ); @@ -1014,14 +1029,6 @@ if ( $version ) } # end if $sth->finish(); - print( "\nPrevious versions of ZoneMinder used the MyISAM database engine.\nHowever, the recommended database engine is InnoDB.\n"); - print( "\nHint: InnoDB tables are much less likely to be corrupted during an unclean shutdown.\n\nPress 'y' to convert your tables to InnoDB or 'n' to skip : "); - my $response = ; - chomp( $response ); - if ( $response =~ /^[yY]$/ ) - { - toInnoDB($dbh); - } $cascade = !undef; $version = '1.26.0';