mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
Merge remote-tracking branch 'origin/3.0' into 3.1
This commit is contained in:
commit
931b726589
@ -5,7 +5,6 @@ php:
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
- TESTDB=MYSQL
|
- TESTDB=MYSQL
|
||||||
- TESTDB=PGSQL
|
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
exclude:
|
exclude:
|
||||||
|
@ -73,62 +73,81 @@ class ErrorPage extends Page {
|
|||||||
mkdir(ASSETS_PATH);
|
mkdir(ASSETS_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
$pageNotFoundErrorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = '404'");
|
$defaultPages = $this->getDefaultRecords();
|
||||||
$pageNotFoundErrorPageExists = ($pageNotFoundErrorPage && $pageNotFoundErrorPage->exists()) ? true : false;
|
|
||||||
$pageNotFoundErrorPagePath = self::get_filepath_for_errorcode(404);
|
foreach($defaultPages as $defaultData) {
|
||||||
if(!($pageNotFoundErrorPageExists && file_exists($pageNotFoundErrorPagePath))) {
|
$code = $defaultData['ErrorCode'];
|
||||||
if(!$pageNotFoundErrorPageExists) {
|
$page = DataObject::get_one(
|
||||||
$pageNotFoundErrorPage = new ErrorPage();
|
'ErrorPage',
|
||||||
$pageNotFoundErrorPage->ErrorCode = 404;
|
sprintf("\"ErrorCode\" = '%s'", $code)
|
||||||
$pageNotFoundErrorPage->Title = _t('ErrorPage.DEFAULTERRORPAGETITLE', 'Page not found');
|
);
|
||||||
$pageNotFoundErrorPage->Content = _t('ErrorPage.DEFAULTERRORPAGECONTENT', '<p>Sorry, it seems you were trying to access a page that doesn\'t exist.</p><p>Please check the spelling of the URL you were trying to access and try again.</p>');
|
$pageExists = ($page && $page->exists());
|
||||||
$pageNotFoundErrorPage->write();
|
$pagePath = self::get_filepath_for_errorcode($code);
|
||||||
$pageNotFoundErrorPage->publish('Stage', 'Live');
|
if(!($pageExists && file_exists($pagePath))) {
|
||||||
|
if(!$pageExists) {
|
||||||
|
$page = new ErrorPage($defaultData);
|
||||||
|
$page->write();
|
||||||
|
$page->publish('Stage', 'Live');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure a static error page is created from latest error page content
|
// Ensure a static error page is created from latest error page content
|
||||||
$response = Director::test(Director::makeRelative($pageNotFoundErrorPage->Link()));
|
$response = Director::test(Director::makeRelative($page->Link()));
|
||||||
$written = null;
|
$written = null;
|
||||||
if($fh = fopen($pageNotFoundErrorPagePath, 'w')) {
|
if($fh = fopen($pagePath, 'w')) {
|
||||||
$written = fwrite($fh, $response->getBody());
|
$written = fwrite($fh, $response->getBody());
|
||||||
fclose($fh);
|
fclose($fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($written) {
|
if($written) {
|
||||||
DB::alteration_message('404 error page created', 'created');
|
DB::alteration_message(
|
||||||
|
sprintf('%s error page created', $code),
|
||||||
|
'created'
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
DB::alteration_message(sprintf('404 error page could not be created at %s. Please check permissions', $pageNotFoundErrorPagePath), 'error');
|
DB::alteration_message(
|
||||||
|
sprintf(
|
||||||
|
'%s error page could not be created at %s. Please check permissions',
|
||||||
|
$code,
|
||||||
|
$pagePath
|
||||||
|
),
|
||||||
|
'error'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$serverErrorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = '500'");
|
}
|
||||||
$serverErrorPageExists = ($serverErrorPage && $serverErrorPage->exists()) ? true : false;
|
|
||||||
$serverErrorPagePath = self::get_filepath_for_errorcode(500);
|
|
||||||
if(!($serverErrorPageExists && file_exists($serverErrorPagePath))) {
|
|
||||||
if(!$serverErrorPageExists) {
|
|
||||||
$serverErrorPage = new ErrorPage();
|
|
||||||
$serverErrorPage->ErrorCode = 500;
|
|
||||||
$serverErrorPage->Title = _t('ErrorPage.DEFAULTSERVERERRORPAGETITLE', 'Server error');
|
|
||||||
$serverErrorPage->Content = _t('ErrorPage.DEFAULTSERVERERRORPAGECONTENT', '<p>Sorry, there was a problem with handling your request.</p>');
|
|
||||||
$serverErrorPage->write();
|
|
||||||
$serverErrorPage->publish('Stage', 'Live');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure a static error page is created from latest error page content
|
/**
|
||||||
$response = Director::test(Director::makeRelative($serverErrorPage->Link()));
|
* Returns an array of arrays, each of which defines
|
||||||
$written = null;
|
* properties for a new ErrorPage record.
|
||||||
if($fh = fopen($serverErrorPagePath, 'w')) {
|
*
|
||||||
$written = fwrite($fh, $response->getBody());
|
* @return Array
|
||||||
fclose($fh);
|
*/
|
||||||
}
|
protected function getDefaultRecords() {
|
||||||
|
$data = array(
|
||||||
|
array(
|
||||||
|
'ErrorCode' => 404,
|
||||||
|
'Title' => _t('ErrorPage.DEFAULTERRORPAGETITLE', 'Page not found'),
|
||||||
|
'Content' => _t(
|
||||||
|
'ErrorPage.DEFAULTERRORPAGECONTENT',
|
||||||
|
'<p>Sorry, it seems you were trying to access a page that doesn\'t exist.</p>'
|
||||||
|
. '<p>Please check the spelling of the URL you were trying to access and try again.</p>'
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'ErrorCode' => 500,
|
||||||
|
'Title' => _t('ErrorPage.DEFAULTSERVERERRORPAGETITLE', 'Server error'),
|
||||||
|
'Content' => _t(
|
||||||
|
'ErrorPage.DEFAULTSERVERERRORPAGECONTENT',
|
||||||
|
'<p>Sorry, there was a problem with handling your request.</p>'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->extend('getDefaultRecords', $data);
|
||||||
|
|
||||||
if($written) {
|
return $data;
|
||||||
DB::alteration_message('500 error page created', 'created');
|
|
||||||
} else {
|
|
||||||
DB::alteration_message(sprintf('500 error page could not be created at %s. Please check permissions', $serverErrorPagePath), 'error');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCMSFields() {
|
public function getCMSFields() {
|
||||||
|
Loading…
Reference in New Issue
Block a user