[TASK] Switches TcaMigrationsCheck to Ajax 80/50380/9
authorPatricia Tiedemann <pixelaeffchen@googlemail.com>
Wed, 26 Oct 2016 09:45:50 +0000 (11:45 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Thu, 27 Oct 2016 14:21:21 +0000 (16:21 +0200)
Similar to the "TCA in ext_tables.php check" the "TCA Migrations"
check now uses Ajax to show its results.

Most of this check's code logic itself hasn't been modified, only
moved to a different class.

Resolves: #78443
Releases: master
Change-Id: I99249e806e6fb1945c994e8ca58f17c488948240
Reviewed-on: https://review.typo3.org/50380
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/install/Classes/Controller/Action/Ajax/TcaExtTablesCheck.php
typo3/sysext/install/Classes/Controller/Action/Ajax/TcaMigrationsCheck.php [new file with mode: 0644]
typo3/sysext/install/Classes/Controller/Action/Tool/ImportantActions.php
typo3/sysext/install/Classes/Controller/AjaxController.php
typo3/sysext/install/Resources/Private/Partials/Action/Tool/ImportantActions/TcaExtTablesCheck.html
typo3/sysext/install/Resources/Private/Partials/Action/Tool/ImportantActions/TcaMigrations.html [deleted file]
typo3/sysext/install/Resources/Private/Partials/Action/Tool/ImportantActions/TcaMigrationsCheck.html [new file with mode: 0644]
typo3/sysext/install/Resources/Private/Templates/Action/Tool/ImportantActions.html
typo3/sysext/install/Resources/Public/JavaScript/Install.js

index 56e01b7..5ff5997 100644 (file)
@@ -16,6 +16,9 @@ namespace TYPO3\CMS\Install\Controller\Action\Ajax;
 
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Install\Service\LoadTcaService;
+use TYPO3\CMS\Install\Status\NoticeStatus;
+use TYPO3\CMS\Install\Status\StatusInterface;
+use TYPO3\CMS\Install\View\JsonView;
 
 /**
  * Check ext_tables.php files of loaded extensions for TCA changes.
@@ -28,13 +31,61 @@ use TYPO3\CMS\Install\Service\LoadTcaService;
  */
 class TcaExtTablesCheck extends AbstractAjaxAction
 {
+
     /**
-     * Load base TCA, then load each single ext_tables.php file and see if TCA changed.
+     * @var \TYPO3\CMS\Install\View\JsonView
+     */
+    protected $view;
+
+    /**
+     * @param JsonView $view
+     */
+    public function __construct(JsonView $view = null)
+    {
+        $this->view = $view ?: GeneralUtility::makeInstance(JsonView::class);
+    }
+
+    /**
+     * Initialize the handle action, sets up fluid stuff and assigns default variables.
+     * @ToDo Refactor View Initialization for all Ajax Controllers
+     * @return void
+     */
+    protected function initializeHandle()
+    {
+        // empty on purpose because AbstractAjaxAction still overwrites $this->view with StandaloneView
+    }
+
+    /**
+     * Fetches all installed extensions that still mess with the TCA in a way they shouldn't
      *
-     * @return string "OK" on success, the error message otherwise
+     * @return array status list of extensions that still mess with the TCA
      */
     protected function executeAction()
     {
+        $statusMessages = [];
+        $tcaMessages = $this->checkTcaChangesInExtTables();
+
+        foreach ($tcaMessages as $tcaMessage) {
+            /** @var $message StatusInterface */
+            $message = GeneralUtility::makeInstance(NoticeStatus::class);
+            $message->setTitle($tcaMessage);
+            $statusMessages[] = $message;
+        }
+
+        $this->view->assignMultiple([
+            'success' => true,
+            'status' => $statusMessages,
+        ]);
+        return $this->view->render();
+    }
+
+    /**
+     * Load base TCA, then load each single ext_tables.php file and see if TCA changed.
+     *
+     * @return array list of extensions that still mess with the tca
+     */
+    protected function checkTcaChangesInExtTables()
+    {
         $loadTcaService = GeneralUtility::makeInstance(LoadTcaService::class);
         $loadTcaService->loadExtensionTablesWithoutMigration();
         $baseTca = $GLOBALS['TCA'];
@@ -51,9 +102,6 @@ class TcaExtTablesCheck extends AbstractAjaxAction
                 $baseTca = $newTca;
             }
         }
-        if (empty($messages)) {
-            $messages[] = 'OK';
-        }
-        return implode('<br />', $messages);
+        return $messages;
     }
 }
