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
@ -180,13 +180,46 @@ function update_db_schema($package, $version, $file)
function fix_table_names($sql)
function fix_table_names($sql)
{
{
global $DB;
global $DB, $RC, $dir;
static $tables;
static $sequences;
$prefix=$RC->config->get('db_prefix');
$engine=$DB->db_provider;
if(empty($prefix)){
return$sql;
}
if($tables=== null){
$tables= array();
$sequences= array();
// readcomplete schema (initial) file
$filename="$dir/../$engine.initial.sql";
$schema= @file_get_contents($filename);
// find table names
if(preg_match_all('/CREATE TABLE (\[dbo\]\.|IF NOT EXISTS )?[`"\[\]]*([^`"\[\] \r\n]+)/i', $schema, $matches)){
foreach ($matches[2] as $table){
$tables[$table]=$prefix . $table;
}
}
// find sequence names
if($engine=='postgres'&& preg_match_all('/CREATE SEQUENCE (IF NOT EXISTS )?"?([^" \n\r]+)/i', $schema, $matches)){
foreach ($matches[2] as $sequence){
$sequences[$sequence]=$prefix . $sequence;
}
}
}
foreach (array('users','identities','contacts','contactgroups','contactgroupmembers','session','cache','cache_index','cache_index','cache_messages','dictionary','searches','system') as $table){