[BUGFIX] Handle cache tables in install tool and em
authorChristian Kuhn <lolli@schwarzbu.ch>
Sun, 14 Aug 2011 16:17:01 +0000 (18:17 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 18 Aug 2011 18:00:11 +0000 (20:00 +0200)
This patch moves the needed table definition for a cache from the caching
framework to the install tool and the extension manager. This way the cf
tables are handled just like every other table and show up for example in
compare wizard of install tool and if an extension is installed that
registers own caches (like extbase).

Change-Id: I61e7dd1b1fbe970529810876bc7137986f9ae656
Resolves: #28973
Reviewed-on: http://review.typo3.org/4323
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
t3lib/cache/backend/class.t3lib_cache_backend_dbbackend.php
t3lib/cache/backend/resources/dbbackend-layout-cache.sql
t3lib/class.t3lib_cache.php
t3lib/class.t3lib_install_sql.php
t3lib/config_default.php
tests/t3lib/cache/backend/class.t3lib_cache_backend_dbbackendTest.php
typo3/sysext/em/classes/index.php
typo3/sysext/em/classes/install/class.tx_em_install.php
typo3/sysext/install/mod/class.tx_install.php

index 40a0c0d..2eef8c4 100644 (file)
@@ -104,9 +104,8 @@ class t3lib_cache_backend_DbBackend extends t3lib_cache_backend_AbstractBackend
        public function setCache(t3lib_cache_frontend_Frontend $cache) {
                parent::setCache($cache);
 
-               $tablePrefix = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['tablePrefix'];
-               $this->cacheTable = $tablePrefix . $this->cacheIdentifier;
-               $this->tagsTable = $tablePrefix . $this->cacheIdentifier . '_tags';
+               $this->cacheTable = 'cf_' .$this->cacheIdentifier;
+               $this->tagsTable = 'cf_' . $this->cacheIdentifier . '_tags';
                $this->initializeCommonReferences();
        }
 
@@ -208,10 +207,6 @@ class t3lib_cache_backend_DbBackend extends t3lib_cache_backend_AbstractBackend
                                ' AND ' . $this->notExpiredStatement
                );
 
-               if (strlen($GLOBALS['TYPO3_DB']->sql_error()) > 0) {
-                       $this->flush();
-               }
-
                if (is_array($cacheEntry)) {
                        $cacheEntry = $cacheEntry['content'];
                }
@@ -313,10 +308,6 @@ class t3lib_cache_backend_DbBackend extends t3lib_cache_backend_AbstractBackend
 
                $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery($this->cacheTable);
                $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery($this->tagsTable);
-               $GLOBALS['TYPO3_DB']->admin_query('DROP TABLE IF EXISTS ' . $this->cacheTable);
-               $GLOBALS['TYPO3_DB']->admin_query('DROP TABLE IF EXISTS ' . $this->tagsTable);
-               $this->createCacheTable();
-               $this->createTagsTable();
        }
 
        /**
@@ -459,25 +450,18 @@ class t3lib_cache_backend_DbBackend extends t3lib_cache_backend_AbstractBackend
        }
 
        /**
-        * Create data table of cache
-        *
-        * @return void
-        */
-       protected function createCacheTable() {
-               $sql = file_get_contents(PATH_t3lib . 'cache/backend/resources/dbbackend-layout-cache.sql');
-               $sql = str_replace('###CACHE_TABLE###', $this->cacheTable, $sql);
-               $GLOBALS['TYPO3_DB']->admin_query($sql);
-       }
-
-       /**
-        * Create tags table of cache
+        * Calculate needed table definitions for this cache.
+        * This helper method is used by install tool and extension manager
+        * and is not part of the public API!
         *
-        * @return void
-        */
-       protected function createTagsTable() {
-               $sql = file_get_contents(PATH_t3lib . 'cache/backend/resources/dbbackend-layout-tags.sql');
-               $sql = str_replace('###TAGS_TABLE###', $this->tagsTable, $sql);
-               $GLOBALS['TYPO3_DB']->admin_query($sql);
+        * @return string SQL of table definitions
+        */
+       public function getTableDefinitions() {
+               $cacheTableSql = file_get_contents(PATH_t3lib . 'cache/backend/resources/dbbackend-layout-cache.sql');
+               $requiredTableStructures = str_replace('###CACHE_TABLE###', $this->cacheTable, $cacheTableSql) . LF . LF;
+               $tagsTableSql = file_get_contents(PATH_t3lib . 'cache/backend/resources/dbbackend-layout-tags.sql');
+               $requiredTableStructures .= str_replace('###TAGS_TABLE###', $this->tagsTable, $tagsTableSql) . LF;
+               return $requiredTableStructures;
        }
 
        /**
index 78759b6..1730855 100644 (file)
@@ -4,5 +4,5 @@ CREATE TABLE ###CACHE_TABLE### (
        expires int(11) unsigned DEFAULT '0' NOT NULL,
        content mediumblob,
        PRIMARY KEY (id),
-       KEY cache_id (identifier, expires)
+       KEY cache_id (identifier,expires)
 ) ENGINE=InnoDB;
\ No newline at end of file
index 1d1ab02..28841e0 100644 (file)
@@ -112,5 +112,24 @@ class t3lib_cache {
        public function enableCachingFramework() {
                t3lib_div::logDeprecatedFunction();
        }
+
+       /**
+        * Helper method for install tool and extension manager to determine
+        * required table structure of all caches that depend on it
+        *
+        * This is not a public API method!
+        *
+        * @return string Required table structure of all registered caches
+        */
+       public function getDatabaseTableDefinitions() {
+               $tableDefinitions = '';
+               foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $cacheName => $_) {
+                       $backend = $GLOBALS['typo3CacheManager']->getCache($cacheName)->getBackend();
+                       if (method_exists($backend, 'getTableDefinitions')) {
+                               $tableDefinitions .= LF . $backend->getTableDefinitions();
+                       }
+               }
+               return $tableDefinitions;
+       }
 }
 ?>