diff --git a/typo3/sysext/install/Classes/Controller/Action/Ajax/TcaMigrationsCheck.php b/typo3/sysext/install/Classes/Controller/Action/Ajax/TcaMigrationsCheck.php
new file mode 100644 (file)
index 0000000..96280c8
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+namespace TYPO3\CMS\Install\Controller\Action\Ajax;
+
+/*
+ * 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\Migrations\TcaMigration;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Install\Service\LoadTcaService;
+use TYPO3\CMS\Install\Status\NoticeStatus;
+use TYPO3\CMS\Install\Status\StatusInterface;
+use TYPO3\CMS\Install\View\JsonView;
+
+/**
+ * Checks whether the current TCA needs migrations and displays applied migrations.
+ */
+class TcaMigrationsCheck extends AbstractAjaxAction
+{
+    /**
+     * @var \TYPO3\CMS\Install\View\JsonView
+     */
+    protected $view;
+
+    /**
+     * @param JsonView $view
+     */
+    public function __construct(JsonView $view = null)
+    {
+        $this->view = $view ?: GeneralUtility::makeInstance(JsonView::class);
+    }
+
+    /**
+     * Initialize the handle action, sets up fluid stuff and assigns default variables.
+     * @ToDo Refactor View Initialization for all Ajax Controllers
+     * @return void
+     */
+    protected function initializeHandle()
+    {
+        // empty on purpose because AbstractAjaxAction still overwrites $this->view with StandaloneView
+    }
+
+    /**
+     * Load all TCA Migrations and return if there are any todos
+     *
+     * @return array TCA status messages
+     */
+    protected function executeAction()
+    {
+        $statusMessages = [];
+        $tcaMessages = $this->checkTcaMigrations();
+
+        foreach ($tcaMessages as $tcaMessage) {
+            /** @var $message StatusInterface */
+            $message = GeneralUtility::makeInstance(NoticeStatus::class);
+            $message->setMessage($tcaMessage);
+            $statusMessages[] = $message;
+        }
+
+        $this->view->assignMultiple([
+            'success' => true,
+            'status' => $statusMessages,
+        ]);
+        return $this->view->render();
+    }
+
+    /**
+     * "TCA migration" action
+     *
+     * @return array The TCA migration messages
+     */
+    protected function checkTcaMigrations()
+    {
+        GeneralUtility::makeInstance(LoadTcaService::class)->loadExtensionTablesWithoutMigration();
+        $tcaMigration = GeneralUtility::makeInstance(TcaMigration::class);
+        $GLOBALS['TCA'] = $tcaMigration->migrate($GLOBALS['TCA']);
+        return $tcaMigration->getMessages();
+    }
+}
index 9c3c3e0..d990bd4 100644 (file)
@@ -57,26 +57,6 @@ class ImportantActions extends Action\AbstractAction
         if (isset($this->postValues['set']['dumpAutoload'])) {
             $actionMessages[] = $this->dumpAutoload();
         }
-        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'])
@@ -484,20 +464,7 @@ class ImportantActions extends Action\AbstractAction
         /** @var $message \TYPO3\CMS\Install\Status\StatusInterface */
         $message = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Status\OkStatus::class);
         $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();
+        return $message;
     }
 }
index e71e562..876d344 100644 (file)
@@ -44,7 +44,8 @@ class AjaxController extends AbstractController
         'coreUpdateActivate',
         'folderStatus',
         'environmentStatus',
