diff options
author | Aleksander Machniak <alec@alec.pl> | 2014-04-29 11:34:43 +0200 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2014-04-29 11:34:43 +0200 |
commit | 90f7aa9e39e744e708a597ff6d1ac83f7c4fcef5 (patch) | |
tree | e1f87bcbf54f21efd6eccbfda2a7c012e3f9ec56 /program/lib/Roundcube/rcube_db_pgsql.php | |
parent | d5038ee5d910ffe200e5cad60ca407f615b2691d (diff) |
Fix varius db_prefix issues (#1489839)
- Move DDL script execution code to rcube_db class(es).
- Improve prefix replacement code, so index names are also modified
Diffstat (limited to 'program/lib/Roundcube/rcube_db_pgsql.php')
-rw-r--r-- | program/lib/Roundcube/rcube_db_pgsql.php | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/program/lib/Roundcube/rcube_db_pgsql.php b/program/lib/Roundcube/rcube_db_pgsql.php index 68bf6d85d..a92d3cf36 100644 --- a/program/lib/Roundcube/rcube_db_pgsql.php +++ b/program/lib/Roundcube/rcube_db_pgsql.php @@ -73,10 +73,9 @@ class rcube_db_pgsql extends rcube_db // Note: we support only one sequence per table // Note: The sequence name must be <table_name>_seq $sequence = $table . '_seq'; - $rcube = rcube::get_instance(); - // return sequence name if configured - if ($prefix = $rcube->config->get('db_prefix')) { + // modify sequence name if prefix is configured + if ($prefix = $this->options['table_prefix']) { return $prefix . $sequence; } @@ -190,4 +189,24 @@ class rcube_db_pgsql extends rcube_db return $result; } + /** + * Parse SQL file and fix table names according to table prefix + */ + protected function fix_table_names($sql) + { + if (!$this->options['table_prefix']) { + return $sql; + } + + $sql = parent::fix_table_names($sql); + + // replace sequence names, and other postgres-specific commands + $sql = preg_replace_callback( + '/((SEQUENCE |RENAME TO |nextval\()["\']*)([^"\' \r\n]+)/', + array($this, 'fix_table_names_callback'), + $sql + ); + + return $sql; + } } |