[TASK] EXT:reports Improve xclass reporting 76/17776/4
authorChristian Kuhn <lolli@schwarzbu.ch>
Mon, 28 Jan 2013 22:19:47 +0000 (23:19 +0100)
committerJigal van Hemert <jigal@xs4all.nl>
Tue, 29 Jan 2013 07:24:11 +0000 (08:24 +0100)
Since TYPO3 CMS 6.0, the XCLASS registration changed and the old
registration style does not work anymore. Additionally, 6.0 comes
with a basic check for old XCLASS registration to warn users about
that.

The patch adds a new report for newly registered XCLASS'es and
adapts the messages to better notify that neither old nor new
registrations are a real problem, but that those classes should
be kept an eye on during upgrading.

Change-Id: I8c0052b9c7fb0e88aff62a71c9592bf51bcec7ad
Resolves: #44895
Releases: 6.1, 6.0
Reviewed-on: https://review.typo3.org/17776
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
typo3/sysext/core/Build/UnitTests.xml
typo3/sysext/reports/Classes/Report/Status/Typo3Status.php
typo3/sysext/reports/Tests/Unit/Report/Status/Typo3StatusTest.php [new file with mode: 0644]
typo3/sysext/reports/reports/locallang.xlf

index ed31355..1bff3f5 100644 (file)
@@ -55,6 +55,9 @@
                <testsuite name="EXT:lowlevel tests">
                        <directory>../../../../typo3/sysext/lowlevel/Tests/Unit/</directory>
                </testsuite>
+               <testsuite name="EXT:reports tests">
+                       <directory>../../../../typo3/sysext/reports/Tests/Unit/</directory>
+               </testsuite>
                <testsuite name="EXT:saltedpasswords tests">
                        <directory>../../../../typo3/sysext/saltedpasswords/Tests/Unit/</directory>
                </testsuite>
index 92a16eb..27258bf 100644 (file)
@@ -39,7 +39,8 @@ class Typo3Status implements \TYPO3\CMS\Reports\StatusProviderInterface {
        public function getStatus() {
                $statuses = array(
                        'Typo3Version' => $this->getTypo3VersionStatus(),
-                       'oldXclassStatus' => $this->getOldXclassUsageStatus()
+                       'oldXclassStatus' => $this->getOldXclassUsageStatus(),
+                       'registeredXclass' => $this->getRegisteredXclassStatus(),
                );
                return $statuses;
        }
@@ -62,14 +63,70 @@ class Typo3Status implements \TYPO3\CMS\Reports\StatusProviderInterface {
                $message = '';
                $value = $GLOBALS['LANG']->getLL('status_none');
                $severity = \TYPO3\CMS\Reports\Status::OK;
-               $xclasses = array_merge((array) $GLOBALS['TYPO3_CONF_VARS']['BE']['XCLASS'], (array) $GLOBALS['TYPO3_CONF_VARS']['FE']['XCLASS']);
+
+               $xclasses = array_merge(
+                       (array) $GLOBALS['TYPO3_CONF_VARS']['BE']['XCLASS'],
+                       (array) $GLOBALS['TYPO3_CONF_VARS']['FE']['XCLASS']
+               );
+
                $numberOfXclasses = count($xclasses);
                if ($numberOfXclasses > 0) {
                        $value = sprintf($GLOBALS['LANG']->getLL('status_oldXclassUsageFound'), $numberOfXclasses);
-                       $message = '<ol><li>' . implode('</li><li>', $xclasses) . '</li></ol>';
-                       $severity = \TYPO3\CMS\Reports\Status::WARNING;
+                       $message = $GLOBALS['LANG']->getLL('status_oldXclassUsageFound_message') . '<br />';
+                       $message .= '<ol><li>' . implode('</li><li>', $xclasses) . '</li></ol>';
+                       $severity = \TYPO3\CMS\Reports\Status::NOTICE;
                }
-               return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->getLL('status_oldXclassUsage'), $value, $message, $severity);
+
+               return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
+                       'TYPO3\\CMS\\Reports\\Status',
+                       $GLOBALS['LANG']->getLL('status_oldXclassUsage'),
+                       $value,
+                       $message,
+                       $severity
+               );
+       }
+
+       /**
+        * List any Xclasses registered in the stystem
+        *
+        * @return \TYPO3\CMS\Reports\Status
+        */
+       protected function getRegisteredXclassStatus() {
+               $message = '';
+               $value = $GLOBALS['LANG']->getLL('status_none');
+               $severity = \TYPO3\CMS\Reports\Status::OK;
+
+               $xclassFoundArray = array();
+               if (array_key_exists('Objects', $GLOBALS['TYPO3_CONF_VARS']['SYS'])) {
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'] as $originalClass => $override) {
+                               if (array_key_exists('className', $override)) {
+                                       $xclassFoundArray[$originalClass] = $override['className'];
+                               }
+                       }
+               }
+               if (count($xclassFoundArray) > 0) {
+                       $value = $GLOBALS['LANG']->getLL('status_xclassUsageFound');
+                       $message = $GLOBALS['LANG']->getLL('status_xclassUsageFound_message') . '<br />';
+                       $message .= '<ol>';
+                       foreach ($xclassFoundArray as $originalClass => $xClassName) {
+                               $messageDetail = sprintf(
+                                       $GLOBALS['LANG']->getLL('status_xclassUsageFound_message_detail'),
+                                       $originalClass,
+                                       $xClassName
+                               );
+                               $message .= '<li>' . $messageDetail . '</li>';
+                       }
+                       $message .= '</ol';
+                       $severity = \TYPO3\CMS\Reports\Status::NOTICE;
+               }
+
+               return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
+                       'TYPO3\\CMS\\Reports\\Status',
+                       $GLOBALS['LANG']->getLL('status_xclassUsage'),
+                       $value,
+                       $message,
+                       $severity
+               );
        }
 
 }