-        'tcaExtTablesCheck'
+        'tcaExtTablesCheck',
+        'tcaMigrationsCheck',
     ];
 
     /**
index b318b69..1bfec80 100644 (file)
@@ -1,24 +1,15 @@
 <h3>TCA in ext_tables.php check</h3>
-
 <p>
        Check if an extension changes $GLOBALS['TCA'] in ext_tables.php.
 </p>
-
 <form method="post">
        <f:render partial="Action/Common/HiddenFormFields" arguments="{_all}" />
        <div id="tcaExtTablesCheck">
-               <div id="tcaExtTablesCheck-loading" class="t3js-message typo3-message alert alert-loading" role="alert" style="display: none;">
-                       <h4>Loading...</h4>
-               </div>
-               <div id="tcaExtTablesCheck-ok" class="t3js-message typo3-message alert alert-success" role="alert" style="display: none;">
-                       <h4>No TCA changes in ext_tables.php files. Good job!</h4>
-               </div>
-               <div id="tcaExtTablesCheck-fatal" class="t3js-message typo3-message alert alert-danger" role="alert" style="display: none;">
-                       <h4>Something went wrong checking ext_tables.php, use "Check for broken extensions"!</h4>
-               </div>
-               <div id="tcaExtTablesCheck-broken" class="t3js-message typo3-message alert alert-danger" role="alert" style="display: none;">
-                               <h4>Extensions change TCA in ext_tables.php, check for ExtensionManagementUtility and $GLOBALS['TCA']:</h4>
+               <div class="messageTemplate" style="display: none;">
+                       <div class="t3js-message typo3-message alert">
+                               <h4></h4>
                                <p class="messageText"></p>
+                       </div>
                </div>
                <f:render partial="Action/Common/SubmitButton" arguments="{name:'tceExtTablesCheck', text:'Check loaded extensions'}"/>
        </div>
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
deleted file mode 100644 (file)
index 24f3ae4..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<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>
diff --git a/typo3/sysext/install/Resources/Private/Partials/Action/Tool/ImportantActions/TcaMigrationsCheck.html b/typo3/sysext/install/Resources/Private/Partials/Action/Tool/ImportantActions/TcaMigrationsCheck.html
new file mode 100644 (file)
index 0000000..3130860
--- /dev/null
@@ -0,0 +1,16 @@
+<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}" />
+       <div id="tcaMigrationsCheck">
+               <div class="messageTemplate" style="display: none;">
+                       <div class="t3js-message typo3-message alert">
+                               <h4></h4>
+                               <p class="messageText"></p>
+                       </div>
+               </div>
+               <f:render partial="Action/Common/SubmitButton" arguments="{name:'tcaMigrationsCheck', text:'Check TCA Migrations'}"/>
+       </div>
+</form>
\ No newline at end of file
index 6a6a8f2..d9af37b 100644 (file)
@@ -35,7 +35,7 @@
        <f:render partial="Action/Tool/ImportantActions/ExtensionCompatibilityTester" arguments="{_all}"/>
        <hr />
 
-       <f:render partial="Action/Tool/ImportantActions/TcaMigrations" arguments="{_all}"/>
+       <f:render partial="Action/Tool/ImportantActions/TcaMigrationsCheck" arguments="{_all}"/>
        <hr />
 
        <f:render partial="Action/Tool/ImportantActions/TcaExtTablesCheck" arguments="{_all}"/>
index 2a651ab..1f514d6 100644 (file)
@@ -215,36 +215,183 @@ TYPO3.Install.ExtensionChecker = {
        }
 };
 
-TYPO3.Install.TcaExtTablesChecker = {
-       checkTcaExtTables: function() {
-               var self = this;
-               var url = location.href + '&install[controller]=ajax&install[action]=tcaExtTablesCheck';
+TYPO3.Install.TcaIntegrityChecker = {
 
-               $('button', '#tcaExtTablesCheck').hide();
-               $('#tcaExtTablesCheck-loading').show();
+       /**
+        * Default output messages
+        */
+       outputMessages: {
+               tcaMigrationsCheck: {
+                       fatalTitle: 'Something went wrong',
+                       fatalMessage: 'Use "Check for broken extensions!"',
+                       loadingTitle: 'Loading…',
+                       loadingMessage: '',
+                       successTitle: 'No TCA migrations need to be applied',
+                       successMessage: 'Your TCA looks good.',
+                       warningTitle: 'TCA migrations need to be applied',
+                       warningMessage: 'Check the following list and apply needed changes.'
+               },
+               tcaExtTablesCheck: {
+                       fatalTitle: 'Something went wrong',
+                       fatalMessage: 'Use "Check for broken extensions!"',
+                       loadingTitle: 'Loading…',
+                       loadingMessage: '',
+                       successTitle: 'No TCA changes in ext_tables.php files. Good job!',
+                       successMessage: '',
+                       warningTitle: 'Extensions change TCA in ext_tables.php',
+                       warningMessage: 'Check for ExtensionManagementUtility and $GLOBALS["TCA"].'
+               }
+       },
 
