From 840ba5e8c1f98d2d7ca59c93f440a188e38fc513 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 16 May 2013 15:11:38 +0200 Subject: [PATCH] Removed support to drop conflicting database tables --- .../files/lib/system/WCFSetup.class.php | 11 +-- .../database/editor/DatabaseEditor.class.php | 7 -- .../editor/MySQLDatabaseEditor.class.php | 72 ------------------- .../editor/PostgreSQLDatabaseEditor.class.php | 7 -- .../SQLPackageInstallationPlugin.class.php | 63 ++-------------- wcfsetup/setup/template/stepConfigureDB.tpl | 7 -- 6 files changed, 6 insertions(+), 161 deletions(-) diff --git a/wcfsetup/install/files/lib/system/WCFSetup.class.php b/wcfsetup/install/files/lib/system/WCFSetup.class.php index 593061cc46..2744342c54 100644 --- a/wcfsetup/install/files/lib/system/WCFSetup.class.php +++ b/wcfsetup/install/files/lib/system/WCFSetup.class.php @@ -580,17 +580,12 @@ class WCFSetup extends WCF { $dbClass = $dbClass['class']; break; } - $overwriteTables = false; if (isset($_POST['send'])) { if (isset($_POST['dbHost'])) $dbHost = $_POST['dbHost']; if (isset($_POST['dbUser'])) $dbUser = $_POST['dbUser']; if (isset($_POST['dbPassword'])) $dbPassword = $_POST['dbPassword']; if (isset($_POST['dbName'])) $dbName = $_POST['dbName']; - if (isset($_POST['overwriteTables'])) $overwriteTables = intval($_POST['overwriteTables']); - // Should the user not be prompted if converted or default n match an - // existing installation number? By now the existing installation - // will be overwritten just so! // ensure that $dbNumber is zero or a positive integer if (isset($_POST['dbNumber'])) $dbNumber = max(0, intval($_POST['dbNumber'])); @@ -635,13 +630,9 @@ class WCFSetup extends WCF { // check for table conflicts $conflictedTables = $this->getConflictedTables($db, $dbNumber); - if (!empty($conflictedTables) && ($overwriteTables || self::$developerMode)) { - // remove tables - $db->getEditor()->dropConflictedTables($conflictedTables); - } // write config.inc - if (empty($conflictedTables) || $overwriteTables || self::$developerMode) { + if (empty($conflictedTables)) { // connection successfully established // write configuration to config.inc.php $file = new File(WCF_DIR.'config.inc.php'); diff --git a/wcfsetup/install/files/lib/system/database/editor/DatabaseEditor.class.php b/wcfsetup/install/files/lib/system/database/editor/DatabaseEditor.class.php index fc9cc59ef4..82b029fcdb 100644 --- a/wcfsetup/install/files/lib/system/database/editor/DatabaseEditor.class.php +++ b/wcfsetup/install/files/lib/system/database/editor/DatabaseEditor.class.php @@ -127,11 +127,4 @@ abstract class DatabaseEditor { * @param string $indexName */ abstract public function dropForeignKey($tableName, $indexName); - - /** - * Drops all given databases. - * - * @param array $conflictedTables - */ - abstract public function dropConflictedTables(array $conflictedTables); } diff --git a/wcfsetup/install/files/lib/system/database/editor/MySQLDatabaseEditor.class.php b/wcfsetup/install/files/lib/system/database/editor/MySQLDatabaseEditor.class.php index 29c1b1703e..b015ba9dd1 100644 --- a/wcfsetup/install/files/lib/system/database/editor/MySQLDatabaseEditor.class.php +++ b/wcfsetup/install/files/lib/system/database/editor/MySQLDatabaseEditor.class.php @@ -239,76 +239,4 @@ class MySQLDatabaseEditor extends DatabaseEditor { return $definition; } - - /** - * @see wcf\system\database\editor\DatabaseEditor::dropConflictedTables() - */ - public function dropConflictedTables(array $conflictedTables) { - $tables = array(); - foreach ($conflictedTables as $tableName) { - $tables[$tableName] = array(); - } - - // get current database - $sql = "SELECT DATABASE() AS currentDB"; - $statement = $this->dbObj->prepareStatement($sql); - $statement->execute(); - $row = $statement->fetchArray(); - $currentDB = $row['currentDB']; - - // get constraints - $conditions = new PreparedStatementConditionBuilder(); - $conditions->add("TABLE_SCHEMA = ?", array($currentDB)); - $conditions->add("TABLE_NAME IN (?)", array($conflictedTables)); - $conditions->add("REFERENCED_TABLE_NAME IS NOT NULL"); - $conditions->add("CONSTRAINT_NAME LIKE ?", array('%_fk')); - - $sql = "SELECT CONSTRAINT_NAME, TABLE_NAME - FROM information_schema.KEY_COLUMN_USAGE - ".$conditions; - $statement = $this->dbObj->prepareStatement($sql); - $statement->execute($conditions->getParameters()); - while ($row = $statement->fetchArray()) { - $tables[$row['TABLE_NAME']][] = $row['CONSTRAINT_NAME']; - } - - // handle foreign keys from 3rd party tables - $conditions = new PreparedStatementConditionBuilder(); - $conditions->add("TABLE_SCHEMA = ?", array($currentDB)); - $conditions->add("REFERENCED_TABLE_NAME IN (?)", array($conflictedTables)); - $conditions->add("CONSTRAINT_NAME LIKE ?", array('%_fk')); - - $sql = "SELECT CONSTRAINT_NAME, TABLE_NAME - FROM information_schema.KEY_COLUMN_USAGE - ".$conditions; - $statement = $this->dbObj->prepareStatement($sql); - $statement->execute($conditions->getParameters()); - $foreignConstraints = array(); - while ($row = $statement->fetchArray()) { - if (!isset($foreignConstraints[$row['TABLE_NAME']])) { - $foreignConstraints[$row['TABLE_NAME']] = array(); - } - - $foreignConstraints[$row['TABLE_NAME']][] = $row['CONSTRAINT_NAME']; - } - - // drop foreign keys from 3rd party tables - foreach ($foreignConstraints as $tableName => $foreignKeys) { - foreach ($foreignKeys as $fk) { - $this->dropForeignKey($tableName, $fk); - } - } - - // drop foreign keys - foreach ($tables as $tableName => $foreignKeys) { - foreach ($foreignKeys as $fk) { - $this->dropForeignKey($tableName, $fk); - } - } - - // drop tables - foreach (array_keys($tables) as $tableName) { - $this->dropTable($tableName); - } - } } diff --git a/wcfsetup/install/files/lib/system/database/editor/PostgreSQLDatabaseEditor.class.php b/wcfsetup/install/files/lib/system/database/editor/PostgreSQLDatabaseEditor.class.php index 51bf2519fb..e9a8523403 100644 --- a/wcfsetup/install/files/lib/system/database/editor/PostgreSQLDatabaseEditor.class.php +++ b/wcfsetup/install/files/lib/system/database/editor/PostgreSQLDatabaseEditor.class.php @@ -438,11 +438,4 @@ class PostgreSQLDatabaseEditor extends DatabaseEditor { throw new DatabaseException("Unknown / unsupported data type '".$mySQLType."'", $this->dbObj); } - - /** - * @see wcf\system\database\editor\DatabaseEditor::dropConflictedTables() - */ - public function dropConflictedTables(array $conflictedTables) { - die('IMPLEMENT ME: PostgreSQLDatabaseEditor::dropConflictedTables'); - } } diff --git a/wcfsetup/install/files/lib/system/package/plugin/SQLPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/SQLPackageInstallationPlugin.class.php index 54c8bb1d1b..89dc96a88c 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/SQLPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/SQLPackageInstallationPlugin.class.php @@ -51,65 +51,12 @@ class SQLPackageInstallationPlugin extends AbstractPackageInstallationPlugin { // check queries $parser = new PackageInstallationSQLParser($queries, $this->installation->getPackage(), $this->installation->getAction()); $conflicts = $parser->test(); - if (!empty($conflicts)) { - if (isset($conflicts['CREATE TABLE']) || isset($conflicts['DROP TABLE'])) { - if (!PackageInstallationFormManager::findForm($this->installation->queue, 'overwriteDatabaseTables')) { - $container = new GroupFormElementContainer(); - - if (isset($conflicts['CREATE TABLE'])) { - $text = implode('
', $conflicts['CREATE TABLE']); - $label = WCF::getLanguage()->get('wcf.acp.package.error.sql.createTable'); - $description = WCF::getLanguage()->get('wcf.acp.package.error.sql.createTable.description'); - - $element = new LabelFormElement($container); - $element->setLabel($label); - $element->setText($text); - $element->setDescription($description); - $container->appendChild($element); - } - - if (isset($conflicts['DROP TABLE'])) { - $text = implode('
', $conflicts['DROP TABLE']); - $label = WCF::getLanguage()->get('wcf.acp.package.error.sql.dropTable'); - $description = WCF::getLanguage()->get('wcf.acp.package.error.sql.dropTable.description'); - - $element = new LabelFormElement($container); - $element->setLabel($label); - $element->setText($text); - $element->setDescription($description); - $container->appendChild($element); - } - - $document = new FormDocument('overwriteDatabaseTables'); - $document->appendContainer($container); - - PackageInstallationFormManager::registerForm($this->installation->queue, $document); - return $document; - } - else { - /* - * At this point the user decided to continue the installation (he would called the rollback - * otherwise), thus we do not care about the form anymore - */ - } - } + if (!empty($conflicts) && (isset($conflicts['CREATE TABLE']) || isset($conflicts['DROP TABLE']))) { + WCF::getTPL()->assign(array( + 'conflicts' => $conflicts + )); - // ask user here - // search default value in session - if (!WCF::getSession()->getVar('overrideAndDontAskAgain')) { - // show page - if (!empty($_POST['override']) || !empty($_POST['overrideAndDontAskAgain'])) { - if (!empty($_POST['overrideAndDontAskAgain'])) { - WCF::getSession()->register('overrideAndDontAskAgain', true); - WCF::getSession()->update(); - } - } - else { - WCF::getTPL()->assign('conflicts', $conflicts); - WCF::getTPL()->display('packageInstallationCheckOverrideTables'); - exit; - } - } + throw new SystemException(WCF::getTPL()->fetch('packageInstallationDatabaseConflict')); } // execute queries diff --git a/wcfsetup/setup/template/stepConfigureDB.tpl b/wcfsetup/setup/template/stepConfigureDB.tpl index ce6a95bf70..0101b0b49d 100644 --- a/wcfsetup/setup/template/stepConfigureDB.tpl +++ b/wcfsetup/setup/template/stepConfigureDB.tpl @@ -59,13 +59,6 @@ {lang}wcf.global.configureDB.number.description{/lang} - - {if $conflictedTables|isset} -
-
-
- {/if} - -- 2.20.1