$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']));
// 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');
* @param string $indexName
*/
abstract public function dropForeignKey($tableName, $indexName);
-
- /**
- * Drops all given databases.
- *
- * @param array $conflictedTables
- */
- abstract public function dropConflictedTables(array $conflictedTables);
}
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);
- }
- }
}
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');
- }
}
// 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
<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>