diff --git a/CHANGELOG b/CHANGELOG index 36f9bd8b6..3a71e59c2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,7 @@ CHANGELOG Roundcube Webmail - Fix so update.sh script warns about changed defaults (#7011) - Fix tables listing routine when DSN contained a database with unsupported suffix (#7034) - Fix so Elastic is also a default in jqueryui plugin (#7039) +- Fix bug where the Installer would not warn about required schema upgrade (#7042) RELEASE 1.4.0 ------------- diff --git a/program/include/rcmail_install.php b/program/include/rcmail_install.php index ae5a6bcbd..ebd23417d 100644 --- a/program/include/rcmail_install.php +++ b/program/include/rcmail_install.php @@ -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; diff --git a/program/include/rcmail_utils.php b/program/include/rcmail_utils.php index 78f38646a..ca1359355 100644 --- a/program/include/rcmail_utils.php +++ b/program/include/rcmail_utils.php @@ -112,13 +112,7 @@ class rcmail_utils // Read DB schema version from database (if 'system' table exists) if (in_array($db->table_name('system'), (array)$db->list_tables())) { - $db->query("SELECT `value`" - . " FROM " . $db->table_name('system', true) - . " WHERE `name` = ?", - $package . '-version'); - - $row = $db->fetch_array(); - $version = preg_replace('/[^0-9]/', '', $row[0]); + $version = self::db_version($package); } // DB version not found, but release version is specified @@ -253,6 +247,28 @@ class rcmail_utils return $db->is_error(); } + /** + * Get version string for the specified package + * + * @param string $package Package name + * + * @return string Version string + */ + public static function db_version($package = 'roundcube') + { + $db = self::db(); + + $db->query("SELECT `value`" + . " FROM " . $db->table_name('system', true) + . " WHERE `name` = ?", + $package . '-version'); + + $row = $db->fetch_array(); + $version = preg_replace('/[^0-9]/', '', $row[0]); + + return $version; + } + /** * Removes all deleted records older than X days *