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
*/
public static function response_for($statusCode) {
// first attempt to dynamically generate the error page
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
// first look for cached files
$cachedPath = self::get_filepath_for_errorcode($statusCode, Translatable::get_current_locale());
if(file_exists($cachedPath)) {
@ -48,6 +43,9 @@ class ErrorPage extends Page {
$response->setBody(file_get_contents($cachedPath));
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', ''));
}
}