BUGFIX Prioritize static error pages in ErrorPage::response_for() (otherwise any 404 will be a major performance hit)

This commit is contained in:
Ingo Schommer 2010-12-01 10:59:32 +13:00
parent 32548a9b3b
commit 51a0a806fc

View File

@ -33,12 +33,7 @@ class ErrorPage extends Page {
* @return SS_HTTPResponse * @return SS_HTTPResponse
*/ */
public static function response_for($statusCode) { public static function response_for($statusCode) {
// first attempt to dynamically generate the error page // first look for cached files
if($errorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = $statusCode")) {
return ModelAsController::controller_for($errorPage)->handleRequest(new SS_HTTPRequest('GET', ''));
}
// then fall back on a cached version
$cachedPath = self::get_filepath_for_errorcode($statusCode, Translatable::get_current_locale()); $cachedPath = self::get_filepath_for_errorcode($statusCode, Translatable::get_current_locale());
if(file_exists($cachedPath)) { if(file_exists($cachedPath)) {
@ -48,6 +43,9 @@ class ErrorPage extends Page {
$response->setBody(file_get_contents($cachedPath)); $response->setBody(file_get_contents($cachedPath));
return $response; return $response;
} else if($errorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = $statusCode")) {
// then attempt to dynamically generate the error page
return ModelAsController::controller_for($errorPage)->handleRequest(new SS_HTTPRequest('GET', ''));
} }
} }