summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <thomas@roundcube.net>2013-03-21 14:58:43 +0100
committerThomas Bruederli <thomas@roundcube.net>2013-03-21 14:58:43 +0100
commit15e4c89ce6bbb381f4ec1070de0f0bd4a8574e33 (patch)
tree02afc2185d01c4f019e13e8c1ddc3efb0854b3b3
parent8d9c65ede64b63fb2ef476f3f0081bd319459d93 (diff)
Consider alternative table names from config when running DB updates
-rwxr-xr-xbin/updatedb.sh18
1 files changed, 16 insertions, 2 deletions
diff --git a/bin/updatedb.sh b/bin/updatedb.sh
index c856e0d63..1c7e1c7a1 100755
--- a/bin/updatedb.sh
+++ b/bin/updatedb.sh
@@ -56,7 +56,7 @@ if (!$DB->is_connected()) {
}
// Read DB schema version from database (if 'system' table exists)
-if (in_array('system', (array)$DB->list_tables())) {
+if (in_array($DB->table_name('system'), (array)$DB->list_tables())) {
$DB->query("SELECT " . $DB->quote_identifier('value')
." FROM " . $DB->quote_identifier($DB->table_name('system'))
." WHERE " . $DB->quote_identifier('name') ." = ?",
@@ -150,7 +150,7 @@ function update_db_schema($package, $version, $file)
$sql .= $line . "\n";
if (preg_match('/(;|^GO)$/', trim($line))) {
- @$DB->query($sql);
+ @$DB->query(fix_table_names($sql));
$sql = '';
if ($error = $DB->is_error()) {
return $error;
@@ -181,4 +181,18 @@ function update_db_schema($package, $version, $file)
return $DB->is_error();
}
+function fix_table_names($sql)
+{
+ global $DB;
+
+ foreach (array('users','identities','contacts','contactgroups','contactgroupmembers','session','cache','cache_index','cache_index','cache_messages','dictionary','searches','system') as $table) {
+ $real_table = $DB->table_name($table);
+ if ($real_table != $table) {
+ $sql = preg_replace("/([^a-z0-9_])$table([^a-z0-9_])/i", "\\1$real_table\\2", $sql);
+ }
+ }
+
+ return $sql;
+}
+
?>