2 namespace TYPO3\CMS\Install\Controller\Action\Tool;
18 use TYPO3\CMS\Install\Controller\Action;
34 if (isset($this->postValues[
'set'][
'changeEncryptionKey'])) {
35 $this->setNewEncryptionKeyAndLogOut();
38 $actionMessages = array();
39 if (isset($this->postValues[
'set'][
'changeInstallToolPassword'])) {
40 $actionMessages[] = $this->changeInstallToolPassword();
42 if (isset($this->postValues[
'set'][
'changeSiteName'])) {
43 $actionMessages[] = $this->changeSiteName();
45 if (isset($this->postValues[
'set'][
'createAdministrator'])) {
46 $actionMessages[] = $this->createAdministrator();
48 if (isset($this->postValues[
'set'][
'clearAllCache'])) {
49 $actionMessages[] = $this->clearAllCache();
51 if (isset($this->postValues[
'set'][
'clearOpcodeCache'])) {
56 if (isset($this->postValues[
'set'][
'databaseAnalyzerExecute'])
57 || isset($this->postValues[
'set'][
'databaseAnalyzerAnalyze'])
61 if (isset($this->postValues[
'set'][
'databaseAnalyzerExecute'])) {
62 $actionMessages = array_merge($actionMessages, $this->databaseAnalyzerExecute());
64 if (isset($this->postValues[
'set'][
'databaseAnalyzerAnalyze'])) {
65 $actionMessages[] = $this->databaseAnalyzerAnalyze();
68 $this->view->assign(
'actionMessages', $actionMessages);
70 $operatingSystem = TYPO3_OS ===
'WIN' ?
'Windows' :
'Unix';
75 $coreUpdateService = $this->objectManager->get(\TYPO3\CMS\Install\Service\CoreUpdateService::class);
77 ->assign(
'enableCoreUpdate', $coreUpdateService->isCoreUpdateEnabled())
79 ->assign(
'operatingSystem', $operatingSystem)
81 ->assign(
'databaseName',
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'database'])
82 ->assign(
'databaseUsername',
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'username'])
83 ->assign(
'databaseHost',
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'host'])
84 ->assign(
'databasePort',
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'port'])
85 ->assign(
'databaseSocket',
$GLOBALS[
'TYPO3_CONF_VARS'][
'DB'][
'socket'])
86 ->assign(
'databaseNumberOfTables', count($this->getDatabaseConnection()->admin_get_tables()))
87 ->assign(
'extensionCompatibilityTesterProtocolFile',
GeneralUtility::getIndpEnv(
'TYPO3_SITE_URL') .
'typo3temp/ExtensionCompatibilityTester.txt')
88 ->assign(
'extensionCompatibilityTesterErrorProtocolFile',
GeneralUtility::getIndpEnv(
'TYPO3_SITE_URL') .
'typo3temp/ExtensionCompatibilityTesterErrors.json')
89 ->assign(
'extensionCompatibilityTesterMessages', $this->getExtensionCompatibilityTesterMessages())
90 ->assign(
'listOfOpcodeCaches', $opcodeCacheService->getAllActive());
92 return $this->view->render();
100 protected function changeInstallToolPassword()
102 $values = $this->postValues[
'values'];
103 if ($values[
'newInstallToolPassword'] !== $values[
'newInstallToolPasswordCheck']) {
105 $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
106 $message->setTitle(
'Install tool password not changed');
107 $message->setMessage(
'Given passwords do not match.');
108 }
elseif (strlen($values[
'newInstallToolPassword']) < 8) {
110 $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
111 $message->setTitle(
'Install tool password not changed');
112 $message->setMessage(
'Given password must be at least eight characters long.');
115 $configurationManager = $this->objectManager->get(\TYPO3\CMS\Core\
Configuration\ConfigurationManager::class);
116 $configurationManager->setLocalConfigurationValueByPath(
117 'BE/installToolPassword',
121 $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\OkStatus::class);
122 $message->setTitle(
'Install tool password changed');
132 protected function changeSiteName()
134 $values = $this->postValues[
'values'];
135 if (isset($values[
'newSiteName']) && $values[
'newSiteName'] !==
'') {
137 $configurationManager = $this->objectManager->get(\TYPO3\CMS\Core\
Configuration\ConfigurationManager::class);
138 $configurationManager->setLocalConfigurationValueByPath(
'SYS/sitename', $values[
'newSiteName']);
140 $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\OkStatus::class);
141 $message->setTitle(
'Site name changed');
142 $this->view->assign(
'siteName', $values[
'newSiteName']);
145 $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
146 $message->setTitle(
'Site name not changed');
147 $message->setMessage(
'Site name must be at least one character long.');
157 protected function clearAllCache()
160 $clearCacheService = $this->objectManager->get(\TYPO3\CMS\Install\Service\ClearCacheService::class);
161 $clearCacheService->clearAll();
162 $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\OkStatus::class);
163 $message->setTitle(
'Successfully cleared all caches');
175 $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\OkStatus::class);
176 $message->setTitle(
'Successfully cleared all available opcode caches');
185 protected function setNewEncryptionKeyAndLogOut()
187 $newKey = \TYPO3\CMS\Core\Utility\GeneralUtility::getRandomHexString(96);
189 $configurationManager = $this->objectManager->get(\TYPO3\CMS\Core\
Configuration\ConfigurationManager::class);
190 $configurationManager->setLocalConfigurationValueByPath(
'SYS/encryptionKey', $newKey);
192 $formProtection = \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get(
193 \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection::class
195 $formProtection->clean();
197 $session = $this->objectManager->get(\TYPO3\CMS\Install\Service\SessionService::class);
198 $session->destroySession();
199 \TYPO3\CMS\Core\Utility\HttpUtility::redirect(
'Install.php?install[context]=' . $this->
getContext());
207 protected function createAdministrator()
209 $values = $this->postValues[
'values'];
210 $username = preg_replace(
'/\\s/i',
'', $values[
'newUserUsername']);
211 $password = $values[
'newUserPassword'];
212 $passwordCheck = $values[
'newUserPasswordCheck'];
214 if (strlen($username) < 1) {
216 $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
217 $message->setTitle(
'Administrator user not created');
218 $message->setMessage(
'No valid username given.');
219 }
elseif ($password !== $passwordCheck) {
221 $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
222 $message->setTitle(
'Administrator user not created');
223 $message->setMessage(
'Passwords do not match.');
224 }
elseif (strlen($password) < 8) {
226 $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
227 $message->setTitle(
'Administrator user not created');
228 $message->setMessage(
'Password must be at least eight characters long.');
230 $database = $this->getDatabaseConnection();
231 $userExists = $database->exec_SELECTcountRows(
234 'username=' . $database->fullQuoteStr($username,
'be_users')
238 $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
239 $message->setTitle(
'Administrator user not created');
240 $message->setMessage(
'A user with username "' . $username .
'" exists already.');
243 $adminUserFields = array(
244 'username' => $username,
245 'password' => $hashedPassword,
250 $database->exec_INSERTquery(
'be_users', $adminUserFields);
252 $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\OkStatus::class);
253 $message->setTitle(
'Administrator created with username "' . $username .
'".');
265 protected function databaseAnalyzerExecute()
270 if (empty($this->postValues[
'values'])) {
272 $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\WarningStatus::class);
273 $message->setTitle(
'No database changes selected');
279 $schemaMigrationService = $this->objectManager->get(\TYPO3\CMS\Install\Service\SqlSchemaMigrationService::class);
281 $expectedSchemaService = $this->objectManager->get(\TYPO3\CMS\Install\Service\SqlExpectedSchemaService::class);
282 $expectedSchema = $expectedSchemaService->getExpectedDatabaseSchema();
283 $currentSchema = $schemaMigrationService->getFieldDefinitions_database();
285 $statementHashesToPerform = $this->postValues[
'values'];
290 $addCreateChange = $schemaMigrationService->getDatabaseExtra($expectedSchema, $currentSchema);
291 $addCreateChange = $schemaMigrationService->getUpdateSuggestions($addCreateChange);
292 $results[] = $schemaMigrationService->performUpdateQueries($addCreateChange[
'add'], $statementHashesToPerform);
293 $results[] = $schemaMigrationService->performUpdateQueries($addCreateChange[
'change'], $statementHashesToPerform);
294 $results[] = $schemaMigrationService->performUpdateQueries($addCreateChange[
'create_table'], $statementHashesToPerform);
297 $dropRename = $schemaMigrationService->getDatabaseExtra($currentSchema, $expectedSchema);
298 $dropRename = $schemaMigrationService->getUpdateSuggestions($dropRename,
'remove');
299 $results[] = $schemaMigrationService->performUpdateQueries($dropRename[
'change'], $statementHashesToPerform);
300 $results[] = $schemaMigrationService->performUpdateQueries($dropRename[
'drop'], $statementHashesToPerform);
301 $results[] = $schemaMigrationService->performUpdateQueries($dropRename[
'change_table'], $statementHashesToPerform);
302 $results[] = $schemaMigrationService->performUpdateQueries($dropRename[
'drop_table'], $statementHashesToPerform);
305 foreach ($results as $resultSet) {
306 if (is_array($resultSet)) {
307 foreach ($resultSet as $errorMessage) {
309 $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\ErrorStatus::class);
310 $message->setTitle(
'Database update failed');
311 $message->setMessage(
'Error: ' . $errorMessage);
318 $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\OkStatus::class);
319 $message->setTitle(
'Executed database updates');
332 protected function databaseAnalyzerAnalyze()
335 $schemaMigrationService = $this->objectManager->get(\TYPO3\CMS\Install\Service\SqlSchemaMigrationService::class);
337 $expectedSchemaService = $this->objectManager->get(\TYPO3\CMS\Install\Service\SqlExpectedSchemaService::class);
338 $expectedSchema = $expectedSchemaService->getExpectedDatabaseSchema();
340 $currentSchema = $schemaMigrationService->getFieldDefinitions_database();
342 $databaseAnalyzerSuggestion = array();
345 $addCreateChange = $schemaMigrationService->getDatabaseExtra($expectedSchema, $currentSchema);
346 $addCreateChange = $schemaMigrationService->getUpdateSuggestions($addCreateChange);
347 if (isset($addCreateChange[
'create_table'])) {
348 $databaseAnalyzerSuggestion[
'addTable'] = array();
349 foreach ($addCreateChange[
'create_table'] as $hash => $statement) {
350 $databaseAnalyzerSuggestion[
'addTable'][$hash] = array(
352 'statement' => $statement,
356 if (isset($addCreateChange[
'add'])) {
357 $databaseAnalyzerSuggestion[
'addField'] = array();
358 foreach ($addCreateChange[
'add'] as $hash => $statement) {
359 $databaseAnalyzerSuggestion[
'addField'][$hash] = array(
361 'statement' => $statement,
365 if (isset($addCreateChange[
'change'])) {
366 $databaseAnalyzerSuggestion[
'change'] = array();
367 foreach ($addCreateChange[
'change'] as $hash => $statement) {
368 $databaseAnalyzerSuggestion[
'change'][$hash] = array(
370 'statement' => $statement,
372 if (isset($addCreateChange[
'change_currentValue'][$hash])) {
373 $databaseAnalyzerSuggestion[
'change'][$hash][
'current'] = $addCreateChange[
'change_currentValue'][$hash];
379 $dropRename = $schemaMigrationService->getDatabaseExtra($currentSchema, $expectedSchema);
380 $dropRename = $schemaMigrationService->getUpdateSuggestions($dropRename,
'remove');
381 if (isset($dropRename[
'change_table'])) {
382 $databaseAnalyzerSuggestion[
'renameTableToUnused'] = array();
383 foreach ($dropRename[
'change_table'] as $hash => $statement) {
384 $databaseAnalyzerSuggestion[
'renameTableToUnused'][$hash] = array(
386 'statement' => $statement,
388 if (!empty($dropRename[
'tables_count'][$hash])) {
389 $databaseAnalyzerSuggestion[
'renameTableToUnused'][$hash][
'count'] = $dropRename[
'tables_count'][$hash];
393 if (isset($dropRename[
'change'])) {
394 $databaseAnalyzerSuggestion[
'renameTableFieldToUnused'] = array();
395 foreach ($dropRename[
'change'] as $hash => $statement) {
396 $databaseAnalyzerSuggestion[
'renameTableFieldToUnused'][$hash] = array(
398 'statement' => $statement,
402 if (isset($dropRename[
'drop'])) {
403 $databaseAnalyzerSuggestion[
'deleteField'] = array();
404 foreach ($dropRename[
'drop'] as $hash => $statement) {
405 $databaseAnalyzerSuggestion[
'deleteField'][$hash] = array(
407 'statement' => $statement,
411 if (isset($dropRename[
'drop_table'])) {
412 $databaseAnalyzerSuggestion[
'deleteTable'] = array();
413 foreach ($dropRename[
'drop_table'] as $hash => $statement) {
414 $databaseAnalyzerSuggestion[
'deleteTable'][$hash] = array(
416 'statement' => $statement,
418 if (!empty($dropRename[
'tables_count'][$hash])) {
419 $databaseAnalyzerSuggestion[
'deleteTable'][$hash][
'count'] = $dropRename[
'tables_count'][$hash];
424 $this->view->assign(
'databaseAnalyzerSuggestion', $databaseAnalyzerSuggestion);
427 $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\OkStatus::class);
428 $message->setTitle(
'Analyzed current database');