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

pull/7051/head
Aleksander Machniak 5 years ago
parent bd21d43ac9
commit 3cd3d8eecb

@ -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
-------------

@ -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;

@ -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
*

Loading…
Cancel
Save