Fix bug where the Installer would not warn about required schema upgrade (#7042)

This commit is contained in:
Aleksander Machniak
2019-11-16 09:23:32 +01:00
parent 47f72303ac
commit ea3ad31ce0
3 changed files with 43 additions and 9 deletions

View File

@@ -463,9 +463,23 @@ class rcmail_install
// read reference schema from mysql.initial.sql
$engine = $db->db_provider;
$db_schema = $this->db_read_schema(INSTALL_PATH . "SQL/$engine.initial.sql");
$db_schema = $this->db_read_schema(INSTALL_PATH . "SQL/$engine.initial.sql", $schema_version);
$errors = array();
// Just check the version
if ($schema_version) {
$version = rcmail_utils::db_version();
if (empty($version)) {
$errors[] = "Schema version not found";
}
else if ($schema_version != $version) {
$errors[] = "Schema version: {$version} (required: {$schema_version})";
}
return !empty($errors) ? $errors : false;
}
// check list of tables
$existing_tables = $db->list_tables();
@@ -491,7 +505,7 @@ class rcmail_install
/**
* Utility function to read database schema from an .sql file
*/
private function db_read_schema($schemafile)
private function db_read_schema($schemafile, &$version = null)
{
$lines = file($schemafile);
$schema = array();
@@ -503,6 +517,9 @@ class rcmail_install
$table_name = end($table_name);
$table_name = preg_replace('/[`"\[\]]/', '', $table_name);
}
else if (preg_match('/insert into/i', $line) && preg_match('/\'roundcube-version\',\s*\'([0-9]+)\'/', $line, $m)) {
$version = $m[1];
}
else if ($table_name && ($line = trim($line))) {
if ($line == 'GO' || $line[0] == ')' || $line[strlen($line)-1] == ';') {
$table_name = null;