aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid M <davidmj@users.sourceforge.net>2007-02-19 19:35:52 +0000
committerDavid M <davidmj@users.sourceforge.net>2007-02-19 19:35:52 +0000
commit59fdd2edca9455126c6ce606ba2819aa6450dfda (patch)
tree594260670a88be3ea7b580534280aaf211c029c8
parentbf8bea4967c50ba61c6bd897d3611fccdac24bee (diff)
downloadforums-59fdd2edca9455126c6ce606ba2819aa6450dfda.tar
forums-59fdd2edca9455126c6ce606ba2819aa6450dfda.tar.gz
forums-59fdd2edca9455126c6ce606ba2819aa6450dfda.tar.bz2
forums-59fdd2edca9455126c6ce606ba2819aa6450dfda.tar.xz
forums-59fdd2edca9455126c6ce606ba2819aa6450dfda.zip
#8234
- some stupid bugs in restore - centralized the method of getting tables git-svn-id: file:///svn/phpbb/trunk@7015 89ea8834-ac86-4346-8a33-228a782c2dd0
-rw-r--r--phpBB/includes/functions_convert.php2
-rw-r--r--phpBB/includes/functions_install.php131
-rw-r--r--phpBB/install/install_convert.php19
-rw-r--r--phpBB/language/en/acp/database.php1
4 files changed, 77 insertions, 76 deletions
diff --git a/phpBB/includes/functions_convert.php b/phpBB/includes/functions_convert.php
index e8c57a4db6..914311c2b8 100644
--- a/phpBB/includes/functions_convert.php
+++ b/phpBB/includes/functions_convert.php
@@ -1374,7 +1374,7 @@ function get_path($src_path, $src_url, $test_file)
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))
{
diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php
index 0906e5e1b1..29eb0d3dc6 100644
--- a/phpBB/includes/functions_install.php
+++ b/phpBB/includes/functions_install.php
@@ -182,6 +182,69 @@ function dbms_select($default = '', $only_20x_options = false)
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
@@ -264,74 +327,20 @@ function connect_check_db($error_connect, &$error, $dbms, $table_prefix, $dbhost
}
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
+ if (!$prefix_may_exist)
{
- // Likely matches for an existing phpBB installation
$temp_prefix = strtolower($table_prefix);
$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);
+
+ if (sizeof($table_intersect))
{
- // All phpBB installations will at least have config else it won't work
- if (in_array(strtolower($row[$field]), $table_ary))
- {
- if (!$prefix_may_exist)
- {
- $error[] = $lang['INST_ERR_PREFIX'];
- }
- break;
- }
+ $error[] = $lang['INST_ERR_PREFIX'];
}
- 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
switch ($dbms['DRIVER'])
diff --git a/phpBB/install/install_convert.php b/phpBB/install/install_convert.php
index 0986ef42f9..c7432aeb42 100644
--- a/phpBB/install/install_convert.php
+++ b/phpBB/install/install_convert.php
@@ -445,22 +445,13 @@ class install_convert extends module
if (!$result)
{
$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))
- {
- 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);
+ compare_table($tables, $table_name, $prefixes);
}
+ unset($tables_existing);
foreach ($prefixes as $prefix => $count)
{
diff --git a/phpBB/language/en/acp/database.php b/phpBB/language/en/acp/database.php
index a59ebc416f..b8b423d08a 100644
--- a/phpBB/language/en/acp/database.php
+++ b/phpBB/language/en/acp/database.php
@@ -50,6 +50,7 @@ $lang = array_merge($lang, array(
'FILE_TYPE' => 'File type',
'FULL_BACKUP' => 'Full',
+ 'RESTORE_FAILURE' => 'The backup file may be corrupt.',
'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.',