[FEATURE] Add symfony dependency injection for core and extbase
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / MaintenanceController.php
index e6b7b25..25032a6 100644 (file)
@@ -20,6 +20,7 @@ use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Core\Configuration\ConfigurationManager;
 use TYPO3\CMS\Core\Core\ClassLoadingInformation;
 use TYPO3\CMS\Core\Core\Environment;
+use TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Schema\Exception\StatementException;
 use TYPO3\CMS\Core\Database\Schema\SchemaMigrator;
@@ -36,10 +37,10 @@ use TYPO3\CMS\Install\Service\ClearCacheService;
 use TYPO3\CMS\Install\Service\ClearTableService;
 use TYPO3\CMS\Install\Service\LanguagePackService;
 use TYPO3\CMS\Install\Service\Typo3tempFileService;
-use TYPO3\CMS\Saltedpasswords\Salt\SaltFactory;
 
 /**
  * Maintenance controller
+ * @internal This class is a specific controller implementation and is not considered part of the Public TYPO3 API.
  */
 class MaintenanceController extends AbstractController
 {
@@ -52,18 +53,6 @@ class MaintenanceController extends AbstractController
     public function cardsAction(ServerRequestInterface $request): ResponseInterface
     {
         $view = $this->initializeStandaloneView($request, 'Maintenance/Cards.html');
-        $formProtection = FormProtectionFactory::get(InstallToolFormProtection::class);
-        $view->assignMultiple([
-            'clearAllCacheOpcodeCaches' => (new OpcodeCacheService())->getAllActive(),
-            'clearTablesClearToken' => $formProtection->generateToken('installTool', 'clearTablesClear'),
-            'clearTypo3tempFilesToken' => $formProtection->generateToken('installTool', 'clearTypo3tempFiles'),
-            'createAdminToken' => $formProtection->generateToken('installTool', 'createAdmin'),
-            'databaseAnalyzerExecuteToken' => $formProtection->generateToken('installTool', 'databaseAnalyzerExecute'),
-            'languagePacksActivateLanguageToken' => $formProtection->generateToken('installTool', 'languagePacksActivateLanguage'),
-            'languagePacksDeactivateLanguageToken' => $formProtection->generateToken('installTool', 'languagePacksDeactivateLanguage'),
-            'languagePacksUpdatePackToken' => $formProtection->generateToken('installTool', 'languagePacksUpdatePack'),
-            'languagePacksUpdateIsoTimesToken' => $formProtection->generateToken('installTool', 'languagePacksUpdateIsoTimes'),
-        ]);
         return new JsonResponse([
             'success' => true,
             'html' => $view->render(),
@@ -91,7 +80,7 @@ class MaintenanceController extends AbstractController
     /**
      * Clear typo3temp files statistics action
      *
-     * @param $request ServerRequestInterface
+     * @param ServerRequestInterface $request
      * @return ResponseInterface
      */
     public function clearTypo3tempFilesStatsAction(ServerRequestInterface $request): ResponseInterface
@@ -106,12 +95,18 @@ class MaintenanceController extends AbstractController
                 'success' => true,
                 'stats' => (new Typo3tempFileService())->getDirectoryStatistics(),
                 'html' => $view->render(),
+                'buttons' => [
+                    [
+                        'btnClass' => 'btn-default t3js-clearTypo3temp-stats',
+                        'text' => 'Scan again',
+                    ],
+                ],
             ]
         );
     }
 
     /**
-     * Clear Processed Files
+     * Clear typo3temp/assets or FAL processed Files
      *
      * @param ServerRequestInterface $request
      * @return ResponseInterface
@@ -121,8 +116,14 @@ class MaintenanceController extends AbstractController
         $messageQueue = new FlashMessageQueue('install');
         $typo3tempFileService = new Typo3tempFileService();
         $folder = $request->getParsedBody()['install']['folder'];
-        if ($folder === '_processed_') {
-            $failedDeletions = $typo3tempFileService->clearProcessedFiles();
+        // storageUid is an optional post param if FAL storages should be cleaned
+        $storageUid = $request->getParsedBody()['install']['storageUid'] ?? null;
+        if ($storageUid === null) {
+            $typo3tempFileService->clearAssetsFolder($folder);
+            $messageQueue->enqueue(new FlashMessage('Cleared files in "' . $folder . '" folder'));
+        } else {
+            $storageUid = (int)$storageUid;
+            $failedDeletions = $typo3tempFileService->clearProcessedFiles($storageUid);
             if ($failedDeletions) {
                 $messageQueue->enqueue(new FlashMessage(
                     'Failed to delete ' . $failedDeletions . ' processed files. See TYPO3 log (by default typo3temp/var/log/typo3_*.log)',
@@ -132,9 +133,6 @@ class MaintenanceController extends AbstractController
             } else {
                 $messageQueue->enqueue(new FlashMessage('Cleared processed files'));
             }
-        } else {
-            $typo3tempFileService->clearAssetsFolder($folder);
-            $messageQueue->enqueue(new FlashMessage('Cleared files in "' . $folder . '" folder'));
         }
         return new JsonResponse([
             'success' => true,
@@ -152,8 +150,8 @@ class MaintenanceController extends AbstractController
         $messageQueue = new FlashMessageQueue('install');
         if (Environment::isComposerMode()) {
             $messageQueue->enqueue(new FlashMessage(
-                '',
                 'Skipped generating additional class loading information in composer mode.',
+                '',
                 FlashMessage::NOTICE
             ));
         } else {
@@ -169,24 +167,46 @@ class MaintenanceController extends AbstractController
     }
 
     /**
-     * Analyze current database situation
+     * Get main database analyzer modal HTML
      *
-     * @param $request ServerRequestInterface
+     * @param ServerRequestInterface $request
      * @return ResponseInterface
      */
-    public function databaseAnalyzerAnalyzeAction(ServerRequestInterface $request): ResponseInterface
+    public function databaseAnalyzerAction(ServerRequestInterface $request): ResponseInterface
     {
         $view = $this->initializeStandaloneView($request, 'Maintenance/DatabaseAnalyzer.html');
         $formProtection = FormProtectionFactory::get(InstallToolFormProtection::class);
         $view->assignMultiple([
             'databaseAnalyzerExecuteToken' => $formProtection->generateToken('installTool', 'databaseAnalyzerExecute'),
         ]);
-        $this->loadExtLocalconfDatabaseAndExtTables();
-        $messageQueue = new FlashMessageQueue('install');
+        return new JsonResponse([
+            'success' => true,
+            'html' => $view->render(),
+            'buttons' => [
+                [
+                    'btnClass' => 'btn-default t3js-databaseAnalyzer-analyze',
+                    'text' => 'Run database compare again',
+                ], [
+                    'btnClass' => 'btn-warning t3js-databaseAnalyzer-execute',
+                    'text' => 'Apply selected changes',
+                ],
+            ],
+        ]);
+    }
 
+    /**
+     * Analyze current database situation
+     *
+     * @param ServerRequestInterface $request
+     * @return ResponseInterface
+     */
+    public function databaseAnalyzerAnalyzeAction(ServerRequestInterface $request): ResponseInterface
+    {
+        $container = $this->loadExtLocalconfDatabaseAndExtTables();
+        $messageQueue = new FlashMessageQueue('install');
         $suggestions = [];
         try {
-            $sqlReader = GeneralUtility::makeInstance(SqlReader::class);
+            $sqlReader = $container->get(SqlReader::class);
             $sqlStatements = $sqlReader->getCreateTableStatementArray($sqlReader->getTablesDefinitionString());
             $schemaMigrationService = GeneralUtility::makeInstance(SchemaMigrator::class);
             $addCreateChange = $schemaMigrationService->getUpdateSuggestions($sqlStatements);
@@ -316,11 +336,6 @@ class MaintenanceController extends AbstractController
                 }
                 $suggestions[] = $suggestion;
             }
-
-            $messageQueue->enqueue(new FlashMessage(
-                '',
-                'Analyzed current database'
-            ));
         } catch (StatementException $e) {
             $messageQueue->enqueue(new FlashMessage(
                 $e->getMessage(),
@@ -332,7 +347,6 @@ class MaintenanceController extends AbstractController
             'success' => true,
             'status' => $messageQueue,
             'suggestions' => $suggestions,
-            'html' => $view->render(),
         ]);
     }
 
