Removed support to drop conflicting database tables
authorAlexander Ebert <ebert@woltlab.com>
Thu, 16 May 2013 13:11:38 +0000 (15:11 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 16 May 2013 13:11:38 +0000 (15:11 +0200)
wcfsetup/install/files/lib/system/WCFSetup.class.php
wcfsetup/install/files/lib/system/database/editor/DatabaseEditor.class.php
wcfsetup/install/files/lib/system/database/editor/MySQLDatabaseEditor.class.php
wcfsetup/install/files/lib/system/database/editor/PostgreSQLDatabaseEditor.class.php
wcfsetup/install/files/lib/system/package/plugin/SQLPackageInstallationPlugin.class.php
wcfsetup/setup/template/stepConfigureDB.tpl

index 593061cc464fe0b1b3015267790f389f509086fd..2744342c5431e76a2d8430e2d7c40b2d7a67555a 100644 (file)
@@ -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');
index fc9cc59ef420ef45ea69b1f683387b0e45d4188f..82b029fcdb06e144d96bba379754d11c5b8f5646 100644 (file)
@@ -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);
 }
index 29c1b1703e5e008bbfe0980bf2da67470d519878..b015ba9dd1f00202dd01a0b61dbc27e98304befe 100644 (file)
@@ -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);
-               }
-       }
 }
index 51bf2519fb65b173d5e869c8774ba1250620b524..e9a852340387fd3b8d427d04937208a679fd3bde 100644 (file)
@@ -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');
-       }
 }
index 54c8bb1d1bc475ff1179bd9d66f8cefa07d7774f..89dc96a88c02b89b987f68dc1a7e039fec537990 100644 (file)
@@ -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('<br />', $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('<br />', $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
index ce6a95bf700849b7fb282f76fe31364fc5405be4..0101b0b49da41fd3663fd5375408059cd7563970 100644 (file)
                                        <small>{lang}wcf.global.configureDB.number.description{/lang}</small>
                                </dd>
                        </dl>
-                       
-                       {if $conflictedTables|isset}
-                               <dl>
-                                       <dd><label><input type="checkbox" name="overwriteTables" value="1" /> {lang}wcf.global.configureDB.conflictedTables.overwrite{/lang}</label></dd>
-                               </dl>
-                       {/if}
-                       
                </fieldset>
        </div>