Decouple ErrorPage

This commit is contained in:
Jonathon Menz 2015-12-28 12:17:31 -08:00
parent f8678f6bc0
commit 8ddef0b817
5 changed files with 7 additions and 26 deletions

View File

@ -1,6 +1,9 @@
LeftAndMain: LeftAndMain:
extensions: extensions:
- LeftAndMainPageIconsExtension - LeftAndMainPageIconsExtension
Security: Controller:
extensions:
- ErrorPageControllerExtension
Form:
extensions: extensions:
- ErrorPageControllerExtension - ErrorPageControllerExtension

View File

@ -210,16 +210,6 @@ class ContentController extends Controller {
return $response; return $response;
} }
/**
* @uses ErrorPage::response_for()
*/
public function httpError($code, $message = null) {
// Don't use the HTML response for media requests
$response = $this->getRequest()->isMedia() ? null : ErrorPage::response_for($code);
// Failover to $message if the HTML response is unavailable / inappropriate
parent::httpError($code, $response ? $response : $message);
}
/** /**
* Get the project name * Get the project name
* *
@ -424,12 +414,6 @@ HTML;
if (!file_exists(BASE_PATH . '/install.php')) { if (!file_exists(BASE_PATH . '/install.php')) {
$this->httpError(410); $this->httpError(410);
} }
// The manifest should be built by now, so it's safe to publish the 404 page
$fourohfour = Versioned::get_one_by_stage('ErrorPage', 'Stage', '"ErrorPage"."ErrorCode" = 404');
if($fourohfour) {
$fourohfour->write();
$fourohfour->publish("Stage", "Live");
}
// TODO Allow this to work when allow_url_fopen=0 // TODO Allow this to work when allow_url_fopen=0
if(isset($_SESSION['StatsID']) && $_SESSION['StatsID']) { if(isset($_SESSION['StatsID']) && $_SESSION['StatsID']) {

View File

@ -111,8 +111,7 @@ class ModelAsController extends Controller implements NestedController {
if(class_exists('Translatable')) Translatable::enable_locale_filter(); if(class_exists('Translatable')) Translatable::enable_locale_filter();
if(!$sitetree) { if(!$sitetree) {
$response = ErrorPage::response_for(404); $this->httpError(404, 'The requested page could not be found.');
$this->httpError(404, $response ? $response : 'The requested page could not be found.');
} }
// Enforce current locale setting to the loaded SiteTree object // Enforce current locale setting to the loaded SiteTree object

View File

@ -439,7 +439,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
if ( if (
!($page = DataObject::get_by_id('SiteTree', $arguments['id'])) // Get the current page by ID. !($page = DataObject::get_by_id('SiteTree', $arguments['id'])) // Get the current page by ID.
&& !($page = Versioned::get_latest_version('SiteTree', $arguments['id'])) // Attempt link to old version. && !($page = Versioned::get_latest_version('SiteTree', $arguments['id'])) // Attempt link to old version.
&& !($page = DataObject::get_one('ErrorPage', array('"ErrorPage"."ErrorCode"' => 404))) // Link to 404 page directly.
) { ) {
return; // There were no suitable matches at all. return; // There were no suitable matches at all.
} }

View File

@ -613,7 +613,6 @@ class SiteTreeTest extends SapphireTest {
public function testLinkShortcodeHandler() { public function testLinkShortcodeHandler() {
$aboutPage = $this->objFromFixture('Page', 'about'); $aboutPage = $this->objFromFixture('Page', 'about');
$errorPage = $this->objFromFixture('ErrorPage', '404');
$redirectPage = $this->objFromFixture('RedirectorPage', 'external'); $redirectPage = $this->objFromFixture('RedirectorPage', 'external');
$parser = new ShortcodeParser(); $parser = new ShortcodeParser();
@ -636,11 +635,8 @@ class SiteTreeTest extends SapphireTest {
$aboutShortcode = '[sitetree_link,id="-1"]'; $aboutShortcode = '[sitetree_link,id="-1"]';
$aboutEnclosed = '[sitetree_link,id="-1"]Example Content[/sitetree_link]'; $aboutEnclosed = '[sitetree_link,id="-1"]Example Content[/sitetree_link]';
$aboutShortcodeExpected = $errorPage->Link(); $this->assertEquals('', $parser->parse($aboutShortcode), 'Test empty result if no suitable matches.');
$aboutEnclosedExpected = sprintf('<a href="%s">Example Content</a>', $errorPage->Link()); $this->assertEquals('', $parser->parse($aboutEnclosed));
$this->assertEquals($aboutShortcodeExpected, $parser->parse($aboutShortcode), 'Test link to 404 page if no suitable matches.');
$this->assertEquals($aboutEnclosedExpected, $parser->parse($aboutEnclosed));
$redirectShortcode = sprintf('[sitetree_link,id=%d]', $redirectPage->ID); $redirectShortcode = sprintf('[sitetree_link,id=%d]', $redirectPage->ID);
$redirectEnclosed = sprintf('[sitetree_link,id=%d]Example Content[/sitetree_link]', $redirectPage->ID); $redirectEnclosed = sprintf('[sitetree_link,id=%d]Example Content[/sitetree_link]', $redirectPage->ID);