[TASK] Follow-up to TCA refactoring
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Core / Bootstrap.php
index 795cf62..e20f5b6 100644 (file)
@@ -164,6 +164,21 @@ class Bootstrap {
        }
 
        /**
+        * Load TYPO3_LOADED_EXT, recreate class loader registry and load ext_localconf
+        *
+        * @param boolean $allowCaching
+        * @return \TYPO3\CMS\Core\Core\Bootstrap
+        * @internal This is not a public API method, do not use in own extensions
+        */
+       public function reloadTypo3LoadedExtAndClassLoaderAndExtLocalconf() {
+               $bootstrap = $this->getInstance();
+               $bootstrap->populateTypo3LoadedExtGlobal(FALSE);
+               \TYPO3\CMS\Core\Core\ClassLoader::loadClassLoaderCache();
+               $bootstrap->loadAdditionalConfigurationFromExtensions(FALSE);
+               return $this;
+       }
+
+       /**
         * Sets up additional configuration applied in all scopes
         *
         * @return \TYPO3\CMS\Core\Core\Bootstrap
@@ -216,7 +231,10 @@ class Bootstrap {
                define('TYPO3_db_username', $GLOBALS['TYPO3_CONF_VARS']['DB']['username']);
                define('TYPO3_db_password', $GLOBALS['TYPO3_CONF_VARS']['DB']['password']);
                define('TYPO3_db_host', $GLOBALS['TYPO3_CONF_VARS']['DB']['host']);
-               define('TYPO3_extTableDef_script', $GLOBALS['TYPO3_CONF_VARS']['DB']['extTablesDefinitionScript']);
+               define('TYPO3_extTableDef_script',
+                       isset($GLOBALS['TYPO3_CONF_VARS']['DB']['extTablesDefinitionScript'])
+                       ? $GLOBALS['TYPO3_CONF_VARS']['DB']['extTablesDefinitionScript']
+                       : 'extTables.php');
                unset($GLOBALS['TYPO3_CONF_VARS']['DB']);
                define('TYPO3_user_agent', 'User-Agent: ' . $GLOBALS['TYPO3_CONF_VARS']['HTTP']['userAgent']);
                return $this;
@@ -607,7 +625,7 @@ class Bootstrap {
 
        /**
         * Unsetting reserved global variables:
-        * Those which are/can be set in "stddb/tables.php" files:
+        * Those are set in "ext:core/ext_tables.php" file:
         *
         * @return \TYPO3\CMS\Core\Core\Bootstrap
         */
@@ -747,6 +765,35 @@ class Bootstrap {
        }
 
        /**
+        * Load TCA for frontend
+        *
+        * This method is *only* executed in frontend scope. The idea is to execute the
+        * whole TCA and ext_tables (which manipulate TCA) on first frontend access,
+        * and then cache the full TCA on disk to be used for the next run again.
+        *
+        * This way, ext_tables.php ist not executed every time, but $GLOBALS['TCA']
+        * is still always there.
+        *
+        * @return \TYPO3\CMS\Core\Core\Bootstrap
+        * @internal This is not a public API method, do not use in own extensions
+        */
+       public function loadCachedTca() {
+               $cacheIdentifier = 'tca_fe_' . sha1((TYPO3_version . PATH_site . 'tca_fe'));
+               /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */
+               $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core');
+               if ($codeCache->has($cacheIdentifier)) {
+                       $codeCache->requireOnce($cacheIdentifier);
+               } else {
+                       $this->loadExtensionTables(TRUE);
+                       $phpCodeToCache = '$GLOBALS[\'TCA\'] = ';
+                       $phpCodeToCache .= \TYPO3\CMS\Core\Utility\ArrayUtility::arrayExport($GLOBALS['TCA']);
+                       $phpCodeToCache .= ';';
+                       $codeCache->set($cacheIdentifier, $phpCodeToCache);
+               }
+               return $this;
+       }
+
+       /**
         * Load ext_tables and friends.
         *
         * This will mainly set up $TCA and several other global arrays
@@ -754,42 +801,51 @@ class Bootstrap {
         * Executes ext_tables.php files of loaded extensions or the
         * according cache file if exists.
         *
+        * @param boolean $allowCaching True, if reading compiled ext_tables file from cache is allowed
+        * @return \TYPO3\CMS\Core\Core\Bootstrap
+        * @internal This is not a public API method, do not use in own extensions
+        */
+       public function loadExtensionTables($allowCaching = TRUE) {
+               \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadBaseTca($allowCaching);
+               \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadExtTables($allowCaching);
+               $this->executeExtTablesAdditionalFile();
+               $this->runExtTablesPostProcessingHooks();
+               return $this;
+       }
+
+       /**
+        * Execute TYPO3_extTableDef_script if defined and exists
+        *
         * Note: For backwards compatibility some global variables are
         * explicitly set as global to be used without $GLOBALS[] in
-        * ext_tables.php. It is discouraged to access variables like
-        * $TBE_MODULES directly in ext_tables.php, but we can not prohibit
+        * the extension table script. It is discouraged to access variables like
+        * $TBE_MODULES directly, but we can not prohibit
         * this without heavily breaking backwards compatibility.
         *
         * @TODO : We could write a scheduler / reports module or an update checker
         * @TODO : It should be defined, which global arrays are ok to be manipulated
-        * @param boolean $allowCaching True, if reading compiled ext_tables file from cache is allowed
-        * @return \TYPO3\CMS\Core\Core\Bootstrap
-        * @internal This is not a public API method, do not use in own extensions
+        *
+        * @return void
         */
-       public function loadExtensionTables($allowCaching = TRUE) {
+       protected function executeExtTablesAdditionalFile() {
                // It is discouraged to use those global variables directly, but we
                // can not prohibit this without breaking backwards compatibility
                global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
                global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;
                global $PAGES_TYPES, $TBE_STYLES, $FILEICONS;
                global $_EXTKEY;
-               // Include standard tables.php file
-               require PATH_t3lib . 'stddb/tables.php';
-               \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadExtTables($allowCaching);
-               // Load additional ext tables script if registered
-               if (TYPO3_extTableDef_script) {
-                       include PATH_typo3conf . TYPO3_extTableDef_script;
+               // Load additional ext tables script if the file exists
+               $extTablesFile = PATH_typo3conf . TYPO3_extTableDef_script;
+               if (file_exists($extTablesFile)) {
+                       include $extTablesFile;
                }
-               // Run post hook for additional manipulation
-               $this->runExtTablesPostProcessingHooks();
-               return $this;
        }
 
        /**
         * Check for registered ext tables hooks and run them
         *
         * @throws \UnexpectedValueException
-        * @return \TYPO3\CMS\Core\Core\Bootstrap
+        * @return void
         */
        protected function runExtTablesPostProcessingHooks() {
                if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'])) {
@@ -802,7 +858,6 @@ class Bootstrap {
                                $hookObject->processData();
                        }
                }
-               return $this;
        }
 
        /**
@@ -832,10 +887,12 @@ class Bootstrap {
                if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
                        $backendUser->dontSetCookie = TRUE;
                }
+               // The global must be available very early, because methods below
+               // might triger code which relies on it. See: #45625
+               $GLOBALS['BE_USER'] = $backendUser;
                $backendUser->start();
                $backendUser->checkCLIuser();
                $backendUser->backendCheckLogin();
-               $GLOBALS['BE_USER'] = $backendUser;
                return $this;
        }