mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Decouple ErrorPage
This commit is contained in:
parent
f8678f6bc0
commit
8ddef0b817
@ -1,6 +1,9 @@
|
|||||||
LeftAndMain:
|
LeftAndMain:
|
||||||
extensions:
|
extensions:
|
||||||
- LeftAndMainPageIconsExtension
|
- LeftAndMainPageIconsExtension
|
||||||
Security:
|
Controller:
|
||||||
|
extensions:
|
||||||
|
- ErrorPageControllerExtension
|
||||||
|
Form:
|
||||||
extensions:
|
extensions:
|
||||||
- ErrorPageControllerExtension
|
- ErrorPageControllerExtension
|
||||||
|
@ -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']) {
|
||||||
|
@ -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
|
||||||
|
@ -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.
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user