\ No newline at end of file
index e5c1d20..1b961cf 100644 (file)
@@ -41,11 +41,6 @@ class t3lib_install_Sql {
        protected $deletedPrefixKey = 'zzz_deleted_'; // Prefix used for tables/fields when deleted/renamed.
 
        /**
-        * @var array Tables starting with this name are ignored during compare
-        */
-       protected $ignoreTablePrefixes = array();
-
-       /**
         * @var float|int Multiplier of SQL field size (for char, varchar and text fields)
         */
        protected $multiplySize = 1;
@@ -62,7 +57,6 @@ class t3lib_install_Sql {
                if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['multiplyDBfieldSize'] >= 1 && $GLOBALS['TYPO3_CONF_VARS']['SYS']['multiplyDBfieldSize'] <= 5) {
                        $this->multiplySize = (double) $GLOBALS['TYPO3_CONF_VARS']['SYS']['multiplyDBfieldSize'];
                }
-               $this->ignoreTablePrefixes[] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['tablePrefix'];
        }
 
        /**
@@ -529,19 +523,8 @@ class t3lib_install_Sql {
                                        if ($info['whole_table']) {
                                                if ($remove) {
                                                        if (substr($table, 0, strlen($deletedPrefixKey)) != $deletedPrefixKey) {
-                                                                       // Ignore table operation if the table name starts with a
-                                                                       // prefix that should be ignored
-                                                               $ignoreTable = FALSE;
-                                                               foreach ($this->ignoreTablePrefixes as $ignorePrefix) {
-                                                                       if (substr($table, 0, strlen($ignorePrefix)) === $ignorePrefix) {
-                                                                               $ignoreTable = TRUE;
-                                                                               break;
-                                                                       }
-                                                               }
-                                                               if (!$ignoreTable) {
-                                                                       $statement = 'ALTER TABLE ' . $table . ' RENAME ' . $deletedPrefixKey . $table . ';';
-                                                                       $statements['change_table'][md5($statement)] = $statement;
-                                                               }
+                                                               $statement = 'ALTER TABLE ' . $table . ' RENAME ' . $deletedPrefixKey . $table . ';';
+                                                               $statements['change_table'][md5($statement)] = $statement;
                                                        } else {
                                                                $statement = 'DROP TABLE ' . $table . ';';
                                                                $statements['drop_table'][md5($statement)] = $statement;
index 230f928..d7e4199 100644 (file)
@@ -125,7 +125,6 @@ $TYPO3_CONF_VARS = array(
                'reverseProxySSL' => '',                                // String: '*' or list of IP addresses of proxies that use SSL (https) for the connection to the client, but an unencrypted connection (http) to the server. If '*' all proxies defined in <a href="#SYS-reverseProxyIP">[SYS][reverseProxyIP]</a> use SSL.
                'reverseProxyPrefixSSL' => '',                          // String: prefix to be added to the internal URL (SCRIPT_NAME and REQUEST_URI) when accessing the server via an SSL proxy. This setting overrides <a href="#SYS-reverseProxyPrefix">[SYS][reverseProxyPrefix]</a>.
                'caching' => array(
-                       'tablePrefix' => 'cachingframework_',
                        'cacheConfigurations' => array(
                                'cache_hash' => array(
                                        'frontend' => 't3lib_cache_frontend_VariableFrontend',
index 7eab1b3..78b1cdf 100644 (file)
@@ -66,7 +66,7 @@ class t3lib_cache_backend_DbBackendTest extends tx_phpunit_testcase {
         */
        public function setUp() {
                $this->typo3DbBackup = $GLOBALS['TYPO3_DB'];
-               $tablePrefix = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['tablePrefix'];
+               $tablePrefix = 'cf_';
                $this->testingCacheTable = $tablePrefix . 'Testing';
                $this->testingTagsTable = $tablePrefix . 'Testing_tags';
        }
