1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-06 23:55:26 +02:00

[ticket/10937] Comment removal functions: Restore backward compatibility

PHPBB3-10937
This commit is contained in:
Andreas Fischer 2012-06-20 13:56:11 +02:00
parent 155c93d71a
commit 81d5327e44
4 changed files with 55 additions and 8 deletions

View File

@ -2293,6 +2293,21 @@ function auto_prune($forum_id, $prune_mode, $prune_flags, $prune_days, $prune_fr
return; return;
} }
/**
* remove_comments will strip the sql comment lines out of an uploaded sql file
* specifically for mssql and postgres type files in the install....
*
* @deprecated Use phpbb_remove_comments() instead.
*/
function remove_comments(&$output)
{
// Remove /* */ comments (http://ostermiller.org/findcomment.html)
$output = preg_replace('#/\*(.|[\r\n])*?\*/#', "\n", $output);
// Return by reference and value.
return $output;
}
/** /**
* Cache moderators, called whenever permissions are changed via admin_permissions. Changes of username * Cache moderators, called whenever permissions are changed via admin_permissions. Changes of username
* and group names must be carried through for the moderators table * and group names must be carried through for the moderators table

View File

@ -50,6 +50,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'SCHEMA' => 'firebird', 'SCHEMA' => 'firebird',
'MODULE' => 'interbase', 'MODULE' => 'interbase',
'DELIM' => ';;', 'DELIM' => ';;',
'COMMENTS' => 'remove_remarks',
'DRIVER' => 'firebird', 'DRIVER' => 'firebird',
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => false, '2.0.x' => false,
@ -59,6 +60,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'SCHEMA' => 'mysql_41', 'SCHEMA' => 'mysql_41',
'MODULE' => 'mysqli', 'MODULE' => 'mysqli',
'DELIM' => ';', 'DELIM' => ';',
'COMMENTS' => 'remove_remarks',
'DRIVER' => 'mysqli', 'DRIVER' => 'mysqli',
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => true, '2.0.x' => true,
@ -68,6 +70,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'SCHEMA' => 'mysql', 'SCHEMA' => 'mysql',
'MODULE' => 'mysql', 'MODULE' => 'mysql',
'DELIM' => ';', 'DELIM' => ';',
'COMMENTS' => 'remove_remarks',
'DRIVER' => 'mysql', 'DRIVER' => 'mysql',
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => true, '2.0.x' => true,
@ -77,6 +80,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'SCHEMA' => 'mssql', 'SCHEMA' => 'mssql',
'MODULE' => 'mssql', 'MODULE' => 'mssql',
'DELIM' => 'GO', 'DELIM' => 'GO',
'COMMENTS' => 'remove_comments',
'DRIVER' => 'mssql', 'DRIVER' => 'mssql',
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => true, '2.0.x' => true,
@ -86,6 +90,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'SCHEMA' => 'mssql', 'SCHEMA' => 'mssql',
'MODULE' => 'odbc', 'MODULE' => 'odbc',
'DELIM' => 'GO', 'DELIM' => 'GO',
'COMMENTS' => 'remove_comments',
'DRIVER' => 'mssql_odbc', 'DRIVER' => 'mssql_odbc',
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => true, '2.0.x' => true,
@ -95,6 +100,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'SCHEMA' => 'mssql', 'SCHEMA' => 'mssql',
'MODULE' => 'sqlsrv', 'MODULE' => 'sqlsrv',
'DELIM' => 'GO', 'DELIM' => 'GO',
'COMMENTS' => 'remove_comments',
'DRIVER' => 'mssqlnative', 'DRIVER' => 'mssqlnative',
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => false, '2.0.x' => false,
@ -104,6 +110,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'SCHEMA' => 'oracle', 'SCHEMA' => 'oracle',
'MODULE' => 'oci8', 'MODULE' => 'oci8',
'DELIM' => '/', 'DELIM' => '/',
'COMMENTS' => 'remove_comments',
'DRIVER' => 'oracle', 'DRIVER' => 'oracle',
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => false, '2.0.x' => false,
@ -113,6 +120,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'SCHEMA' => 'postgres', 'SCHEMA' => 'postgres',
'MODULE' => 'pgsql', 'MODULE' => 'pgsql',
'DELIM' => ';', 'DELIM' => ';',
'COMMENTS' => 'remove_comments',
'DRIVER' => 'postgres', 'DRIVER' => 'postgres',
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => true, '2.0.x' => true,
@ -122,6 +130,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'SCHEMA' => 'sqlite', 'SCHEMA' => 'sqlite',
'MODULE' => 'sqlite', 'MODULE' => 'sqlite',
'DELIM' => ';', 'DELIM' => ';',
'COMMENTS' => 'remove_remarks',
'DRIVER' => 'sqlite', 'DRIVER' => 'sqlite',
'AVAILABLE' => true, 'AVAILABLE' => true,
'2.0.x' => false, '2.0.x' => false,
@ -465,16 +474,39 @@ function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix,
/** /**
* Removes comments from schema files * Removes comments from schema files
*
* @deprecated Use phpbb_remove_comments() instead.
*/ */
function remove_comments($sql) function remove_remarks(&$sql)
{ {
// Remove /* */ comments (http://ostermiller.org/findcomment.html)
$sql = preg_replace('#/\*(.|[\r\n])*?\*/#', "\n", $sql);
// Remove # style comments // Remove # style comments
$sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql)); $sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql));
return $sql; // Return by reference
}
/**
* Removes comments from $input.
*
* @param string $input Input string
*
* @return string Input string with comments removed
*/
function phpbb_remove_comments($input)
{
if (!function_exists('remove_comments'))
{
global $phpbb_root_path, $phpEx;
require($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
}
// Remove /* */ comments
remove_comments($input);
// Remove # style comments
remove_remarks($input);
return $input;
} }
/** /**

View File

@ -1164,7 +1164,7 @@ class install_install extends module
$sql_query = preg_replace('#phpbb_#i', $data['table_prefix'], $sql_query); $sql_query = preg_replace('#phpbb_#i', $data['table_prefix'], $sql_query);
$sql_query = remove_comments($sql_query); $sql_query = phpbb_remove_comments($sql_query);
$sql_query = split_sql_file($sql_query, $delimiter); $sql_query = split_sql_file($sql_query, $delimiter);
@ -1202,7 +1202,7 @@ class install_install extends module
// Change language strings... // Change language strings...
$sql_query = preg_replace_callback('#\{L_([A-Z0-9\-_]*)\}#s', 'adjust_language_keys_callback', $sql_query); $sql_query = preg_replace_callback('#\{L_([A-Z0-9\-_]*)\}#s', 'adjust_language_keys_callback', $sql_query);
$sql_query = remove_comments($sql_query); $sql_query = phpbb_remove_comments($sql_query);
$sql_query = split_sql_file($sql_query, ';'); $sql_query = split_sql_file($sql_query, ';');
foreach ($sql_query as $sql) foreach ($sql_query as $sql)

View File

@ -243,7 +243,7 @@ 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 = remove_comments($queries); $sql = phpbb_remove_comments($queries);
$sql = split_sql_file($sql, $this->dbms['DELIM']); $sql = split_sql_file($sql, $this->dbms['DELIM']);