/** * @test */ public function columnAndKeyDeletionDoesNotReturnAnError() { // Get the current database fields. $currentDatabaseSchema = $this->sqlSchemaMigrationService->getFieldDefinitions_database(); // Limit our scope to the be_users table: $currentDatabaseSchemaForBeUsers = array(); $currentDatabaseSchemaForBeUsers['be_users'] = $currentDatabaseSchema['be_users']; unset($currentDatabaseSchema); // Create a key and a field that belongs to that key: $expectedDatabaseSchemaForBeUsers = $currentDatabaseSchemaForBeUsers; $expectedDatabaseSchemaForBeUsers['be_users']['fields']['functional_test_field_1'] = "tinyint(1) unsigned NOT NULL default '0'"; $expectedDatabaseSchemaForBeUsers['be_users']['keys']['functional_test_key_1'] = 'KEY functional_test_key_1 (functional_test_field_1)'; $createFieldDiff = $this->sqlSchemaMigrationService->getDatabaseExtra($expectedDatabaseSchemaForBeUsers, $currentDatabaseSchemaForBeUsers); $createFieldDiff = $this->sqlSchemaMigrationService->getUpdateSuggestions($createFieldDiff); $this->sqlSchemaMigrationService->performUpdateQueries($createFieldDiff['add'], $createFieldDiff['add']); // Now remove the fields again (without the renaming step). unset($currentDatabaseSchemaForBeUsers['be_users']['fields']['functional_test_field_1']); unset($currentDatabaseSchemaForBeUsers['be_users']['keys']['functional_test_key_1']); $this->sqlSchemaMigrationService->setDeletedPrefixKey(''); $removeFieldDiff = $this->sqlSchemaMigrationService->getDatabaseExtra($expectedDatabaseSchemaForBeUsers, $currentDatabaseSchemaForBeUsers); $removeFieldDiff = $this->sqlSchemaMigrationService->getUpdateSuggestions($removeFieldDiff, 'remove'); $result = $this->sqlSchemaMigrationService->performUpdateQueries($removeFieldDiff['drop'], $removeFieldDiff['drop']); $this->assertTrue($result, 'performUpdateQueries() did not return TRUE, this means an error occurred: ' . (is_array($result) ? array_pop($result) : '')); }
/** * Executes the database structure updates. * * @param array $arguments Optional arguemtns passed to this action * @param boolean $allowKeyModifications Whether to allow key modifications * @return string */ protected function executeUpdateStructure(array $arguments, $isRemovalEnabled, $allowKeyModifications = FALSE) { $result = ''; $isExcuteEnabled = isset($arguments['--execute']) || isset($arguments['-e']); $isRemovalEnabled = isset($arguments['--remove']) || isset($arguments['-r']); $isVerboseEnabled = isset($arguments['--verbose']) || isset($arguments['-v']); $database = isset($arguments['--database']) && $arguments['--database'] ? $arguments['--database'] : TYPO3_db; $changes = $this->install->getUpdateSuggestions($this->getStructureDifferencesForUpdate($database, $allowKeyModifications)); if ($isRemovalEnabled) { // Disable the delete prefix, thus tables and fields can be removed directly: $this->install->setDeletedPrefixKey(''); // Add types considered for removal: $this->addConsideredTypes($this->getRemoveTypes()); // Merge update suggestions: $removals = $this->install->getUpdateSuggestions($this->getStructureDifferencesForRemoval($database, $allowKeyModifications), 'remove'); $changes = array_merge($changes, $removals); } if ($isExcuteEnabled || $isVerboseEnabled) { $statements = array(); // Concatenates all statements: foreach ($this->consideredTypes as $consideredType) { if (isset($changes[$consideredType]) && is_array($changes[$consideredType])) { $statements += $changes[$consideredType]; } } if ($isExcuteEnabled) { foreach ($statements as $statement) { $GLOBALS['TYPO3_DB']->admin_query($statement); } } if ($isVerboseEnabled) { $result = implode(PHP_EOL, $statements); } } return $result; }