[FEATURE] Display TCA migration messages in Install Tool 06/49806/6
authorPhilipp Gampe <philipp.gampe@typo3.org>
Fri, 2 Sep 2016 21:54:14 +0000 (23:54 +0200)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Sat, 3 Sep 2016 09:09:32 +0000 (11:09 +0200)
Add a new action to check for TCA migrations and display
all applied migrations.

Resolves: #77799
Releases: master
Change-Id: I8ad82575051a9ba44ef8407a75c09f341d3d0771
Reviewed-on: https://review.typo3.org/49806
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
typo3/sysext/core/Documentation/Changelog/master/Feature-77799-DisplayTCAMigrationMessagesInInstallTool.rst [new file with mode: 0644]
typo3/sysext/install/Classes/Controller/Action/Tool/ImportantActions.php
typo3/sysext/install/Classes/Service/LoadTcaService.php [new file with mode: 0644]
typo3/sysext/install/Resources/Private/Partials/Action/Tool/ImportantActions/TcaMigrations.html [new file with mode: 0644]
typo3/sysext/install/Resources/Private/Templates/Action/Tool/ImportantActions.html

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-77799-DisplayTCAMigrationMessagesInInstallTool.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-77799-DisplayTCAMigrationMessagesInInstallTool.rst
new file mode 100644 (file)
index 0000000..b691ac4
--- /dev/null
@@ -0,0 +1,14 @@
+================================================================
+Feature: #77799 - Display TCA migration messages in Install Tool
+================================================================
+
+Description
+===========
+
+Display the TCA migration message(s) in the Install Tool.
+
+
+Impact
+======
+
+You are now able to show all TCA migration messages from within the Install Tool.
\ No newline at end of file
index f29a345..a46d226 100644 (file)
@@ -53,6 +53,26 @@ class ImportantActions extends Action\AbstractAction
             $actionMessages[] = $this->clearAllCache();
             $actionMessages[] = $this->clearOpcodeCache();
         }
             $actionMessages[] = $this->clearAllCache();
             $actionMessages[] = $this->clearOpcodeCache();
         }
+        if (isset($this->postValues['set']['tcaMigrations'])) {
+            $tcaMessages = $this->checkTcaMigrations();
+
+            if (count($tcaMessages) === 0) {
+                $message = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Status\OkStatus::class);
+                $message->setTitle('No TCA migrations need to be applied');
+                $message->setMessage('Your TCA looks good.');
+                $actionMessages[] = $message;
+            } else {
+                $message = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Status\WarningStatus::class);
+                $message->setTitle('TCA migrations need to be applied');
+                $messageContent = ['Check the following list and apply needed changes. <br><br><ol>'];
+                foreach ($tcaMessages as $tcaMessage) {
+                    $messageContent[] = '<li>' . $tcaMessage . '</li>';
+                }
+                $messageContent[] = '</ol>';
+                $message->setMessage(implode('', $messageContent));
+                $actionMessages[] = $message;
+            }
+        }
 
         // Database analyzer handling
         if (isset($this->postValues['set']['databaseAnalyzerExecute'])
 
         // Database analyzer handling
         if (isset($this->postValues['set']['databaseAnalyzerExecute'])
@@ -437,4 +457,18 @@ class ImportantActions extends Action\AbstractAction
         $message->setTitle('Analyzed current database');
         return $message;
     }
         $message->setTitle('Analyzed current database');
         return $message;
     }
+
+    /**
+     * "TCA migration" action
+     *
+     * @return array The TCA migration messages
+     */
+    protected function checkTcaMigrations()
+    {
+        GeneralUtility::makeInstance(\TYPO3\CMS\Install\Service\LoadTcaService::class)
+            ->loadExtensionTablesWithoutMigration();
+        $tcaMigration = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Migrations\TcaMigration::class);
+        $GLOBALS['TCA'] = $tcaMigration->migrate($GLOBALS['TCA']);
+        return $tcaMigration->getMessages();
+    }
 }
 }
