mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
- some stupid bugs in restore - centralized the method of getting tables git-svn-id: file:///svn/phpbb/trunk@7015 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
bf8bea4967
commit
59fdd2edca
4 changed files with 77 additions and 76 deletions
|
@ -1374,7 +1374,7 @@ function get_path($src_path, $src_url, $test_file)
|
||||||
|
|
||||||
function compare_table($tables, $tablename, &$prefixes)
|
function compare_table($tables, $tablename, &$prefixes)
|
||||||
{
|
{
|
||||||
for ($i = 0; $i < sizeof($tables); ++$i)
|
for ($i = 0, $table_size = sizeof($tables); $i < $table_size; ++$i)
|
||||||
{
|
{
|
||||||
if (preg_match('/(.*)' . $tables[$i] . '$/', $tablename, $m))
|
if (preg_match('/(.*)' . $tables[$i] . '$/', $tablename, $m))
|
||||||
{
|
{
|
||||||
|
|
|
@ -182,6 +182,69 @@ function dbms_select($default = '', $only_20x_options = false)
|
||||||
return $dbms_options;
|
return $dbms_options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get tables of a database
|
||||||
|
*/
|
||||||
|
function get_tables($db)
|
||||||
|
{
|
||||||
|
switch ($db->sql_layer)
|
||||||
|
{
|
||||||
|
case 'mysql':
|
||||||
|
case 'mysql4':
|
||||||
|
case 'mysqli':
|
||||||
|
$sql = 'SHOW TABLES';
|
||||||
|
$field = 'Tables_in_' . $db->dbname;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'sqlite':
|
||||||
|
$sql = 'SELECT name
|
||||||
|
FROM sqlite_master
|
||||||
|
WHERE type = "table"';
|
||||||
|
$field = 'name';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'mssql':
|
||||||
|
case 'mssql_odbc':
|
||||||
|
$sql = "SELECT name
|
||||||
|
FROM sysobjects
|
||||||
|
WHERE type='U'";
|
||||||
|
$field = 'name';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'postgres':
|
||||||
|
$sql = 'SELECT relname
|
||||||
|
FROM pg_stat_user_tables';
|
||||||
|
$field = 'relname';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'firebird':
|
||||||
|
$sql = 'SELECT rdb$relation_name
|
||||||
|
FROM rdb$relations
|
||||||
|
WHERE rdb$view_source is null
|
||||||
|
AND rdb$system_flag = 0';
|
||||||
|
$field = 'rdb$relation_name';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'oracle':
|
||||||
|
$sql = 'SELECT table_name
|
||||||
|
FROM USER_TABLES';
|
||||||
|
$field = 'table_name';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $db->sql_query($sql);
|
||||||
|
|
||||||
|
$tables = array();
|
||||||
|
|
||||||
|
while ($row = $db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
$tables[] = $row[$field];
|
||||||
|
}
|
||||||
|
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
|
return $tables;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to test whether we are able to connect to the database the user has specified
|
* Used to test whether we are able to connect to the database the user has specified
|
||||||
|
@ -263,75 +326,21 @@ function connect_check_db($error_connect, &$error, $dbms, $table_prefix, $dbhost
|
||||||
$error[] = $lang['INST_ERR_DB_CONNECT'] . '<br />' . (($db_error['message']) ? $db_error['message'] : $lang['INST_ERR_DB_NO_ERROR']);
|
$error[] = $lang['INST_ERR_DB_CONNECT'] . '<br />' . (($db_error['message']) ? $db_error['message'] : $lang['INST_ERR_DB_NO_ERROR']);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
switch ($dbms['DRIVER'])
|
|
||||||
{
|
|
||||||
case 'mysql':
|
|
||||||
case 'mysqli':
|
|
||||||
$sql = 'SHOW TABLES';
|
|
||||||
$field = "Tables_in_{$dbname}";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'sqlite':
|
|
||||||
$sql = 'SELECT name
|
|
||||||
FROM sqlite_master
|
|
||||||
WHERE type = "table"';
|
|
||||||
$field = 'name';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'mssql':
|
|
||||||
case 'mssql_odbc':
|
|
||||||
$sql = "SELECT name
|
|
||||||
FROM sysobjects
|
|
||||||
WHERE type='U'";
|
|
||||||
$field = 'name';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'postgres':
|
|
||||||
$sql = "SELECT relname
|
|
||||||
FROM pg_class
|
|
||||||
WHERE relkind = 'r'
|
|
||||||
AND relname NOT LIKE 'pg\_%'";
|
|
||||||
$field = 'relname';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'firebird':
|
|
||||||
$sql = 'SELECT rdb$relation_name
|
|
||||||
FROM rdb$relations
|
|
||||||
WHERE rdb$view_source is null
|
|
||||||
AND rdb$system_flag = 0';
|
|
||||||
$field = 'rdb$relation_name';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'oracle':
|
|
||||||
$sql = 'SELECT table_name
|
|
||||||
FROM USER_TABLES';
|
|
||||||
$field = 'table_name';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$result = $db->sql_query($sql);
|
|
||||||
|
|
||||||
if ($row = $db->sql_fetchrow($result))
|
|
||||||
{
|
{
|
||||||
// Likely matches for an existing phpBB installation
|
// Likely matches for an existing phpBB installation
|
||||||
|
if (!$prefix_may_exist)
|
||||||
|
{
|
||||||
$temp_prefix = strtolower($table_prefix);
|
$temp_prefix = strtolower($table_prefix);
|
||||||
$table_ary = array($temp_prefix . 'attachments', $temp_prefix . 'config', $temp_prefix . 'sessions', $temp_prefix . 'topics', $temp_prefix . 'users');
|
$table_ary = array($temp_prefix . 'attachments', $temp_prefix . 'config', $temp_prefix . 'sessions', $temp_prefix . 'topics', $temp_prefix . 'users');
|
||||||
|
|
||||||
do
|
$tables = get_tables($db);
|
||||||
{
|
$table_intersect = array_intersect($tables, $table_ary);
|
||||||
// All phpBB installations will at least have config else it won't work
|
|
||||||
if (in_array(strtolower($row[$field]), $table_ary))
|
if (sizeof($table_intersect))
|
||||||
{
|
|
||||||
if (!$prefix_may_exist)
|
|
||||||
{
|
{
|
||||||
$error[] = $lang['INST_ERR_PREFIX'];
|
$error[] = $lang['INST_ERR_PREFIX'];
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
while ($row = $db->sql_fetchrow($result));
|
|
||||||
}
|
|
||||||
$db->sql_freeresult($result);
|
|
||||||
|
|
||||||
// Make sure that the user has selected a sensible DBAL for the DBMS actually installed
|
// Make sure that the user has selected a sensible DBAL for the DBMS actually installed
|
||||||
switch ($dbms['DRIVER'])
|
switch ($dbms['DRIVER'])
|
||||||
|
|
|
@ -445,22 +445,13 @@ class install_convert extends module
|
||||||
if (!$result)
|
if (!$result)
|
||||||
{
|
{
|
||||||
$prefixes = array();
|
$prefixes = array();
|
||||||
// TODO: fixme
|
|
||||||
if ($result = $src_db->sql_query('SHOW TABLES'))
|
$tables_existing = get_tables($src_db);
|
||||||
|
foreach ($tables_existing as $table_name)
|
||||||
{
|
{
|
||||||
while ($row = $src_db->sql_fetchrow($result))
|
compare_table($tables, $table_name, $prefixes);
|
||||||
{
|
|
||||||
if (sizeof($row) > 1)
|
|
||||||
{
|
|
||||||
compare_table($tables, $row[0], $prefixes);
|
|
||||||
}
|
|
||||||
else if (list(, $tablename) = @each($row))
|
|
||||||
{
|
|
||||||
compare_table($tables, $tablename, $prefixes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$src_db->sql_freeresult($result);
|
|
||||||
}
|
}
|
||||||
|
unset($tables_existing);
|
||||||
|
|
||||||
foreach ($prefixes as $prefix => $count)
|
foreach ($prefixes as $prefix => $count)
|
||||||
{
|
{
|
||||||
|
|
|
@ -50,6 +50,7 @@ $lang = array_merge($lang, array(
|
||||||
'FILE_TYPE' => 'File type',
|
'FILE_TYPE' => 'File type',
|
||||||
'FULL_BACKUP' => 'Full',
|
'FULL_BACKUP' => 'Full',
|
||||||
|
|
||||||
|
'RESTORE_FAILURE' => 'The backup file may be corrupt.',
|
||||||
'RESTORE_OPTIONS' => 'Restore options',
|
'RESTORE_OPTIONS' => 'Restore options',
|
||||||
'RESTORE_SUCCESS' => 'The database has been successfully restored.<br /><br />Your board should be back to the state it was when the backup was made.',
|
'RESTORE_SUCCESS' => 'The database has been successfully restored.<br /><br />Your board should be back to the state it was when the backup was made.',
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue