mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-12 06:18:52 +00:00
[ticket/10349] Removed duplicated functions from schema loading in tests
PHPBB3-10349
This commit is contained in:
parent
b4dcd4193e
commit
baac9e5d15
2 changed files with 4 additions and 44 deletions
|
@ -506,7 +506,6 @@ function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes comments from schema files
|
* Removes comments from schema files
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
function remove_comments($sql)
|
function remove_comments($sql)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_install.php';
|
||||||
|
|
||||||
class phpbb_database_test_connection_manager
|
class phpbb_database_test_connection_manager
|
||||||
{
|
{
|
||||||
private $config;
|
private $config;
|
||||||
|
@ -236,9 +238,9 @@ class phpbb_database_test_connection_manager
|
||||||
$filename = $directory . $schema . '_schema.sql';
|
$filename = $directory . $schema . '_schema.sql';
|
||||||
|
|
||||||
$queries = file_get_contents($filename);
|
$queries = file_get_contents($filename);
|
||||||
$sql = $this->remove_comments($queries);
|
$sql = remove_comments($queries);
|
||||||
|
|
||||||
$sql = $this->split_sql($sql);
|
$sql = split_sql_file($sql, $this->dbms['DELIM']);
|
||||||
|
|
||||||
foreach ($sql as $query)
|
foreach ($sql as $query)
|
||||||
{
|
{
|
||||||
|
@ -246,47 +248,6 @@ class phpbb_database_test_connection_manager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Split contents of an SQL file into an array of SQL statements
|
|
||||||
*
|
|
||||||
* Note: This method is not the same as split_sql_file from functions_install.
|
|
||||||
*
|
|
||||||
* @param string $sql Raw contents of an SQL file
|
|
||||||
*
|
|
||||||
* @return Array of runnable SQL statements
|
|
||||||
*/
|
|
||||||
protected function split_sql($sql)
|
|
||||||
{
|
|
||||||
$sql = str_replace("\r" , '', $sql);
|
|
||||||
$data = preg_split('/' . preg_quote($this->dbms['DELIM'], '/') . '$/m', $sql);
|
|
||||||
|
|
||||||
$data = array_map('trim', $data);
|
|
||||||
|
|
||||||
// The empty case
|
|
||||||
$end_data = end($data);
|
|
||||||
|
|
||||||
if (empty($end_data))
|
|
||||||
{
|
|
||||||
unset($data[key($data)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes comments from schema files
|
|
||||||
*/
|
|
||||||
protected function remove_comments($sql)
|
|
||||||
{
|
|
||||||
// Remove /* */ comments (http://ostermiller.org/findcomment.html)
|
|
||||||
$sql = preg_replace('#/\*(.|[\r\n])*?\*/#', "\n", $sql);
|
|
||||||
|
|
||||||
// Remove # style comments
|
|
||||||
$sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql));
|
|
||||||
|
|
||||||
return $sql;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map a phpBB dbms driver name to dbms data array
|
* Map a phpBB dbms driver name to dbms data array
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue