Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/roundcube/roundcubemail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'program/include')
-rw-r--r--program/include/rcmail_install.php21
-rw-r--r--program/include/rcmail_utils.php30
2 files changed, 42 insertions, 9 deletions
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
@@ -254,6 +248,28 @@ class rcmail_utils
}
/**
+ * 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
*
* @param int $days Number of days