[TASK] Switches TcaMigrationsCheck to Ajax
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / Action / Ajax / TcaMigrationsCheck.php
1 <?php
2 namespace TYPO3\CMS\Install\Controller\Action\Ajax;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Migrations\TcaMigration;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Install\Service\LoadTcaService;
20 use TYPO3\CMS\Install\Status\NoticeStatus;
21 use TYPO3\CMS\Install\Status\StatusInterface;
22 use TYPO3\CMS\Install\View\JsonView;
23
24 /**
25 * Checks whether the current TCA needs migrations and displays applied migrations.
26 */
27 class TcaMigrationsCheck extends AbstractAjaxAction
28 {
29 /**
30 * @var \TYPO3\CMS\Install\View\JsonView
31 */
32 protected $view;
33
34 /**
35 * @param JsonView $view
36 */
37 public function __construct(JsonView $view = null)
38 {
39 $this->view = $view ?: GeneralUtility::makeInstance(JsonView::class);
40 }
41
42 /**
43 * Initialize the handle action, sets up fluid stuff and assigns default variables.
44 * @ToDo Refactor View Initialization for all Ajax Controllers
45 * @return void
46 */
47 protected function initializeHandle()
48 {
49 // empty on purpose because AbstractAjaxAction still overwrites $this->view with StandaloneView
50 }
51
52 /**
53 * Load all TCA Migrations and return if there are any todos
54 *
55 * @return array TCA status messages
56 */
57 protected function executeAction()
58 {
59 $statusMessages = [];
60 $tcaMessages = $this->checkTcaMigrations();
61
62 foreach ($tcaMessages as $tcaMessage) {
63 /** @var $message StatusInterface */
64 $message = GeneralUtility::makeInstance(NoticeStatus::class);
65 $message->setMessage($tcaMessage);
66 $statusMessages[] = $message;
67 }
68
69 $this->view->assignMultiple([
70 'success' => true,
71 'status' => $statusMessages,
72 ]);
73 return $this->view->render();
74 }
75
76 /**
77 * "TCA migration" action
78 *
79 * @return array The TCA migration messages
80 */
81 protected function checkTcaMigrations()
82 {
83 GeneralUtility::makeInstance(LoadTcaService::class)->loadExtensionTablesWithoutMigration();
84 $tcaMigration = GeneralUtility::makeInstance(TcaMigration::class);
85 $GLOBALS['TCA'] = $tcaMigration->migrate($GLOBALS['TCA']);
86 return $tcaMigration->getMessages();
87 }
88 }