[FEATURE] Display TCA migration messages in Install Tool
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Service / LoadTcaService.php
1 <?php
2 namespace TYPO3\CMS\Install\Service;
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\Category\CategoryRegistry;
18 use TYPO3\CMS\Core\Package\PackageManager;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * Service for loading the TCA
23 */
24 class LoadTcaService
25 {
26
27 /**
28 * Load TCA
29 *
30 * This will set up $GLOBALS['TCA']
31 */
32 public function loadExtensionTablesWithoutMigration()
33 {
34 $this->loadBaseTca();
35 }
36
37 /**
38 * Copy of ExtensionManagementUtility to include TCA without migrations
39 *
40 * @see \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::buildBaseTcaFromSingleFiles
41 */
42 protected function loadBaseTca()
43 {
44 $GLOBALS['TCA'] = [];
45
46 $activePackages = GeneralUtility::makeInstance(PackageManager::class)
47 ->getActivePackages();
48
49 // First load "full table" files from Configuration/TCA
50 foreach ($activePackages as $package) {
51 $tcaConfigurationDirectory = $package->getPackagePath() . 'Configuration/TCA';
52 if (is_dir($tcaConfigurationDirectory)) {
53 $files = scandir($tcaConfigurationDirectory);
54 foreach ($files as $file) {
55 if (is_file($tcaConfigurationDirectory . '/' . $file)
56 && ($file !== '.')
57 && ($file !== '..')
58 && (substr($file, -4, 4) === '.php')
59 ) {
60 $tcaOfTable = require $tcaConfigurationDirectory . '/' . $file;
61 if (is_array($tcaOfTable)) {
62 // TCA table name is filename without .php suffix, eg 'sys_notes', not 'sys_notes.php'
63 $tcaTableName = substr($file, 0, -4);
64 $GLOBALS['TCA'][$tcaTableName] = $tcaOfTable;
65 }
66 }
67 }
68 }
69 }
70
71 // Apply category stuff
72 CategoryRegistry::getInstance()->applyTcaForPreRegisteredTables();
73
74 // Execute override files from Configuration/TCA/Overrides
75 foreach ($activePackages as $package) {
76 $tcaOverridesPathForPackage = $package->getPackagePath() . 'Configuration/TCA/Overrides';
77 if (is_dir($tcaOverridesPathForPackage)) {
78 $files = scandir($tcaOverridesPathForPackage);
79 foreach ($files as $file) {
80 if (is_file($tcaOverridesPathForPackage . '/' . $file)
81 && ($file !== '.')
82 && ($file !== '..')
83 && (substr($file, -4, 4) === '.php')
84 ) {
85 require $tcaOverridesPathForPackage . '/' . $file;
86 }
87 }
88 }
89 }
90 }
91 }