@@ -523,88 +523,6 @@ class t3lib_cache_backend_DbBackendTest extends tx_phpunit_testcase {
 
        /**
         * @test
-        */
-       public function flushDropsDataTable() {
-               $backend = $this->setUpBackend();
-               $this->setUpMockFrontendOfBackend($backend);
-
-               $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('exec_TRUNCATEquery', 'INSERTquery', 'sql_query', 'admin_query'));
-               $GLOBALS['TYPO3_DB']->expects($this->at(2))
-                       ->method('admin_query')
-                       ->with('DROP TABLE IF EXISTS ' . $this->testingCacheTable);
-
-               $backend->flush();
-       }
-
-       /**
-        * @test
-        */
-       public function flushDropsTagsTable() {
-               $backend = $this->setUpBackend();
-               $this->setUpMockFrontendOfBackend($backend);
-
-               $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('exec_TRUNCATEquery', 'INSERTquery', 'sql_query', 'admin_query'));
-               $GLOBALS['TYPO3_DB']->expects($this->at(3))
-                       ->method('admin_query')
-                       ->with('DROP TABLE IF EXISTS ' . $this->testingTagsTable);
-
-               $backend->flush();
-       }
-
-       /**
-        * @test
-        */
-       public function flushCreatesDataTable() {
-               $backend = $this->setUpBackend();
-               $this->setUpMockFrontendOfBackend($backend);
-
-               $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('exec_TRUNCATEquery', 'INSERTquery', 'sql_query', 'admin_query'));
-               $GLOBALS['TYPO3_DB']->expects($this->at(4))
-                       ->method('admin_query')
-                       ->will($this->returnCallback(array($this, flushCreatesDataTableCallback)));
-
-               $backend->flush();
-       }
-
-       /**
-        * Callback of flushCreatesDataTable to check if data table is created
-        *
-        * @param string $sql SQL of admin_query
-        * @return void
-        */
-       public function flushCreatesDataTableCallback($sql) {
-               $startOfStatement = 'CREATE TABLE ' . $this->testingCacheTable . ' (';
-               $this->assertEquals($startOfStatement, substr($sql, 0, strlen($startOfStatement)));
-       }
-
-       /**
-        * @test
-        */
-       public function flushCreatesTagsTable() {
-               $backend = $this->setUpBackend();
-               $this->setUpMockFrontendOfBackend($backend);
-
-               $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('exec_TRUNCATEquery', 'INSERTquery', 'sql_query', 'admin_query'));
-               $GLOBALS['TYPO3_DB']->expects($this->at(5))
-                       ->method('admin_query')
-                       ->will($this->returnCallback(array($this, flushCreatesTagsTableCallback)));
-
-               $backend->flush();
-       }
-
-       /**
-        * Callback of flushCreatesTagsTable to check if tags table is created
-        *
-        * @param string $sql SQL of admin_query
-        * @return void
-        */
-       public function flushCreatesTagsTableCallback($sql) {
-               $startOfStatement = 'CREATE TABLE ' . $this->testingTagsTable . ' (';
-               $this->assertEquals($startOfStatement, substr($sql, 0, strlen($startOfStatement)));
-       }
-
-       /**
-        * @test
         * @expectedException t3lib_cache_Exception
         */
        public function flushByTagThrowsExceptionIfFrontendWasNotSet() {
index 336e2e3..f102942 100644 (file)
@@ -1609,9 +1609,12 @@ class SC_mod_tools_em_index extends t3lib_SCbase {
                                                                );
                                                                t3lib_FlashMessageQueue::addMessage($flashMessage);
                                                        }
