Revert "[BUGFIX] Make category TCA changes cacheable" 80/29480/3
authorHelmut Hummel <helmut.hummel@typo3.org>
Tue, 15 Apr 2014 11:27:33 +0000 (13:27 +0200)
committerHelmut Hummel <helmut.hummel@typo3.org>
Tue, 15 Apr 2014 13:28:38 +0000 (15:28 +0200)
This reverts commit 2b4aeefc27719e0147858f7b0c82a70249a53749

This is reverted in favor of a better approach that makes
caching for every TCA additions or override possible.

Besides that, this change introduced a regression, as
database compare in install tool does not work properly any more.

Change-Id: I4fc0d3d76f28afd8ff82ae5537ff3b207fa53bae
Reviewed-on: https://review.typo3.org/29480
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/core/Classes/Category/CategoryRegistry.php
typo3/sysext/core/Classes/Core/Bootstrap.php
typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
typo3/sysext/core/Tests/Unit/Category/CategoryRegistryTest.php
typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php
typo3/sysext/core/ext_localconf.php

index 323140d..cf80f37 100644 (file)
@@ -221,7 +221,7 @@ class CategoryRegistry implements \TYPO3\CMS\Core\SingletonInterface {
         *
         * @return void
         */
-       protected function applyTca() {
+       public function applyTca() {
 
                $this->registerDefaultCategorizedTables();
 
@@ -236,18 +236,6 @@ class CategoryRegistry implements \TYPO3\CMS\Core\SingletonInterface {
        }
 
        /**
-        * Slot that is registered for tcaIsBeingBuilt
-        * TCA changes are applied and then cached in ExtensionManagementUtility
-        *
-        * @param array $tca
-        * @return array
-        */
-       public function addCategoryRegistryTcaChanges(array $tca) {
-               $this->applyTca();
-               return array($GLOBALS['TCA']);
-       }
-
-       /**
         * Add default categorized tables to the registry
         *
         * @return void
index 729bbb7..056eac6 100644 (file)
@@ -946,6 +946,9 @@ class Bootstrap {
                if (file_exists($extTablesFile) && is_file($extTablesFile)) {
                        include $extTablesFile;
                }
+
+               // Apply TCA onto tables to be categorized
+               \TYPO3\CMS\Core\Category\CategoryRegistry::getInstance()->applyTca();
        }
 
        /**
index 3170a47..35d74de 100644 (file)
@@ -1924,7 +1924,6 @@ tt_content.' . $key . $prefix . ' {
 
        /**
         * Makes a table categorizable by adding value into the category registry.
-        * FOR USE IN ext_localconf.php FILES.
         *
         * @param string $extensionKey Extension key to be used
         * @param string $tableName Name of the table to be categorized
index b6943d7..51dff1e 100644 (file)
@@ -35,7 +35,7 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @var \TYPO3\CMS\Core\Category\CategoryRegistry
         */
-       protected $subject;
+       protected $fixture;
 
        /**
         * @var array
@@ -46,7 +46,7 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * Sets up this test suite.
         */
        protected function setUp() {
-               $this->subject = new \TYPO3\CMS\Core\Category\CategoryRegistry();
+               $this->fixture = new \TYPO3\CMS\Core\Category\CategoryRegistry();
                $this->tables = array(
                        'first' => uniqid('first'),
                        'second' => uniqid('second')
@@ -66,7 +66,7 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function doesAddReturnTrueOnDefinedTable() {
-               $this->assertTrue($this->subject->add('test_extension_a', $this->tables['first'], 'categories'));
+               $this->assertTrue($this->fixture->add('test_extension_a', $this->tables['first'], 'categories'));
        }
 
        /**
@@ -75,78 +75,65 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @expectedExceptionCode 1369122038
         */
        public function doesAddThrowExceptionOnEmptyTablename() {
-               $this->subject->add('test_extension_a', '', 'categories');
-       }
-
-       /**
-        * @test
-        */
-       public function addCategoryRegistryTcaChangesReturnsGlobalTcaArray() {
-               $GLOBALS['TCA'] = array(
-                       'foo' => array(
-                               'bar' => 'baz'
-                       )
-               );
-               list($tca) = $this->subject->addCategoryRegistryTcaChanges($GLOBALS['TCA']);
-               $this->assertSame($tca, $GLOBALS['TCA']);
+               $this->fixture->add('test_extension_a', '', 'categories');
        }
 
        /**
         * @test
         */
        public function areMultipleElementsOfSameExtensionRegistered() {
-               $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
-               $this->subject->add('test_extension_a', $this->tables['second'], 'categories');
-               list($tca) = $this->subject->addCategoryRegistryTcaChanges(array());
+               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
+               $this->fixture->add('test_extension_a', $this->tables['second'], 'categories');
+               $this->fixture->applyTca();
 
-               $this->assertArrayHasKey('categories', $tca[$this->tables['first']]['columns']);
-               $this->assertArrayHasKey('categories', $tca[$this->tables['second']]['columns']);
+               $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['first']]['columns']);
+               $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['second']]['columns']);
        }
 
        /**
         * @test
         */
        public function areElementsOfDifferentExtensionsRegistered() {
-               $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
-               $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
-               list($tca) = $this->subject->addCategoryRegistryTcaChanges(array());
+               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
+               $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
+               $this->fixture->applyTca();
 
-               $this->assertArrayHasKey('categories', $tca[$this->tables['first']]['columns']);
-               $this->assertArrayHasKey('categories', $tca[$this->tables['second']]['columns']);
+               $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['first']]['columns']);
+               $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['second']]['columns']);
        }
 
        /**
         * @test
         */
        public function areElementsOfDifferentExtensionsOnSameTableRegistered() {
-               $this->subject->add('test_extension_a', $this->tables['first'], 'categories1');
-               $this->subject->add('test_extension_b', $this->tables['first'], 'categories2');
-               list($tca) = $this->subject->addCategoryRegistryTcaChanges(array());
+               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories1');
+               $this->fixture->add('test_extension_b', $this->tables['first'], 'categories2');
+               $this->fixture->applyTca();
 
-               $this->assertArrayHasKey('categories1', $tca[$this->tables['first']]['columns']);
-               $this->assertArrayHasKey('categories2', $tca[$this->tables['first']]['columns']);
+               $this->assertArrayHasKey('categories1', $GLOBALS['TCA'][$this->tables['first']]['columns']);
+               $this->assertArrayHasKey('categories2', $GLOBALS['TCA'][$this->tables['first']]['columns']);
        }
 
        /**
         * @test
         */
        public function areElementsOfSameExtensionOnSameTableRegistered() {
-               $this->subject->add('test_extension_a', $this->tables['first'], 'categories1');
-               $this->subject->add('test_extension_a', $this->tables['first'], 'categories2');
-               list($tca) = $this->subject->addCategoryRegistryTcaChanges(array());
+               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories1');
+               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories2');
+               $this->fixture->applyTca();
 
-               $this->assertArrayHasKey('categories1', $tca[$this->tables['first']]['columns']);
-               $this->assertArrayHasKey('categories2', $tca[$this->tables['first']]['columns']);
+               $this->assertArrayHasKey('categories1', $GLOBALS['TCA'][$this->tables['first']]['columns']);
+               $this->assertArrayHasKey('categories2', $GLOBALS['TCA'][$this->tables['first']]['columns']);
        }
 
        /**
         * @test
         */
        public function areDatabaseDefinitionsOfAllElementsAvailable() {
-               $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
-               $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
-               $this->subject->add('test_extension_c', $this->tables['first'], 'categories');
-               $definitions = $this->subject->getDatabaseTableDefinitions();
+               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
+               $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
+               $this->fixture->add('test_extension_c', $this->tables['first'], 'categories');
+               $definitions = $this->fixture->getDatabaseTableDefinitions();
                $matches = array();
                preg_match_all('#CREATE TABLE\\s*([^ (]+)\\s*\\(\\s*([^ )]+)\\s+int\\(11\\)[^)]+\\);#mis', $definitions, $matches);
                $this->assertEquals(2, count($matches[0]));
@@ -160,9 +147,9 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function areDatabaseDefinitionsOfParticularExtensionAvailable() {
-               $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
-               $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
-               $definitions = $this->subject->getDatabaseTableDefinition('test_extension_a');
+               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
+               $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
+               $definitions = $this->fixture->getDatabaseTableDefinition('test_extension_a');
                $matches = array();
                preg_match_all('#CREATE TABLE\\s*([^ (]+)\\s*\\(\\s*([^ )]+)\\s+int\\(11\\)[^)]+\\);#mis', $definitions, $matches);
                $this->assertEquals(1, count($matches[0]));
@@ -175,49 +162,49 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         */
        public function areDefaultCategorizedTablesLoaded() {
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultCategorizedTables'] = $this->tables['first'] . ',' . $this->tables['second'];
-               list($tca) = $this->subject->addCategoryRegistryTcaChanges(array());
+               $this->fixture->applyTca();
 
-               $this->assertArrayHasKey('categories', $tca[$this->tables['first']]['columns']);
-               $this->assertArrayHasKey('categories', $tca[$this->tables['second']]['columns']);
+               $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['first']]['columns']);
+               $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['second']]['columns']);
        }
 
        /**
         * @test
         */
        public function canApplyTca() {
-               $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
-               $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
-               list($tca) = $this->subject->addCategoryRegistryTcaChanges(array());
+               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
+               $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
+               $this->fixture->applyTca();
 
-               $this->assertNotEmpty($tca[$this->tables['first']]['columns']['categories']);
-               $this->assertNotEmpty($tca[$this->tables['second']]['columns']['categories']);
+               $this->assertNotEmpty($GLOBALS['TCA'][$this->tables['first']]['columns']['categories']);
+               $this->assertNotEmpty($GLOBALS['TCA'][$this->tables['second']]['columns']['categories']);
        }
 
        /**
         * @test
         */
        public function isRegisteredReturnsTrueIfElementIsAlreadyRegistered() {
-               $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
-               $this->assertTrue($this->subject->isRegistered($this->tables['first'], 'categories'));
+               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
+               $this->assertTrue($this->fixture->isRegistered($this->tables['first'], 'categories'));
        }
 
        /**
         * @test
         */
        public function isRegisteredReturnsFalseIfElementIsNotRegistered() {
-               $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
-               $this->assertFalse($this->subject->isRegistered($this->tables['first'], '_not_registered'));
-               $this->assertFalse($this->subject->isRegistered($this->tables['second'], 'categories'));
+               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
+               $this->assertFalse($this->fixture->isRegistered($this->tables['first'], '_not_registered'));
+               $this->assertFalse($this->fixture->isRegistered($this->tables['second'], 'categories'));
        }
 
        /**
         * @test
         */
        public function tabIsAddedForElement() {
-               $this->subject->add('text_extension_a', $this->tables['first']);
-               list($tca) = $this->subject->addCategoryRegistryTcaChanges(array());
+               $this->fixture->add('text_extension_a', $this->tables['first']);
+               $this->fixture->applyTca();
 
-               foreach($tca[$this->tables['first']]['types'] as $typeConfig) {
+               foreach($GLOBALS['TCA'][$this->tables['first']]['types'] as $typeConfig) {
                        $this->assertContains('--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category', $typeConfig['showitem']);
                }
        }
@@ -226,10 +213,10 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function tabIsNotAddedForElementIfFieldListIsSpecified() {
-               $this->subject->add('text_extension_a', $this->tables['first'], 'categories', array('fieldList' => 'categories'));
-               list($tca) = $this->subject->addCategoryRegistryTcaChanges(array());
+               $this->fixture->add('text_extension_a', $this->tables['first'], 'categories', array('fieldList' => 'categories'));
+               $this->fixture->applyTca();
 
-               foreach($tca[$this->tables['first']]['types'] as $typeConfig) {
+               foreach($GLOBALS['TCA'][$this->tables['first']]['types'] as $typeConfig) {
                        $this->assertNotContains('--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category', $typeConfig['showitem']);
                }
        }
@@ -238,11 +225,11 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function tabIsAddedOnlyOncePerTable() {
-               $this->subject->add('text_extension_a', $this->tables['first'], 'categories1');
-               $this->subject->add('text_extension_a', $this->tables['first'], 'categories2');
-               list($tca) = $this->subject->addCategoryRegistryTcaChanges(array());
+               $this->fixture->add('text_extension_a', $this->tables['first'], 'categories1');
+               $this->fixture->add('text_extension_a', $this->tables['first'], 'categories2');
+               $this->fixture->applyTca();
 
-               foreach($tca[$this->tables['first']]['types'] as $typeConfig) {
+               foreach($GLOBALS['TCA'][$this->tables['first']]['types'] as $typeConfig) {
                        $this->assertSame(
                                1, substr_count($typeConfig['showitem'], '--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category')
                        );
index fc6e3bb..08b9d38 100644 (file)
@@ -1337,23 +1337,24 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
        /**
         * @test
         */
-       public function doesMakeCategorizableCallsTheCategoryRegistryWithDefaultFieldName() {
+       public function isMakeCategorizableAvailableInRegistryWithDefaultField() {
                $extensionKey = uniqid('extension');
                $tableName = uniqid('table');
                $GLOBALS['TCA'][$tableName] = array(
                        'ctrl' => array(),
                        'columns' => array()
                );
-               $registryMock = $this->getMock('TYPO3\\CMS\\Core\\Category\\CategoryRegistry');
-               $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, 'categories', array());
+               $registryMock = $this->getMock('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', array('dummy'));
                \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', $registryMock);
                ExtensionManagementUtility::makeCategorizable($extensionKey, $tableName);
+               $registryMock->applyTca();
+               $this->assertNotEmpty($GLOBALS['TCA'][$tableName]['columns']['categories']);
        }
 
        /**
         * @test
         */
-       public function doesMakeCategorizableCallsTheCategoryRegistryWithFieldName() {
+       public function isMakeCategorizableAvailableInRegistryWithSpecifictField() {
                $extensionKey = uniqid('extension');
                $tableName = uniqid('table');
                $fieldName = uniqid('field');
@@ -1361,10 +1362,11 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                        'ctrl' => array(),
                        'columns' => array()
                );
-               $registryMock = $this->getMock('TYPO3\\CMS\\Core\\Category\\CategoryRegistry');
-               $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, $fieldName, array());
+               $registryMock = $this->getMock('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', array('dummy'));
                \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', $registryMock);
                ExtensionManagementUtility::makeCategorizable($extensionKey, $tableName, $fieldName);
+               $registryMock->applyTca();
+               $this->assertNotEmpty($GLOBALS['TCA'][$tableName]['columns'][$fieldName]);
        }
 
 }
index c00d7ed..60243c5 100644 (file)
@@ -2,17 +2,15 @@
 if (!defined('TYPO3_MODE')) {
        die('Access denied.');
 }
-/** @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher */
-$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
 
 if (TYPO3_MODE === 'BE' && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_INSTALL)) {
-       $signalSlotDispatcher->connect(
+       \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher')->connect(
                'TYPO3\\CMS\\Core\\Resource\\ResourceFactory',
                \TYPO3\CMS\Core\Resource\ResourceFactoryInterface::SIGNAL_PostProcessStorage,
                'TYPO3\\CMS\\Core\\Resource\\Security\\StoragePermissionsAspect',
                'addUserPermissionsToStorage'
        );
-       $signalSlotDispatcher->connect(
+       \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher')->connect(
                'PackageManagement',
                'packagesMayHaveChanged',
                'TYPO3\\CMS\\Core\\Package\\PackageManager',
@@ -20,20 +18,11 @@ if (TYPO3_MODE === 'BE' && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_INSTALL)) {
        );
 }
 
-$signalSlotDispatcher->connect(
+\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher')->connect(
        'TYPO3\\CMS\\Core\\Resource\\ResourceStorage',
        \TYPO3\CMS\Core\Resource\ResourceStorageInterface::SIGNAL_PostFileDelete,
        'TYPO3\\CMS\\Core\\Resource\\Processing\\FileDeletionAspect',
        'removeFromRepository'
 );
 
-$signalSlotDispatcher->connect(
-       'TYPO3\\CMS\\Core\\Utility\\ExtensionManagementUtility',
-       'tcaIsBeingBuilt',
-       'TYPO3\\CMS\\Core\\Category\\CategoryRegistry',
-       'addCategoryRegistryTcaChanges'
-);
-
-unset($signalSlotDispatcher);
-
 $GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['dumpFile'] = 'EXT:core/Resources/PHP/FileDumpEID.php';