summaryrefslogtreecommitdiff
path: root/installer/rcube_install.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-04-27 18:31:40 +0200
committerAleksander Machniak <alec@alec.pl>2013-04-27 18:31:40 +0200
commit399db1b647e14947e97a865c09215969f56a7efe (patch)
tree4801fc0482e3e6fe94fd6668dae03b13926b9d17 /installer/rcube_install.php
parentd7fcd8ce422a24f794d18e2212163690bf3ca753 (diff)
Add db_prefix configuration option in place of db_table_*/db_sequence_* options
Make possible to use db_prefix for schema initialization in Installer (#1489067) Fix updatedb.sh script so it recognizes also table prefix for external DDL files
Diffstat (limited to 'installer/rcube_install.php')
-rw-r--r--installer/rcube_install.php32
1 files changed, 31 insertions, 1 deletions
diff --git a/installer/rcube_install.php b/installer/rcube_install.php
index 2e1298707..32b6a5dd7 100644
--- a/installer/rcube_install.php
+++ b/installer/rcube_install.php
@@ -372,7 +372,7 @@ class rcube_install
$existing_tables = $DB->list_tables();
foreach ($db_schema as $table => $cols) {
- $table = !empty($this->config['db_table_'.$table]) ? $this->config['db_table_'.$table] : $table;
+ $table = $this->config['db_prefix'] . $table;
if (!in_array($table, $existing_tables)) {
$errors[] = "Missing table '".$table."'";
}
@@ -655,6 +655,7 @@ class rcube_install
*/
function exec_sql($sql, $DB)
{
+ $sql = $this->fix_table_names($sql, $DB);
$buff = '';
foreach (explode("\n", $sql) as $line) {
if (preg_match('/^--/', $line) || trim($line) == '')
@@ -674,6 +675,35 @@ class rcube_install
/**
+ * Parse SQL file and fix table names according to db_prefix
+ * Note: This need to be a complete database initial file
+ */
+ private function fix_table_names($sql, $DB)
+ {
+ if (empty($this->config['db_prefix'])) {
+ return $sql;
+ }
+
+ // replace table names
+ if (preg_match_all('/CREATE TABLE (\[dbo\]\.|IF NOT EXISTS )?[`"\[\]]*([^`"\[\] \r\n]+)/i', $sql, $matches)) {
+ foreach ($matches[2] as $table) {
+ $real_table = $this->config['db_prefix'] . $table;
+ $sql = preg_replace("/([^a-zA-Z0-9_])$table([^a-zA-Z0-9_])/", "\\1$real_table\\2", $sql);
+ }
+ }
+ // replace sequence names
+ if ($DB->db_provider == 'postgres' && preg_match_all('/CREATE SEQUENCE (IF NOT EXISTS )?"?([^" \n\r]+)/i', $sql, $matches)) {
+ foreach ($matches[2] as $sequence) {
+ $real_sequence = $this->config['db_prefix'] . $sequence;
+ $sql = preg_replace("/([^a-zA-Z0-9_])$sequence([^a-zA-Z0-9_])/", "\\1$real_sequence\\2", $sql);
+ }
+ }
+
+ return $sql;
+ }
+
+
+ /**
* Handler for Roundcube errors
*/
function raise_error($p)