[TASK] Switches TcaMigrationsCheck to Ajax
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / Action / Ajax / TcaExtTablesCheck.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\Utility\GeneralUtility;
18 use TYPO3\CMS\Install\Service\LoadTcaService;
19 use TYPO3\CMS\Install\Status\NoticeStatus;
20 use TYPO3\CMS\Install\Status\StatusInterface;
21 use TYPO3\CMS\Install\View\JsonView;
22
23 /**
24 * Check ext_tables.php files of loaded extensions for TCA changes.
25 *
26 * Changing TCA in ext_tables is highly discouraged since core version 7
27 * and can break the frontend since core version 8.
28 *
29 * This test loads all ext_tables.php one-by-one and finds files that
30 * still change TCA.
31 */
32 class TcaExtTablesCheck extends AbstractAjaxAction
33 {
34
35 /**
36 * @var \TYPO3\CMS\Install\View\JsonView
37 */
38 protected $view;
39
40 /**
41 * @param JsonView $view
42 */
43 public function __construct(JsonView $view = null)
44 {
45 $this->view = $view ?: GeneralUtility::makeInstance(JsonView::class);
46 }
47
48 /**
49 * Initialize the handle action, sets up fluid stuff and assigns default variables.
50 * @ToDo Refactor View Initialization for all Ajax Controllers
51 * @return void
52 */
53 protected function initializeHandle()
54 {
55 // empty on purpose because AbstractAjaxAction still overwrites $this->view with StandaloneView
56 }
57
58 /**
59 * Fetches all installed extensions that still mess with the TCA in a way they shouldn't
60 *
61 * @return array status list of extensions that still mess with the TCA
62 */
63 protected function executeAction()
64 {
65 $statusMessages = [];
66 $tcaMessages = $this->checkTcaChangesInExtTables();
67
68 foreach ($tcaMessages as $tcaMessage) {
69 /** @var $message StatusInterface */
70 $message = GeneralUtility::makeInstance(NoticeStatus::class);
71 $message->setTitle($tcaMessage);
72 $statusMessages[] = $message;
73 }
74
75 $this->view->assignMultiple([
76 'success' => true,
77 'status' => $statusMessages,
78 ]);
79 return $this->view->render();
80 }
81
82 /**
83 * Load base TCA, then load each single ext_tables.php file and see if TCA changed.
84 *
85 * @return array list of extensions that still mess with the tca
86 */
87 protected function checkTcaChangesInExtTables()
88 {
89 $loadTcaService = GeneralUtility::makeInstance(LoadTcaService::class);
90 $loadTcaService->loadExtensionTablesWithoutMigration();
91 $baseTca = $GLOBALS['TCA'];
92 $messages = [];
93 foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $extensionKey => $extensionInformation) {
94 if ((is_array($extensionInformation) || $extensionInformation instanceof \ArrayAccess)
95 && $extensionInformation['ext_tables.php']
96 ) {
97 $loadTcaService->loadSingleExtTablesFile($extensionKey);
98 $newTca = $GLOBALS['TCA'];
99 if ($newTca !== $baseTca) {
100 $messages[] = $extensionKey;
101 }
102 $baseTca = $newTca;
103 }
104 }
105 return $messages;
106 }
107 }