[FEATURE] Show PHP Errors after checking compatibility of extensions 98/28298/4
authorDaniel Siepmann <daniel.siepmann@typo3.org>
Wed, 12 Mar 2014 13:59:51 +0000 (14:59 +0100)
committerDmitry Dulepov <dmitry.dulepov@gmail.com>
Mon, 17 Mar 2014 10:07:35 +0000 (11:07 +0100)
The errors are logged in another log file and loaded as json afterwards.

Change-Id: I63458c0a4f64e6d8f4236667b6d22ff6b50aa1f3
Resolves: #51362
Releases: 6.2
Reviewed-on: https://review.typo3.org/28298
Reviewed-by: Tomita Militaru
Reviewed-by: Ernesto Baschny
Tested-by: Ernesto Baschny
Reviewed-by: Dmitry Dulepov
Tested-by: Dmitry Dulepov
typo3/sysext/install/Classes/Controller/Action/Ajax/ExtensionCompatibilityTester.php
typo3/sysext/install/Classes/Controller/Action/Tool/ImportantActions.php
typo3/sysext/install/Resources/Private/Partials/Action/Tool/ImportantActions/ExtensionCompatibilityTester.html
typo3/sysext/install/Resources/Public/Javascript/Install.js

index 43f1549..a5cf0eb 100644 (file)
@@ -44,11 +44,26 @@ class ExtensionCompatibilityTester extends AbstractAjaxAction {
        protected $protocolFile = '';
 
        /**
+        * Store errors that occured during checks.
+        *
+        * @var string
+        */
+       protected $errorProtocolFile = '';
+
+       /**
+        * Define whether to log errors to file or not.
+        *
+        * @var boolean
+        */
+       protected $logError = FALSE;
+
+       /**
         * Construct this class
         * set default protocol file location
         */
        public function __construct() {
                $this->protocolFile = PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt';
+               $this->errorProtocolFile = PATH_site . 'typo3temp/ExtensionCompatibilityTesterErrors.json';
        }
 
        /**
@@ -59,6 +74,7 @@ class ExtensionCompatibilityTester extends AbstractAjaxAction {
         * @return string "OK" if process ran through without errors
         */
        protected function executeAction() {
+               register_shutdown_function(array($this, 'logError'));
                $getVars = Utility\GeneralUtility::_GET('install');
                if (isset($getVars['extensionCompatibilityTester']) && isset($getVars['extensionCompatibilityTester']['forceCheck']) && ($getVars['extensionCompatibilityTester']['forceCheck'] == 1)) {
                        $this->deleteProtocolFile();
@@ -68,7 +84,7 @@ class ExtensionCompatibilityTester extends AbstractAjaxAction {
        }
 
        /**
-        * Delete the protocol file if it exists
+        * Delete the protocol files if they exist
         *
         * @return void
         */
@@ -76,6 +92,9 @@ class ExtensionCompatibilityTester extends AbstractAjaxAction {
                if (file_exists($this->protocolFile)) {
                        unlink($this->protocolFile);
                }
+               if (file_exists($this->errorProtocolFile)) {
+                       unlink($this->errorProtocolFile);
+               }
        }
 
        /**
@@ -190,6 +209,7 @@ class ExtensionCompatibilityTester extends AbstractAjaxAction {
                $incompatibleExtensions = array_filter(Utility\GeneralUtility::trimExplode(',', (string)Utility\GeneralUtility::getUrl($this->protocolFile)));
                $incompatibleExtensions = array_merge($incompatibleExtensions, array($extensionKey));
                Utility\GeneralUtility::writeFile($this->protocolFile, implode(', ', $incompatibleExtensions));
+               $this->logError = TRUE;
        }
 
        /**
@@ -204,5 +224,46 @@ class ExtensionCompatibilityTester extends AbstractAjaxAction {
                unset($extensionsByKey[$extensionKey]);
                $extensionsForFile = array_flip($extensionsByKey);
                Utility\GeneralUtility::writeFile($this->protocolFile, implode(', ', $extensionsForFile));
+               $this->logError = FALSE;
+       }
+
+       /**
+        * Log last occured error for logging.
+        *
+        * @return void
+        */
+       public function logError() {
+               // Logging is disabled.
+               if (!$this->logError) {
+                       return;
+               }
+
+               // Fetch existing errors, add last one and write to file again.
+               $lastError = error_get_last();
+               $errors = array();
+
+               if (file_exists($this->errorProtocolFile)) {
+                       $errors = json_decode(Utility\GeneralUtility::getUrl($this->errorProtocolFile));
+               }
+               switch ($lastError['type']) {
+                       case E_ERROR:
+                               $lastError['type'] = 'E_ERROR';
+                               break;
+                       case E_WARNING:
+                               $lastError['type'] = 'E_WARNING';
+                               break;
+                       case E_PARSE:
+                               $lastError['type'] = 'E_PARSE';
+                               break;
+                       case E_NOTICE:
+                               $lastError['type'] = 'E_NOTICE';
+                               break;
+                       case E_NOTICE:
+                               $lastError['type'] = 'E_NOTICE';
+                               break;
+               }
+               $errors[] = $lastError;
+
+               Utility\GeneralUtility::writeFile($this->errorProtocolFile, json_encode($errors));
        }
 }
index 894119c..dacc47a 100644 (file)
@@ -88,7 +88,8 @@ class ImportantActions extends Action\AbstractAction {
                        ->assign('databasePort', $GLOBALS['TYPO3_CONF_VARS']['DB']['port'])
                        ->assign('databaseSocket', $GLOBALS['TYPO3_CONF_VARS']['DB']['socket'])
                        ->assign('databaseNumberOfTables', count($this->getDatabase()->admin_get_tables()))
-                       ->assign('extensionCompatibilityTesterProtocolFile', GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'typo3temp/ExtensionCompatibilityTester.txt');
+                       ->assign('extensionCompatibilityTesterProtocolFile', GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'typo3temp/ExtensionCompatibilityTester.txt')
+                       ->assign('extensionCompatibilityTesterErrorProtocolFile', GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'typo3temp/ExtensionCompatibilityTesterErrors.json');
 
                return $this->view->render();
        }
index 6e83b00..0c59cd4 100644 (file)
@@ -5,7 +5,7 @@
 </p>
 <form method="post">
        <f:render partial="Action/Common/HiddenFormFields" arguments="{_all}" />
-       <div id="checkExtensions" data-protocolurl="{extensionCompatibilityTesterProtocolFile}">
+       <div id="checkExtensions" data-protocolurl="{extensionCompatibilityTesterProtocolFile}" data-errorprotocolurl="{extensionCompatibilityTesterErrorProtocolFile}">
                <f:render partial="Action/Common/StatusMessage" arguments="{
                        message: {severity:'loading', title:'', message:'Loading...'}
                }" />
index 1336147..64b2949 100644 (file)
@@ -495,14 +495,26 @@ function handleCheckExtensionsSuccess() {
                        } else {
                                $('.typo3-message', '#checkExtensions').hide();
                                $('.message-ok', '#checkExtensions').show();
-
                        }
                },
-               error: function(data) {
+               error: function() {
                        $('.typo3-message', '#checkExtensions').hide();
                        $('.message-ok', '#checkExtensions').show();
                }
-       })
+       });
+       $.getJSON(
+               $('#checkExtensions').data('errorprotocolurl'),
+               function(data) {
+                       $.each(data, function(i, error) {
+                               var messageToDisplay = error.message + ' in ' + error.file + ' on line ' + error.line;
+                               $('#checkExtensions .typo3-message.message-error').before($(
+                                       '<div class="typo3-message message-warning"><div class="header-container"><div class="message-header">' +
+                                       '<strong>' + error.type + '</strong></div><div class="message-body">' +
+                                       messageToDisplay + '</div></div></div><p></p>'
+                               ));
+                       });
+               }
+       );
 }
 
 /**