diff --git a/system/docs/CHANGELOG.md b/system/docs/CHANGELOG.md index c50b874e55..be73edad4a 100644 --- a/system/docs/CHANGELOG.md +++ b/system/docs/CHANGELOG.md @@ -4,9 +4,6 @@ Contao Open Source CMS changelog Version 3.4.5 (2015-03-XX) -------------------------- -### Fixed -Improve the cache handling for empty URLs (see #7618). - ### Fixed Ensure a unique language file array in the `Automator` class (see #7687). diff --git a/system/modules/core/controllers/FrontendIndex.php b/system/modules/core/controllers/FrontendIndex.php index af4484e924..9bdd8583ef 100644 --- a/system/modules/core/controllers/FrontendIndex.php +++ b/system/modules/core/controllers/FrontendIndex.php @@ -268,7 +268,12 @@ protected function outputFromCache() return; } - // Try to map the empty request + /** + * If the request string is empty, look for a cached page matching the + * primary browser language. This is a compromise between not caching + * empty requests at all and considering all browser languages, which + * is not possible for various reasons. + */ if (\Environment::get('request') == '' || \Environment::get('request') == 'index.php') { // Return if the language is added to the URL and the empty domain will be redirected @@ -277,43 +282,8 @@ protected function outputFromCache() return; } - $strCacheKey = null; $arrLanguage = \Environment::get('httpAcceptLanguage'); - - // Try to get the cache key from the mapper array - if (file_exists(TL_ROOT . '/system/cache/config/mapping.php')) - { - $arrMapper = include TL_ROOT . '/system/cache/config/mapping.php'; - - // Try the language specific keys - foreach ($arrLanguage as $strLanguage) - { - $strSpecificKey = \Environment::get('base') . 'empty.' . $strLanguage; - - if (isset($arrMapper[$strSpecificKey])) - { - $strCacheKey = $arrMapper[$strSpecificKey]; - break; - } - } - - // Try the fallback key - if ($strCacheKey === null) - { - $strSpecificKey = \Environment::get('base') . 'empty.fallback'; - - if (isset($arrMapper[$strSpecificKey])) - { - $strCacheKey = $arrMapper[$strSpecificKey]; - } - } - } - - // Fall back to the first accepted language - if ($strCacheKey === null) - { - $strCacheKey = \Environment::get('base') . 'empty.' . $arrLanguage[0]; - } + $strCacheKey = \Environment::get('base') .'empty.'. $arrLanguage[0]; } else { @@ -336,8 +306,8 @@ protected function outputFromCache() // Check for a mobile layout if (\Input::cookie('TL_VIEW') == 'mobile' || (\Environment::get('agent')->mobile && \Input::cookie('TL_VIEW') != 'desktop')) { - $strMd5CacheKey = md5($strCacheKey . '.mobile'); - $strCacheFile = TL_ROOT . '/system/cache/html/' . substr($strMd5CacheKey, 0, 1) . '/' . $strMd5CacheKey . '.html'; + $strCacheKey = md5($strCacheKey . '.mobile'); + $strCacheFile = TL_ROOT . '/system/cache/html/' . substr($strCacheKey, 0, 1) . '/' . $strCacheKey . '.html'; if (file_exists($strCacheFile)) { @@ -348,8 +318,8 @@ protected function outputFromCache() // Check for a regular layout if (!$blnFound) { - $strMd5CacheKey = md5($strCacheKey); - $strCacheFile = TL_ROOT . '/system/cache/html/' . substr($strMd5CacheKey, 0, 1) . '/' . $strMd5CacheKey . '.html'; + $strCacheKey = md5($strCacheKey); + $strCacheFile = TL_ROOT . '/system/cache/html/' . substr($strCacheKey, 0, 1) . '/' . $strCacheKey . '.html'; if (file_exists($strCacheFile)) { diff --git a/system/modules/core/library/Contao/Automator.php b/system/modules/core/library/Contao/Automator.php index 6f63731566..5459e13fbb 100644 --- a/system/modules/core/library/Contao/Automator.php +++ b/system/modules/core/library/Contao/Automator.php @@ -545,54 +545,8 @@ public function generateConfigCache() // Close the file (moves it to its final destination) $objCacheFile->close(); - // Generate the page mapping array - $arrMapper = []; - $objPages = \PageModel::findPublishedRootPages(); - - if ($objPages !== null) - { - while ($objPages->next()) - { - if ($objPages->dns != '') - { - $strBase = $objPages->useSSL ? 'https://' : 'http://'; - $strBase .= $objPages->dns . \Environment::get('path') . '/'; - } - else - { - $strBase = \Environment::get('base'); - } - - if ($objPages->fallback) - { - $arrMapper[$strBase . 'empty.fallback'] = $strBase . 'empty.' . $objPages->language; - } - - $arrMapper[$strBase . 'empty.' . $objPages->language] = $strBase . 'empty.' . $objPages->language; - } - } - - // Generate the page mapper file - $objCacheFile = new \File('system/cache/config/mapping.php', true); - $objCacheFile->write('$strCacheKey) - { - $strContent .= "\t'$strKey' => '$strCacheKey',\n"; - } - - $strContent .= ");"; - $objCacheFile->append($strContent); - - // Close the file (moves it to its final destination) - $objCacheFile->close(); - // Add a log entry - $this->log('Generated the config cache', __METHOD__, TL_CRON); + $this->log('Generated the autoload cache', __METHOD__, TL_CRON); } diff --git a/system/modules/core/models/PageModel.php b/system/modules/core/models/PageModel.php index 3475e384c8..f2796d0f11 100644 --- a/system/modules/core/models/PageModel.php +++ b/system/modules/core/models/PageModel.php @@ -234,7 +234,7 @@ public static function find404ByPid($intPid, array $arrOptions=array()) * @param array $arrAliases An array of possible alias names * @param array $arrOptions An optional options array * - * @return \Model\Collection|null A collection of Models or null if there is no matching pages + * @return \Model_Collection|null A collection of Models or null if there is no matching pages */ public static function findByAliases($arrAliases, array $arrOptions=array()) { @@ -416,28 +416,6 @@ public static function findPublishedFallbackByHostname($strHost, array $arrOptio } - /** - * Finds the published root pages - * - * @param array $arrOptions An optional options array - * - * @return \Model\Collection|null A collection of models or null if there are no parent pages - */ - public static function findPublishedRootPages(array $arrOptions=array()) - { - $t = static::$strTable; - $arrColumns = array("$t.type=?"); - - if (!BE_USER_LOGGED_IN) - { - $time = time(); - $arrColumns[] = "($t.start='' OR $t.start<$time) AND ($t.stop='' OR $t.stop>$time) AND $t.published=1"; - } - - return static::findBy($arrColumns, 'root', $arrOptions); - } - - /** * Find the parent pages of a page *