@@ -344,7 +358,7 @@ class MaintenanceController extends AbstractController
      */
     public function databaseAnalyzerExecuteAction(ServerRequestInterface $request): ResponseInterface
     {
-        $this->loadExtLocalconfDatabaseAndExtTables();
+        $container = $this->loadExtLocalconfDatabaseAndExtTables();
         $messageQueue = new FlashMessageQueue('install');
         $selectedHashes = $request->getParsedBody()['install']['hashes'] ?? [];
         if (empty($selectedHashes)) {
@@ -354,7 +368,7 @@ class MaintenanceController extends AbstractController
                 FlashMessage::WARNING
             ));
         } else {
-            $sqlReader = GeneralUtility::makeInstance(SqlReader::class);
+            $sqlReader = $container->get(SqlReader::class);
             $sqlStatements = $sqlReader->getCreateTableStatementArray($sqlReader->getTablesDefinitionString());
             $schemaMigrationService = GeneralUtility::makeInstance(SchemaMigrator::class);
             $statementHashesToPerform = array_flip($selectedHashes);
@@ -381,7 +395,7 @@ class MaintenanceController extends AbstractController
     /**
      * Clear table overview statistics action
      *
-     * @param $request ServerRequestInterface
+     * @param ServerRequestInterface $request
      * @return ResponseInterface
      */
     public function clearTablesStatsAction(ServerRequestInterface $request): ResponseInterface
@@ -395,6 +409,12 @@ class MaintenanceController extends AbstractController
             'success' => true,
             'stats' => (new ClearTableService())->getTableStatistics(),
             'html' => $view->render(),
+            'buttons' => [
+                [
+                    'btnClass' => 'btn-default t3js-clearTables-stats',
+                    'text' => 'Scan again',
+                ],
+            ],
         ]);
     }
 