+                                                       $techInfo = $this->install->makeDetailedExtensionAnalysis($extKey, $list[$extKey]);
                                                        if ($this->CMD['clrCmd'] || t3lib_div::_GP('_clrCmd')) {
                                                                if ($this->CMD['load'] && @is_file($absPath . 'ext_conf_template.txt')) {
                                                                        $vA = array('CMD' => array('showExt' => $extKey));
+                                                               } elseif ($this->CMD['load'] && $techInfo['hasCacheConfiguration']) {
+                                                                       $vA = array('CMD' => array('showExt' => $extKey));
                                                                } else {
                                                                        $vA = array('CMD' => '');
                                                                }
@@ -1629,7 +1632,6 @@ class SC_mod_tools_em_index extends t3lib_SCbase {
                                                                                '<br /><br />' . $this->getSubmitAndOpenerCloseLink();
                                                        } else {
                                                                // Determine if new modules were installed:
-                                                               $techInfo = $this->install->makeDetailedExtensionAnalysis($extKey, $list[$extKey]);
                                                                if (($this->CMD['load'] || $this->CMD['remove']) && is_array($techInfo['flags']) && in_array('Module', $techInfo['flags'], TRUE)) {
                                                                        $vA['CMD']['refreshMenu'] = 1;
                                                                }
index ee83ebe..4bd5597 100644 (file)
@@ -825,6 +825,7 @@ class tx_em_Install {
                if (is_array($extInfo['files']) && in_array('ext_tables.sql', $extInfo['files'])) {
                        $path = tx_em_Tools::getExtPath($extKey, $extInfo['type']);
                        $fileContent = t3lib_div::getUrl($path . 'ext_tables.sql');
+                       $fileContent .= t3lib_cache::getDatabaseTableDefinitions();
 
                        $FDfile = $this->installerSql->getFieldDefinitions_fileContent($fileContent);
                        if (count($FDfile)) {
@@ -1193,6 +1194,10 @@ class tx_em_Install {
                        }
                }
 
+               if ($this->extensionHasCacheConfiguration($absPath)) {
+                       $infoArray['hasCacheConfiguration'] = TRUE;
+               }
+
                if (@is_file($absPath . 'ext_typoscript_constants.txt')) {
                        $infoArray['TSfiles'][] = $GLOBALS['LANG']->getLL('detailedExtAnalysis_constants');
                }
@@ -1267,8 +1272,7 @@ class tx_em_Install {
                $form = '';
 
                        // Look for template file for form:
-               if (t3lib_extMgm::isLoaded($extKey) && @is_file($absPath . 'ext_conf_template.txt')) {
-
+               if (t3lib_extMgm::isLoaded($extKey) && (@is_file($absPath . 'ext_conf_template.txt') || $this->extensionHasCacheConfiguration($absPath))) {
                                // Load tsStyleConfig class and parse configuration template:
                        $tsStyleConfig = t3lib_div::makeInstance('t3lib_tsStyleConfig');
                        $tsStyleConfig->doNotSortCategoriesBeforeMakingForm = TRUE;
@@ -1367,9 +1371,24 @@ class tx_em_Install {
                                </table>';
                }
 
-
                return $form;
+       }
 
+       /**
+        * Determine if an extension defines own caching framework caches
+        *
+        * @param string $extensionAbsolutePath Path to extension
+        * @return boolean TRUE if extension defines own caches
+        */
+       protected function extensionHasCacheConfiguration($extensionAbsolutePath) {
+               $result = FALSE;
+               if (@is_file($extensionAbsolutePath . 'ext_localconf.php')) {
+                       $content = t3lib_div::getUrl($extensionAbsolutePath . 'ext_localconf.php');
+                       if (stristr($content, 'cacheConfigurations')) {
+                               $result = TRUE;
+                       }
+               }
+               return $result;
        }
 
        /**
@@ -1429,7 +1448,7 @@ class tx_em_Install {
                $updates .= $extensionDetails->checkUploadFolder($extKey, $extInfo);
 
                $absPath = tx_em_Tools::getExtPath($extKey, $extInfo['type']);
-               if ($notSilent && @is_file($absPath . 'ext_conf_template.txt')) {
+               if ($notSilent && @is_file($absPath . 'ext_conf_template.txt') || $this->extensionHasCacheConfiguration($absPath)) {
                        $configForm = $this->tsStyleConfigForm($extKey, $extInfo, 1, $script, $updates . $addFields . '<br />');
                }
 
@@ -1535,6 +1554,7 @@ class tx_em_Install {
                // Updating tables and fields?
                if (is_array($extInfo['files']) && in_array('ext_tables.sql', $extInfo['files'])) {
                        $fileContent = t3lib_div::getUrl(tx_em_Tools::getExtPath($extKey, $extInfo['type']) . 'ext_tables.sql');
+                       $fileContent .= t3lib_cache::getDatabaseTableDefinitions();
 
                        $FDfile = $this->installerSql->getFieldDefinitions_fileContent($fileContent);
                        if (count($FDfile)) {
index abf4496..a8a4199 100755 (executable)
@@ -5528,6 +5528,7 @@ REMOTE_ADDR was '".t3lib_div::getIndpEnv('REMOTE_ADDR')."' (".t3lib_div::getIndp
                                        } elseif (@is_file($actionParts[1])) {
                                                $tblFileContent = t3lib_div::getUrl($actionParts[1]);
                                        }
+                                       $tblFileContent .= t3lib_cache::getDatabaseTableDefinitions();
                                        if ($tblFileContent) {
                                                $fileContent = implode(
                                                        LF,