mirror of
https://github.com/silverstripe/silverstripe-staticpublisher
synced 2024-10-22 14:05:54 +02:00
Merge pull request #24 from mateusz/standard-error-pages
NEW Generate static versions of ErrorPages.
This commit is contained in:
commit
bacc1d44ba
@ -229,17 +229,26 @@ class FilesystemPublisher extends StaticPublisher {
|
|||||||
if($url == "") $url = "/";
|
if($url == "") $url = "/";
|
||||||
if(Director::is_relative_url($url)) $url = Director::absoluteURL($url);
|
if(Director::is_relative_url($url)) $url = Director::absoluteURL($url);
|
||||||
$response = Director::test(str_replace('+', ' ', $url));
|
$response = Director::test(str_replace('+', ' ', $url));
|
||||||
|
|
||||||
if($response) {
|
|
||||||
$result[$origUrl]['statuscode'] = $response->getStatusCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!$response) continue;
|
||||||
|
|
||||||
|
if($response) {
|
||||||
|
$result[$origUrl]['statuscode'] = $response->getStatusCode();
|
||||||
|
}
|
||||||
Requirements::clear();
|
Requirements::clear();
|
||||||
|
|
||||||
singleton('DataObject')->flushCache();
|
singleton('DataObject')->flushCache();
|
||||||
|
|
||||||
//skip any responses with a 404 status code. We don't want to turn those into statically cached pages
|
// Check for ErrorPages generating output - we want to handle this in a special way below.
|
||||||
if (!$response || $response->getStatusCode() == '404') continue;
|
$isErrorPage = false;
|
||||||
|
$pageObject = null;
|
||||||
|
if ($response && is_object($response) && ((int)$response->getStatusCode())>=400) {
|
||||||
|
$pageObject = SiteTree::get_by_link($url);
|
||||||
|
if ($pageObject && $pageObject instanceof ErrorPage) $isErrorPage = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip any responses with a 404 status code unless it's the ErrorPage itself.
|
||||||
|
if (!$isErrorPage && is_object($response) && $response->getStatusCode()=='404') continue;
|
||||||
|
|
||||||
// Generate file content
|
// Generate file content
|
||||||
// PHP file caching will generate a simple script from a template
|
// PHP file caching will generate a simple script from a template
|
||||||
@ -276,12 +285,27 @@ class FilesystemPublisher extends StaticPublisher {
|
|||||||
$content
|
$content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$files[$origUrl] = array(
|
if (!$isErrorPage) {
|
||||||
'Content' => $content,
|
|
||||||
'Folder' => dirname($path).'/',
|
$files[$origUrl] = array(
|
||||||
'Filename' => basename($path),
|
'Content' => $content,
|
||||||
);
|
'Folder' => dirname($path).'/',
|
||||||
|
'Filename' => basename($path),
|
||||||
|
);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Generate a static version of the error page with a standardised name, so they can be plugged
|
||||||
|
// into catch-all webserver statements such as Apache's ErrorDocument.
|
||||||
|
$code = (int)$response->getStatusCode();
|
||||||
|
$files[$origUrl] = array(
|
||||||
|
'Content' => $content,
|
||||||
|
'Folder' => dirname($path).'/',
|
||||||
|
'Filename' => "error-$code.html",
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Add externals
|
// Add externals
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user