[BUGFIX] Caching framework tables depends on ext_tables.sql 14/19214/4
authorNicole Cordes <typo3@cordes.co>
Sat, 23 Mar 2013 13:17:51 +0000 (14:17 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 5 Apr 2013 11:30:20 +0000 (13:30 +0200)
Since TYPO3 version 4.6 the caching framework should be responsible to
create needed tables for itself. But this is only executed when the
extension contains ext_tables.sql file in its extension folder. If you do
not need any other tables/fields no caching framework tables are created.
This should be independent from ext_tables.sql

Change-Id: Ifba3cb7bcc94d09627b38d5b5962cfdb2282306b
Fixes: #46591
Releases: 6.1, 6.0
Reviewed-on: https://review.typo3.org/19214
Reviewed-by: Sascha Egerer
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/extensionmanager/Classes/Utility/InstallUtility.php
typo3/sysext/extensionmanager/Tests/Unit/Utility/InstallUtilityTest.php

index 7eb875b..9870dd2 100644 (file)
@@ -139,6 +139,7 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
                        $this->loadExtension($extensionKey);
                }
                $this->reloadCaches();
+               $this->processCachingFrameworkUpdates();
                $this->saveDefaultConfiguration($extension['key']);
        }
 
@@ -235,11 +236,11 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
         */
        public function processDatabaseUpdates(array $extension) {
                $extTablesSqlFile = PATH_site . $extension['siteRelPath'] . '/ext_tables.sql';
+               $extTablesSqlContent = '';
                if (file_exists($extTablesSqlFile)) {
-                       $extTablesSqlContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($extTablesSqlFile);
-                               // @TODO: This should probably moved to TYPO3\CMS\Core\Cache\Cache->getDatabaseTableDefinitions ?!
-                       $GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
-                       $extTablesSqlContent .= \TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions();
+                       $extTablesSqlContent .= \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($extTablesSqlFile);
+               }
+               if ($extTablesSqlContent !== '') {
                        $this->updateDbWithExtTablesSql($extTablesSqlContent);
                }
                $extTablesStaticSqlFile = PATH_site . $extension['siteRelPath'] . '/ext_tables_static+adt.sql';
@@ -250,6 +251,23 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
        }
 
        /**
+        * Gets all registered caches and creates required caching framework tables.
+        *
+        * @return void
+        */
+       protected function processCachingFrameworkUpdates() {
+               $extTablesSqlContent = '';
+
+               // @TODO: This should probably moved to TYPO3\CMS\Core\Cache\Cache->getDatabaseTableDefinitions ?!
+               $GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
+               $extTablesSqlContent .= \TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions();
+
+               if ($extTablesSqlContent !== '') {
+                       $this->updateDbWithExtTablesSql($extTablesSqlContent);
+               }
+       }
+
+       /**
         * Reload Cache files and Typo3LoadedExtensions
         *
         * @return void
index 1fc0072..bdb9f10 100644 (file)
@@ -62,6 +62,7 @@ class InstallUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                        'unloadExtension',
                        'processDatabaseUpdates',
                        'reloadCaches',
+                       'processCachingFrameworkUpdates',
                        'saveDefaultConfiguration',
                        'enrichExtensionWithDetails',
                        'ensureConfiguredDirectoriesExist',
@@ -119,6 +120,16 @@ class InstallUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        /**
         * @test
         */
+       public function installCallsProcessCachingFrameworkUpdates() {
+               $this->installMock->expects($this->once())
+                       ->method('processCachingFrameworkUpdates');
+
+               $this->installMock->install($this->extensionKey);
+       }
+
+       /**
+        * @test
+        */
        public function installCallsLoadExtenion() {
                $this->installMock->expects($this->once())->method('loadExtension');
                $this->installMock->install($this->extensionKey);
@@ -183,29 +194,39 @@ class InstallUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        /**
         * @test
         */
-       public function processDatabaseUpdatesCallsUpdateDbWithExtTablesSqlIncludingCachingFrameworkTables() {
+       public function processDatabaseUpdatesCallsImportStaticSql() {
                $extKey = $this->createFakeExtension();
                $extPath = PATH_site . 'typo3temp/' . $extKey . '/';
-               $extTablesFile = $extPath . 'ext_tables.sql';
+               $extTablesFile = $extPath . 'ext_tables_static+adt.sql';
                $fileContent = 'DUMMY TEXT TO COMPARE';
                file_put_contents($extTablesFile, $fileContent);
-               $installMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('updateDbWithExtTablesSql'));
-               $installMock->expects($this->once())->method('updateDbWithExtTablesSql')->with($this->stringContains('CREATE TABLE cf_cache_hash'));
+               $installMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('importStaticSql'));
+               $installMock->expects($this->once())->method('importStaticSql')->with($fileContent);
                $installMock->processDatabaseUpdates($this->fakedExtensions[$extKey]);
        }
 
        /**
         * @test
         */
-       public function processDatabaseUpdatesCallsImportStaticSql() {
+       public function InstallCallsUpdateDbWithCachingFrameworkTables() {
                $extKey = $this->createFakeExtension();
-               $extPath = PATH_site . 'typo3temp/' . $extKey . '/';
-               $extTablesFile = $extPath . 'ext_tables_static+adt.sql';
-               $fileContent = 'DUMMY TEXT TO COMPARE';
-               file_put_contents($extTablesFile, $fileContent);
-               $installMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('importStaticSql'));
-               $installMock->expects($this->once())->method('importStaticSql')->with($fileContent);
-               $installMock->processDatabaseUpdates($this->fakedExtensions[$extKey]);
+               $installMock = $this->getMock(
+                       'TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility',
+                       array(
+                               'enrichExtensionWithDetails',
+                               'ensureConfiguredDirectoriesExist',
+                               'updateDbWithExtTablesSql'
+                       )
+               );
+               $installMock->expects($this->any())
+                       ->method('enrichExtensionWithDetails')
+                       ->with($extKey)
+                       ->will($this->returnValue(array('key' => $extKey)));
+               $installMock->expects($this->at(2))
+                       ->method('updateDbWithExtTablesSql')
+                       ->with($this->stringContains('CREATE TABLE cf_cache_hash'));
+
+               $installMock->install($extKey);
        }
 }
 ?>
\ No newline at end of file