-               $.ajax({
-                       url: url,
-                       cache: false,
-                       success: function(data) {
-                               if (data === 'OK') {
-                                       $('#tcaExtTablesCheck-loading').hide();
-                                       $('#tcaExtTablesCheck-ok').show();
-                               } else {
-                                       if (data === 'unauthorized') {
+       /**
+        * output DOM Container
+        */
+       outputContainer: {},
+
+       /**
+        * Clone of a DOM object acts as message template
+        */
+       messageTemplate: {},
+
+       /**
+        * Clone of the DOM object that contains the submit button
+        */
+       submitButton: {},
+
+       /**
+        * Fetching the templates out of the DOM
+        *
+        * @param tcaIntegrityCheckContainer DOM element id with all needed HTML in it
+        * @return boolean DOM container could be found and initialization finished
+        */
+       initialize: function(tcaIntegrityCheckContainer) {
+               var success = false;
+               this.outputContainer[tcaIntegrityCheckContainer] = $('#' + tcaIntegrityCheckContainer);
+
+               if (this.outputContainer[tcaIntegrityCheckContainer]) {
+                       // submit button: save and delete
+                       if(!this.submitButton[tcaIntegrityCheckContainer]) {
+                               var submitButton = this.outputContainer[tcaIntegrityCheckContainer].find('button[type="submit"]');
+                               this.submitButton[tcaIntegrityCheckContainer] = submitButton.clone();
+                               // submitButton.remove();
+                       }
+
+                       // message template (for the output): save and delete
+                       if(!this.messageTemplate[tcaIntegrityCheckContainer]) {
+                               var messageTemplateSection = this.outputContainer[tcaIntegrityCheckContainer].find('.messageTemplate');
+                               this.messageTemplate[tcaIntegrityCheckContainer] = messageTemplateSection.children().clone().show();
+                               messageTemplateSection.remove();
+                       }
+
+                       // clear all messages from the run before
+                       this.outputContainer[tcaIntegrityCheckContainer].find('.typo3-message:visible ').remove();
+
+                       success = true;
+               }
+               return success;
+       },
+
+       checkTcaIntegrity: function(actionName) {
+               var self = this;
+               var url = location.href + '&install[controller]=ajax&install[action]=' + actionName;
+
+               var isInitialized = self.initialize(actionName);
+               if(isInitialized) {
+                       self.addMessage(
+                               'loading',
+                               self.outputMessages[actionName].loadingTitle,
+                               self.outputMessages[actionName].loadingMessage,
+                               actionName
+                       );
+
+                       $.ajax({
+                               url: url,
+                               cache: false,
+                               success: function(data) {
+
+                                       if(data.success === true && Array.isArray(data.status)) {
+                                               if(data.status.length > 0) {
+                                                       self.outputContainer[actionName].find('.alert-loading').hide();
+                                                       self.addMessage(
+                                                               'warning',
+                                                               self.outputMessages[actionName].warningTitle,
+                                                               self.outputMessages[actionName].warningMessage,
+                                                               actionName
+                                                       );
+                                                       data.status.forEach((function (element) {
+                                                               self.addMessage(
+                                                                       element.severity,
+                                                                       element.title,
+                                                                       element.message,
+                                                                       actionName
+                                                               );
+                                                       }));
+                                               } else {
+                                                       // nothing to complain, everything fine
+                                                       self.outputContainer[actionName].find('.alert-loading').hide();
+                                                       self.addMessage(
+                                                               'success',
+                                                               self.outputMessages[actionName].successTitle,
+                                                               self.outputMessages[actionName].successMessage,
+                                                               actionName
+                                                       );
+                                               }
+                                       } else if (data === 'unauthorized') {
                                                location.reload();
                                        }
-                                       $('#tcaExtTablesCheck-loading').hide();
-                                       // secure me!
-                                       $('#tcaExtTablesCheck-broken').show().find('.messageText').html(data);
+                               },
+                               error: function() {
+                                       self.outputContainer[actionName].find('.alert-loading').hide();
+                                       self.addMessage(
+                                               'fatal',
+                                               self.outputMessages[actionName].fatalTitle,
+                                               self.outputMessages[actionName].fatalMessage,
+                                               actionName
+                                       );
                                }
-                       },
-                       error: function() {
-                               $('#tcaExtTablesCheck-loading').hide();
-                               $('#tcaExtTablesCheck-fatal').show();
-                       }
-               });
+                       });
+               }
+       },
+
+       /**
+        * Move the submit button to the end of the box
+        *
+        * @param tcaIntegrityCheckContainer DOM container name
+        */
+       moveSubmitButtonFurtherDown: function(tcaIntegrityCheckContainer) {
+               console.debug(this.outputContainer[tcaIntegrityCheckContainer], 'this.outputContainer['+[tcaIntegrityCheckContainer]+']');
+
+               // first remove the currently visible button
+               this.outputContainer[tcaIntegrityCheckContainer].find('button[type="submit"]').remove();
+               // then append the cloned template to the end
+               this.outputContainer[tcaIntegrityCheckContainer].append(this.submitButton[tcaIntegrityCheckContainer]);
+       },
+
+       /**
+        * Show a status message
+        *
+        * @param severity
+        * @param title
+        * @param message
+        * @param tcaIntegrityCheckContainer DOM container name
+        */
+       addMessage: function(severity, title, message, tcaIntegrityCheckContainer) {
+               var domMessage = this.messageTemplate[tcaIntegrityCheckContainer].clone();
+               if (severity) {
+                       domMessage.addClass('alert-' + severity);
+               }
+               if (title) {
+                       domMessage.find('h4').html(title);
+               }
+               if (message) {
+                       domMessage.find('.messageText').html(message);
+               } else {
+                       domMessage.find('.messageText').remove();
+               }
+               this.outputContainer[tcaIntegrityCheckContainer].append(domMessage);
+               this.moveSubmitButtonFurtherDown(tcaIntegrityCheckContainer);
        }
+
 };
 
 TYPO3.Install.Status = {
@@ -654,7 +801,17 @@ $(function() {
        var $tcaExtTablesCheckSection = $('#tcaExtTablesCheck');
        if ($tcaExtTablesCheckSection) {
                $tcaExtTablesCheckSection.on('click', 'button', (function(e) {
-                       TYPO3.Install.TcaExtTablesChecker.checkTcaExtTables();
+                       TYPO3.Install.TcaIntegrityChecker.checkTcaIntegrity('tcaExtTablesCheck');
+                       e.preventDefault();
+                       return false;
+               }));
+       }
+
+       // Handle TCA Migrations check
+       var $tcaMigrationsCheckSection = $('#tcaMigrationsCheck');
+       if ($tcaMigrationsCheckSection) {
+               $tcaMigrationsCheckSection.on('click', 'button', (function(e) {
+                       TYPO3.Install.TcaIntegrityChecker.checkTcaIntegrity('tcaMigrationsCheck');
                        e.preventDefault();
                        return false;
                }));