Skip to content

Commit

Permalink
Make login page query resilient to cache error (#13525)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Babker authored and rdeutz committed Feb 11, 2017
1 parent 040d4e7 commit 30218ae
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions administrator/components/com_login/models/login.php
Expand Up @@ -127,20 +127,14 @@ protected static function _load($module)
return $clean;
}

$app = JFactory::getApplication();
$lang = JFactory::getLanguage()->getTag();
$app = JFactory::getApplication();
$lang = JFactory::getLanguage()->getTag();
$clientId = (int) $app->getClientId();

$cache = JFactory::getCache('com_modules', '');
$cacheid = md5(serialize(array($clientId, $lang)));
$loginmodule = array();
/** @var JCacheControllerCallback $cache */
$cache = JFactory::getCache('com_modules', 'callback');

if ($cache->contains($cacheid))
{
$clean = $cache->get($cacheid);
}
else
{
$loader = function () use ($app, $lang, $module) {
$db = JFactory::getDbo();

$query = $db->getQuery(true)
Expand All @@ -161,23 +155,44 @@ protected static function _load($module)
// Set the query.
$db->setQuery($query);

return $db->loadObjectList();
};

try
{
return $clean = $cache->get($loader, array(), md5(serialize(array($clientId, $lang))));
}
catch (JCacheExceptionConnecting $cacheException)
{
try
{
$modules = $db->loadObjectList();
return $loader();
}
catch (RuntimeException $e)
catch (JDatabaseExceptionExecuting $databaseException)
{
JError::raiseWarning(500, JText::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $e->getMessage()));
JError::raiseWarning(500, JText::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $databaseException->getMessage()));

return $loginmodule;
return array();
}
}
catch (JCacheExceptionUnsupported $cacheException)
{
try
{
return $loader();
}
catch (JDatabaseExceptionExecuting $databaseException)
{
JError::raiseWarning(500, JText::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $databaseException->getMessage()));

// Return to simple indexing that matches the query order.
$loginmodule = $modules;

$cache->store($loginmodule, $cacheid);
return array();
}
}
catch (JDatabaseExceptionExecuting $databaseException)
{
JError::raiseWarning(500, JText::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $databaseException->getMessage()));

return $loginmodule;
return array();
}
}
}

0 comments on commit 30218ae

Please sign in to comment.