Revert "[BUGFIX] Replace the table definition manipulation by signals"
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Service / SqlExpectedSchemaService.php
index 5cdee62..253e83f 100644 (file)
@@ -42,12 +42,6 @@ class SqlExpectedSchemaService {
         */
        protected $objectManager = NULL;
 
-       /**
-        * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
-        * @inject
-        */
-       protected $signalSlotDispatcher;
-
        /**
         * Get expected schema array
         *
@@ -87,31 +81,50 @@ class SqlExpectedSchemaService {
                        }
                }
 
-               $sqlString = $this->emitTablesDefinitionIsBeingBuiltSignal($sqlString);
+               // Add caching framework sql definition
+               $sqlString[] = $this->getCachingFrameworkRequiredDatabaseSchema();
+
+               // Add category registry sql definition
+               $sqlString[] = \TYPO3\CMS\Core\Category\CategoryRegistry::getInstance()->getDatabaseTableDefinitions();
 
                return implode(LF . LF . LF . LF, $sqlString);
        }
 
        /**
-        * Emits a signal to manipulate the tables definitions
+        * Get schema SQL of required cache framework tables.
+        *
+        * This method needs ext_localconf and ext_tables loaded!
         *
-        * @param array $sqlString
-        * @return mixed
+        * This is a hack, but there was no smarter solution with current cache configuration setup:
+        * ToolController sets the extbase caches to NullBackend to ensure the install tool does not
+        * cache anything. The CacheManager gets the required SQL from database backends only, so we need to
+        * temporarily 'fake' the standard db backends for extbase caches so they are respected.
+        *
+        * Additionally, the extbase_object cache is already in use and instantiated, and the CacheManager singleton
+        * does not allow overriding this definition. The only option at the moment is to 'fake' another cache with
+        * a different name, and then substitute this name in the sql content with the real one.
+        *
+        * @TODO: This construct needs to be improved. It does not recognise if some custom ext overwrote the extbase cache config
+        * @TODO: Solve this as soon as cache configuration is separated from ext_localconf / ext_tables
+        * @TODO: It might be possible to reduce this ugly construct by circumventing the 'singleton' of CacheManager by using 'new'
+        *
+        * @return string Cache framework SQL
         */
-       protected function emitTablesDefinitionIsBeingBuiltSignal(array $sqlString) {
-               $signalReturn = $this->signalSlotDispatcher->dispatch(__CLASS__, 'tablesDefinitionIsBeingBuilt', array('sqlString' => $sqlString));
-               $sqlString = $signalReturn['sqlString'];
-               if (!is_array($sqlString)) {
-                       throw new Exception\UnexpectedSignalReturnValueTypeException(
-                               sprintf(
-                                       'The signal %s of class %s returned a value of type %s, but array was expected.',
-                                       'tablesDefinitionIsBeingBuilt',
-                                       __CLASS__,
-                                       gettype($sqlString)
-                               ),
-                               1382351456
-                       );
-               }
+       public function getCachingFrameworkRequiredDatabaseSchema() {
+               $cacheConfigurationBackup = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'];
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_datamapfactory_datamap'] = array();
+               $extbaseObjectFakeName = uniqid('extbase_object');
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$extbaseObjectFakeName] = array();
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_reflection'] = array();
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_typo3dbbackend_tablecolumns'] = array();
+               /** @var \TYPO3\CMS\Core\Cache\CacheManager $cacheManager */
+               $cacheManager = $GLOBALS['typo3CacheManager'];
+               $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
+               $cacheSqlString = \TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions();
+               $sqlString = str_replace($extbaseObjectFakeName, 'extbase_object', $cacheSqlString);
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = $cacheConfigurationBackup;
+               $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
+
                return $sqlString;
        }
 }