From 8ddef0b8177490177b52249c495a367eda61d49d Mon Sep 17 00:00:00 2001 From: Jonathon Menz Date: Mon, 28 Dec 2015 12:17:31 -0800 Subject: [PATCH] Decouple ErrorPage --- _config/config.yml | 5 ++++- code/controllers/ContentController.php | 16 ---------------- code/controllers/ModelAsController.php | 3 +-- code/model/SiteTree.php | 1 - tests/model/SiteTreeTest.php | 8 ++------ 5 files changed, 7 insertions(+), 26 deletions(-) diff --git a/_config/config.yml b/_config/config.yml index 8b91fc39..e0e480ff 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -1,6 +1,9 @@ LeftAndMain: extensions: - LeftAndMainPageIconsExtension -Security: +Controller: + extensions: + - ErrorPageControllerExtension +Form: extensions: - ErrorPageControllerExtension diff --git a/code/controllers/ContentController.php b/code/controllers/ContentController.php index 177ad00f..07a7e163 100755 --- a/code/controllers/ContentController.php +++ b/code/controllers/ContentController.php @@ -210,16 +210,6 @@ class ContentController extends Controller { 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 * @@ -424,12 +414,6 @@ HTML; if (!file_exists(BASE_PATH . '/install.php')) { $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 if(isset($_SESSION['StatsID']) && $_SESSION['StatsID']) { diff --git a/code/controllers/ModelAsController.php b/code/controllers/ModelAsController.php index c11e800b..ec8377d8 100644 --- a/code/controllers/ModelAsController.php +++ b/code/controllers/ModelAsController.php @@ -111,8 +111,7 @@ class ModelAsController extends Controller implements NestedController { if(class_exists('Translatable')) Translatable::enable_locale_filter(); if(!$sitetree) { - $response = ErrorPage::response_for(404); - $this->httpError(404, $response ? $response : 'The requested page could not be found.'); + $this->httpError(404, 'The requested page could not be found.'); } // Enforce current locale setting to the loaded SiteTree object diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php index a5028540..192acff5 100755 --- a/code/model/SiteTree.php +++ b/code/model/SiteTree.php @@ -439,7 +439,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid if ( !($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 = DataObject::get_one('ErrorPage', array('"ErrorPage"."ErrorCode"' => 404))) // Link to 404 page directly. ) { return; // There were no suitable matches at all. } diff --git a/tests/model/SiteTreeTest.php b/tests/model/SiteTreeTest.php index f9cebf89..e364a199 100644 --- a/tests/model/SiteTreeTest.php +++ b/tests/model/SiteTreeTest.php @@ -613,7 +613,6 @@ class SiteTreeTest extends SapphireTest { public function testLinkShortcodeHandler() { $aboutPage = $this->objFromFixture('Page', 'about'); - $errorPage = $this->objFromFixture('ErrorPage', '404'); $redirectPage = $this->objFromFixture('RedirectorPage', 'external'); $parser = new ShortcodeParser(); @@ -636,11 +635,8 @@ class SiteTreeTest extends SapphireTest { $aboutShortcode = '[sitetree_link,id="-1"]'; $aboutEnclosed = '[sitetree_link,id="-1"]Example Content[/sitetree_link]'; - $aboutShortcodeExpected = $errorPage->Link(); - $aboutEnclosedExpected = sprintf('Example Content', $errorPage->Link()); - - $this->assertEquals($aboutShortcodeExpected, $parser->parse($aboutShortcode), 'Test link to 404 page if no suitable matches.'); - $this->assertEquals($aboutEnclosedExpected, $parser->parse($aboutEnclosed)); + $this->assertEquals('', $parser->parse($aboutShortcode), 'Test empty result if no suitable matches.'); + $this->assertEquals('', $parser->parse($aboutEnclosed)); $redirectShortcode = sprintf('[sitetree_link,id=%d]', $redirectPage->ID); $redirectEnclosed = sprintf('[sitetree_link,id=%d]Example Content[/sitetree_link]', $redirectPage->ID);