diff --git a/typo3/sysext/install/Classes/Service/LoadTcaService.php b/typo3/sysext/install/Classes/Service/LoadTcaService.php
new file mode 100644 (file)
index 0000000..c2b3060
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+namespace TYPO3\CMS\Install\Service;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Category\CategoryRegistry;
+use TYPO3\CMS\Core\Package\PackageManager;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Service for loading the TCA
+ */
+class LoadTcaService
+{
+
+    /**
+     * Load TCA
+     *
+     * This will set up $GLOBALS['TCA']
+     */
+    public function loadExtensionTablesWithoutMigration()
+    {
+        $this->loadBaseTca();
+    }
+
+    /**
+     * Copy of ExtensionManagementUtility to include TCA without migrations
+     *
+     * @see \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::buildBaseTcaFromSingleFiles
+     */
+    protected function loadBaseTca()
+    {
+        $GLOBALS['TCA'] = [];
+
+        $activePackages = GeneralUtility::makeInstance(PackageManager::class)
+            ->getActivePackages();
+
+        // First load "full table" files from Configuration/TCA
+        foreach ($activePackages as $package) {
+            $tcaConfigurationDirectory = $package->getPackagePath() . 'Configuration/TCA';
+            if (is_dir($tcaConfigurationDirectory)) {
+                $files = scandir($tcaConfigurationDirectory);
+                foreach ($files as $file) {
+                    if (is_file($tcaConfigurationDirectory . '/' . $file)
+                        && ($file !== '.')
+                        && ($file !== '..')
+                        && (substr($file, -4, 4) === '.php')
+                    ) {
+                        $tcaOfTable = require $tcaConfigurationDirectory . '/' . $file;
+                        if (is_array($tcaOfTable)) {
+                            // TCA table name is filename without .php suffix, eg 'sys_notes', not 'sys_notes.php'
+                            $tcaTableName = substr($file, 0, -4);
+                            $GLOBALS['TCA'][$tcaTableName] = $tcaOfTable;
+                        }
+                    }
+                }
+            }
+        }
+
+        // Apply category stuff
+        CategoryRegistry::getInstance()->applyTcaForPreRegisteredTables();
+
+        // Execute override files from Configuration/TCA/Overrides
+        foreach ($activePackages as $package) {
+            $tcaOverridesPathForPackage = $package->getPackagePath() . 'Configuration/TCA/Overrides';
+            if (is_dir($tcaOverridesPathForPackage)) {
+                $files = scandir($tcaOverridesPathForPackage);
+                foreach ($files as $file) {
+                    if (is_file($tcaOverridesPathForPackage . '/' . $file)
+                        && ($file !== '.')
+                        && ($file !== '..')
+                        && (substr($file, -4, 4) === '.php')
+                    ) {
+                        require $tcaOverridesPathForPackage . '/' . $file;
+                    }
+                }
+            }
+        }
+    }
+}
diff --git a/typo3/sysext/install/Resources/Private/Partials/Action/Tool/ImportantActions/TcaMigrations.html b/typo3/sysext/install/Resources/Private/Partials/Action/Tool/ImportantActions/TcaMigrations.html
new file mode 100644 (file)
index 0000000..24f3ae4
--- /dev/null
@@ -0,0 +1,8 @@
+<h3>TCA Migrations</h3>
+<p>
+       Checks whether the current TCA needs migrations and displays applied migrations.
+</p>
+<form method="post">
+       <f:render partial="Action/Common/HiddenFormFields" arguments="{_all}" />
+       <f:render partial="Action/Common/SubmitButton" arguments="{name:'tcaMigrations', text:'Check TCA migrations'}"/>
+</form>
index 1be9d69..fb32140 100644 (file)
@@ -28,6 +28,9 @@
        <f:render partial="Action/Tool/ImportantActions/ExtensionCompatibilityTester" arguments="{_all}"/>
        <hr />
 
        <f:render partial="Action/Tool/ImportantActions/ExtensionCompatibilityTester" arguments="{_all}"/>
        <hr />
 
+       <f:render partial="Action/Tool/ImportantActions/TcaMigrations" arguments="{_all}"/>
+       <hr />
+
        <f:render partial="Action/Tool/ImportantActions/CoreUpdateButton" arguments="{_all}"/>
        <hr />
 
        <f:render partial="Action/Tool/ImportantActions/CoreUpdateButton" arguments="{_all}"/>
        <hr />