mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-06 07:35:29 +02:00
[ticket/10349] Unit tests: Remove comments while loading schema files
Perform the same operations that the installer does when preparing the schema files. These functions come straight from /includes/functions_install.php and /includes/functions_admin.php. PHPBB3-10349
This commit is contained in:
parent
8e5eacf692
commit
bcaf65d7cd
@ -234,7 +234,12 @@ class phpbb_database_test_connection_manager
|
|||||||
}
|
}
|
||||||
|
|
||||||
$filename = $directory . $schema . '_schema.sql';
|
$filename = $directory . $schema . '_schema.sql';
|
||||||
$sql = $this->split_sql(file_get_contents($filename));
|
$remove_remarks = $this->dbms['COMMENTS'];
|
||||||
|
|
||||||
|
$queries = file_get_contents($filename);
|
||||||
|
$this->$remove_remarks($queries);
|
||||||
|
|
||||||
|
$sql = $this->split_sql($queries);
|
||||||
|
|
||||||
foreach ($sql as $query)
|
foreach ($sql as $query)
|
||||||
{
|
{
|
||||||
@ -279,6 +284,49 @@ class phpbb_database_test_connection_manager
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove_remarks will strip the sql comment lines out of an uploaded sql file
|
||||||
|
*/
|
||||||
|
protected function remove_remarks(&$sql)
|
||||||
|
{
|
||||||
|
$sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove_comments will strip the sql comment lines out of an uploaded sql file
|
||||||
|
* specifically for mssql and postgres type files in the install....
|
||||||
|
*/
|
||||||
|
protected function remove_comments(&$output)
|
||||||
|
{
|
||||||
|
$lines = explode("\n", $output);
|
||||||
|
$output = '';
|
||||||
|
|
||||||
|
// try to keep mem. use down
|
||||||
|
$linecount = sizeof($lines);
|
||||||
|
|
||||||
|
$in_comment = false;
|
||||||
|
for ($i = 0; $i < $linecount; $i++)
|
||||||
|
{
|
||||||
|
if (trim($lines[$i]) == '/*')
|
||||||
|
{
|
||||||
|
$in_comment = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$in_comment)
|
||||||
|
{
|
||||||
|
$output .= $lines[$i] . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trim($lines[$i]) == '*/')
|
||||||
|
{
|
||||||
|
$in_comment = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($lines);
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map a phpBB dbms driver name to dbms data array
|
* Map a phpBB dbms driver name to dbms data array
|
||||||
*/
|
*/
|
||||||
@ -289,46 +337,55 @@ class phpbb_database_test_connection_manager
|
|||||||
'SCHEMA' => 'firebird',
|
'SCHEMA' => 'firebird',
|
||||||
'DELIM' => ';;',
|
'DELIM' => ';;',
|
||||||
'PDO' => 'firebird',
|
'PDO' => 'firebird',
|
||||||
|
'COMMENTS' => 'remove_remarks',
|
||||||
),
|
),
|
||||||
'mysqli' => array(
|
'mysqli' => array(
|
||||||
'SCHEMA' => 'mysql_41',
|
'SCHEMA' => 'mysql_41',
|
||||||
'DELIM' => ';',
|
'DELIM' => ';',
|
||||||
'PDO' => 'mysql',
|
'PDO' => 'mysql',
|
||||||
|
'COMMENTS' => 'remove_remarks',
|
||||||
),
|
),
|
||||||
'mysql' => array(
|
'mysql' => array(
|
||||||
'SCHEMA' => 'mysql',
|
'SCHEMA' => 'mysql',
|
||||||
'DELIM' => ';',
|
'DELIM' => ';',
|
||||||
'PDO' => 'mysql',
|
'PDO' => 'mysql',
|
||||||
|
'COMMENTS' => 'remove_remarks',
|
||||||
),
|
),
|
||||||
'mssql' => array(
|
'mssql' => array(
|
||||||
'SCHEMA' => 'mssql',
|
'SCHEMA' => 'mssql',
|
||||||
'DELIM' => 'GO',
|
'DELIM' => 'GO',
|
||||||
'PDO' => 'odbc',
|
'PDO' => 'odbc',
|
||||||
|
'COMMENTS' => 'remove_comments',
|
||||||
),
|
),
|
||||||
'mssql_odbc'=> array(
|
'mssql_odbc'=> array(
|
||||||
'SCHEMA' => 'mssql',
|
'SCHEMA' => 'mssql',
|
||||||
'DELIM' => 'GO',
|
'DELIM' => 'GO',
|
||||||
'PDO' => 'odbc',
|
'PDO' => 'odbc',
|
||||||
|
'COMMENTS' => 'remove_comments',
|
||||||
),
|
),
|
||||||
'mssqlnative' => array(
|
'mssqlnative' => array(
|
||||||
'SCHEMA' => 'mssql',
|
'SCHEMA' => 'mssql',
|
||||||
'DELIM' => 'GO',
|
'DELIM' => 'GO',
|
||||||
'PDO' => 'sqlsrv',
|
'PDO' => 'sqlsrv',
|
||||||
|
'COMMENTS' => 'remove_comments',
|
||||||
),
|
),
|
||||||
'oracle' => array(
|
'oracle' => array(
|
||||||
'SCHEMA' => 'oracle',
|
'SCHEMA' => 'oracle',
|
||||||
'DELIM' => '/',
|
'DELIM' => '/',
|
||||||
'PDO' => 'oci',
|
'PDO' => 'oci',
|
||||||
|
'COMMENTS' => 'remove_comments',
|
||||||
),
|
),
|
||||||
'postgres' => array(
|
'postgres' => array(
|
||||||
'SCHEMA' => 'postgres',
|
'SCHEMA' => 'postgres',
|
||||||
'DELIM' => ';',
|
'DELIM' => ';',
|
||||||
'PDO' => 'pgsql',
|
'PDO' => 'pgsql',
|
||||||
|
'COMMENTS' => 'remove_comments',
|
||||||
),
|
),
|
||||||
'sqlite' => array(
|
'sqlite' => array(
|
||||||
'SCHEMA' => 'sqlite',
|
'SCHEMA' => 'sqlite',
|
||||||
'DELIM' => ';',
|
'DELIM' => ';',
|
||||||
'PDO' => 'sqlite2',
|
'PDO' => 'sqlite2',
|
||||||
|
'COMMENTS' => 'remove_remarks',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user