mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
BUG Ensure errorpage is built in live mode
Fixes https://github.com/silverstripe/silverstripe-framework/issues/8110
This commit is contained in:
parent
a3a0e9cb1a
commit
c5205ecc1f
@ -105,15 +105,31 @@ class ErrorPage extends Page {
|
||||
);
|
||||
$pageExists = ($page && $page->exists());
|
||||
$pagePath = self::get_filepath_for_errorcode($code);
|
||||
if(!($pageExists && file_exists($pagePath))) {
|
||||
if(!$pageExists || !file_exists($pagePath)) {
|
||||
if(!$pageExists) {
|
||||
$page = new ErrorPage($defaultData);
|
||||
$page->write();
|
||||
$page->publish('Stage', 'Live');
|
||||
}
|
||||
|
||||
// Skip unpublished records
|
||||
/** @var ErrorPage $livePage */
|
||||
$livePage = Versioned::get_by_stage('ErrorPage', Versioned::LIVE)
|
||||
->byID($page->ID);
|
||||
if (!$livePage) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ensure a static error page is created from latest error page content
|
||||
$response = Director::test(Director::makeRelative($page->Link()));
|
||||
$origReadingMode = static::get_reading_mode();
|
||||
$oldDefault = static::get_default_reading_mode();
|
||||
Versioned::reading_stage(Versioned::LIVE);
|
||||
Versioned::set_default_reading_mode(Versioned::get_reading_mode());
|
||||
$response = Director::test(Director::makeRelative($livePage->Link()));
|
||||
static::set_default_reading_mode($oldDefault);
|
||||
static::set_reading_mode($origReadingMode);
|
||||
|
||||
// Write contents
|
||||
$written = null;
|
||||
if($fh = fopen($pagePath, 'w')) {
|
||||
$written = fwrite($fh, $response->getBody());
|
||||
|
@ -88,4 +88,34 @@ class ErrorPageTest extends FunctionalTest {
|
||||
$this->assertNotNull($response->getBody());
|
||||
$this->assertContains('text/html', $response->getHeader('Content-Type'));
|
||||
}
|
||||
|
||||
public function testRequireDefaultRecords()
|
||||
{
|
||||
$this->logInWithPermission('ADMIN');
|
||||
Config::inst()->update('ErrorPage', 'static_filepath', ASSETS_PATH . '/erropagetest');
|
||||
Filesystem::makeFolder(ASSETS_PATH . '/erropagetest');
|
||||
|
||||
// Ensure 404 page is published
|
||||
/** @var ErrorPage $page404 */
|
||||
$page404 = $this->objFromFixture('ErrorPage', '404');
|
||||
$page404->publish('Stage', 'Live');
|
||||
|
||||
// Ensure 500 page isn't pubilshed
|
||||
/** @var ErrorPage $page500 */
|
||||
$page500 = $this->objFromFixture('ErrorPage', '500');
|
||||
$page500->doUnpublish();
|
||||
|
||||
// Run regeneration
|
||||
/** @var ErrorPage $singleton */
|
||||
$singleton = singleton('ErrorPage');
|
||||
$singleton->requireDefaultRecords();
|
||||
|
||||
// 404 page exists
|
||||
$path404 = ErrorPage::get_filepath_for_errorcode(404);
|
||||
$this->assertFileExists($path404);
|
||||
|
||||
// 500 doesn't exist due to it being unpubilshed
|
||||
$path500 = ErrorPage::get_filepath_for_errorcode(500);
|
||||
$this->assertFileNotExists($path500);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,11 @@ ErrorPage:
|
||||
URLSegment: page-not-found
|
||||
Content: My error page body
|
||||
ErrorCode: 404
|
||||
500:
|
||||
Title: Server error
|
||||
URLSegment: server-error
|
||||
Content: My error page body
|
||||
ErrorCode: 500
|
||||
403:
|
||||
Title: Permission Failure
|
||||
URLSegment: permission-denied
|
||||
|
Loading…
Reference in New Issue
Block a user