diff --git a/typo3/sysext/reports/Tests/Unit/Report/Status/Typo3StatusTest.php b/typo3/sysext/reports/Tests/Unit/Report/Status/Typo3StatusTest.php
new file mode 100644 (file)
index 0000000..3266515
--- /dev/null
@@ -0,0 +1,81 @@
+<?php
+namespace TYPO3\CMS\Reports\Tests\Unit\Report\Status;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Christian Kuhn
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Test case
+ */
+class Typo3StatusTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @test
+        */
+       public function getStatusReturnsOldXclassStatusObjectWithSeverityOkIfNoOldXclassExists() {
+               $GLOBALS['TYPO3_CONF_VARS']['BE']['XCLASS'] = array();
+               $GLOBALS['TYPO3_CONF_VARS']['FE']['XCLASS'] = array();
+               $fixture = new \TYPO3\CMS\Reports\Report\Status\Typo3Status;
+               $result = $fixture->getStatus();
+               $statusObject = $result['oldXclassStatus'];
+               $this->assertSame(\TYPO3\CMS\Reports\Status::OK, $statusObject->getSeverity());
+       }
+
+       /**
+        * @test
+        */
+       public function getStatusReturnsOldXclassStatusObjectWithSeverityNoticeIfOldXclassExists() {
+               $GLOBALS['TYPO3_CONF_VARS']['BE']['XCLASS'] = array('foo' => 'bar');
+               $fixture = new \TYPO3\CMS\Reports\Report\Status\Typo3Status;
+               $result = $fixture->getStatus();
+               $statusObject = $result['oldXclassStatus'];
+               $this->assertSame(\TYPO3\CMS\Reports\Status::NOTICE, $statusObject->getSeverity());
+       }
+
+       /**
+        * @test
+        */
+       public function getStatusReturnsXclassStatusObjectWithSeverityOkIfNoXclassExists() {
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'] = array();
+               $fixture = new \TYPO3\CMS\Reports\Report\Status\Typo3Status;
+               $result = $fixture->getStatus();
+               $statusObject = $result['registeredXclass'];
+               $this->assertSame(\TYPO3\CMS\Reports\Status::OK, $statusObject->getSeverity());
+       }
+
+       /**
+        * @test
+        */
+       public function getStatusReturnsXclassStatusObjectWithSeverityNoticeIfXclassExists() {
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'] = array(
+                       'foo' => array(
+                               'className' => 'bar',
+                       )
+               );
+               $fixture = new \TYPO3\CMS\Reports\Report\Status\Typo3Status;
+               $result = $fixture->getStatus();
+               $statusObject = $result['registeredXclass'];
+               $this->assertSame(\TYPO3\CMS\Reports\Status::NOTICE, $statusObject->getSeverity());
+       }
+}
+?>
\ No newline at end of file
index 19505e9..796bf56 100644 (file)
@@ -252,6 +252,21 @@ You can increase the size to 8MB (default on unix) by adding to the httpd.conf:
                        <trans-unit id="status_oldXclassUsageFound" xml:space="preserve">
                                <source>Old XCLASS method is used in %d cases:</source>
                        </trans-unit>
+                       <trans-unit id="status_oldXclassUsageFound_message" xml:space="preserve">
+                               <source>The old XCLASS registration does not work since TYPO3 CMS version 6.0. This is not necessarily a bad thing, the registration might be done by an extension author to keep compatibility with older TYPO3 CMS versions. Please check the affected extension for TYPO3 CMS 6.0 compatibility to verify whether this is a problem for you.</source>
+                       </trans-unit>
+                       <trans-unit id="status_xclassUsage" xml:space="preserve">
+                               <source>XCLASS used</source>
+                       </trans-unit>
+                       <trans-unit id="status_xclassUsageFound" xml:space="preserve">
+                               <source>Your system registers XCLASS</source>
+                       </trans-unit>
+                       <trans-unit id="status_xclassUsageFound_message" xml:space="preserve">
+                               <source>XCLASS can overwrite methods or classes of the core or other extensions. This is not necessarily a bad thing, but those XCLASS might break during extension or core upgrades. You should keep an eye on extension compatibility and make sure the intended functionality is still given after updates.</source>
+                       </trans-unit>
+                       <trans-unit id="status_xclassUsageFound_message_detail" xml:space="preserve">
+                               <source>%2s registers an XCLASS of %1s</source>
+                       </trans-unit>
                </body>
        </file>
 </xliff>