Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Revert "Improve the cache handling for empty URLs (see #7618)."
Browse files Browse the repository at this point in the history
This reverts commit ed1a73a.
  • Loading branch information
leofeyer committed Mar 19, 2015
1 parent 33d8f2b commit d52ad61
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 114 deletions.
3 changes: 0 additions & 3 deletions system/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
52 changes: 11 additions & 41 deletions system/modules/core/controllers/FrontendIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
{
Expand All @@ -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))
{
Expand All @@ -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))
{
Expand Down
48 changes: 1 addition & 47 deletions system/modules/core/library/Contao/Automator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<?php '); // add one space to prevent the "unexpected $end" error

$strContent = "\n\n";
$strContent .= "return array\n";
$strContent .= "(\n";

foreach ($arrMapper as $strKey=>$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);
}


Expand Down
24 changes: 1 addition & 23 deletions system/modules/core/models/PageModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit d52ad61

Please sign in to comment.