@@ -426,7 +446,7 @@ class MaintenanceController extends AbstractController
     /**
      * Create Admin Get Data action
      *
-     * @param $request ServerRequestInterface
+     * @param ServerRequestInterface $request
      * @return ResponseInterface
      */
     public function createAdminGetDataAction(ServerRequestInterface $request): ResponseInterface
@@ -439,6 +459,12 @@ class MaintenanceController extends AbstractController
         return new JsonResponse([
             'success' => true,
             'html' => $view->render(),
+            'buttons' => [
+                [
+                    'btnClass' => 'btn-default t3js-createAdmin-create',
+                    'text' => 'Create administrator user',
+                ],
+            ],
         ]);
     }
 
@@ -490,8 +516,8 @@ class MaintenanceController extends AbstractController
                     FlashMessage::ERROR
                 ));
             } else {
-                $saltFactory = SaltFactory::getSaltingInstance(null, 'BE');
-                $hashedPassword = $saltFactory->getHashedPassword($password);
+                $hashInstance = GeneralUtility::makeInstance(PasswordHashFactory::class)->getDefaultHashInstance('BE');
+                $hashedPassword = $hashInstance->getHashedPassword($password);
                 $adminUserFields = [
                     'username' => $username,
                     'password' => $hashedPassword,
@@ -537,7 +563,7 @@ class MaintenanceController extends AbstractController
      * * list of available languages with details like active or not and last update
      * * list of loaded extensions
      *
-     * @param $request ServerRequestInterface
+     * @param ServerRequestInterface $request
      * @return ResponseInterface
      */
     public function languagePacksGetDataAction(ServerRequestInterface $request): ResponseInterface
@@ -709,6 +735,7 @@ class MaintenanceController extends AbstractController
      */
     public function languagePacksUpdatePackAction(ServerRequestInterface $request): ResponseInterface
     {
+        $this->loadExtLocalconfDatabaseAndExtTables();
         $iso = $request->getParsedBody()['install']['iso'];
         $key = $request->getParsedBody()['install']['extension'];
         $languagePackService = GeneralUtility::makeInstance(LanguagePackService::class);
@@ -757,8 +784,8 @@ class MaintenanceController extends AbstractController
             ->execute();
         $messageQueue = new FlashMessageQueue('install');
         $messageQueue->enqueue(new FlashMessage(
-            'All backend users preferences has been reseted',
-            'Reset all backend users preferences'
+            'Preferences of all backend users have been reset',
+            'Reset preferences of all backend users'
         ));
         return new JsonResponse([
             'success' => true,