UPDATE: make all response code use getResponse() method

This commit is contained in:
Stevie Mayhew 2015-08-14 12:39:45 +12:00
parent 71b23b622c
commit d54e117392
5 changed files with 281 additions and 285 deletions

View File

@ -342,8 +342,8 @@ JS
$record->delete(); $record->delete();
$this->setCurrentPageID(null); $this->setCurrentPageID(null);
$this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.DELETED', 'Deleted.'))); $this->getResponse()->addHeader('X-Status', rawurlencode(_t('LeftAndMain.DELETED', 'Deleted.')));
$this->response->addHeader('X-Pjax', 'Content'); $this->getResponse()->addHeader('X-Pjax', 'Content');
return $this->redirect(Controller::join_links($this->Link('show'), $parentID ? $parentID : 0)); return $this->redirect(Controller::join_links($this->Link('show'), $parentID ? $parentID : 0));
} }
@ -553,7 +553,7 @@ JS
*/ */
public function doSync() { public function doSync() {
$message = Filesystem::sync(); $message = Filesystem::sync();
$this->response->addHeader('X-Status', rawurlencode($message)); $this->getResponse()->addHeader('X-Status', rawurlencode($message));
return; return;
} }
@ -587,7 +587,7 @@ JS
'{count} unused thumbnails have been deleted', '{count} unused thumbnails have been deleted',
array('count' => $count) array('count' => $count)
); );
$this->response->addHeader('X-Status', rawurlencode($message)); $this->getResponse()->addHeader('X-Status', rawurlencode($message));
return; return;
} }

View File

@ -742,7 +742,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$this->extend('updateChildFilter', $disallowedChildren, $parentID); $this->extend('updateChildFilter', $disallowedChildren, $parentID);
return $this return $this
->response ->getResponse()
->addHeader('Content-Type', 'application/json; charset=utf-8') ->addHeader('Content-Type', 'application/json; charset=utf-8')
->setBody(Convert::raw2json($disallowedChildren)); ->setBody(Convert::raw2json($disallowedChildren));
} }
@ -939,7 +939,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
if(!is_subclass_of($className, $parentClass) && strcasecmp($className, $parentClass) != 0) { if(!is_subclass_of($className, $parentClass) && strcasecmp($className, $parentClass) != 0) {
$response = Security::permissionFailure($this); $response = Security::permissionFailure($this);
if (!$response) { if (!$response) {
$response = $this->response; $response = $this->getResponse();
} }
throw new SS_HTTPResponse_Exception($response); throw new SS_HTTPResponse_Exception($response);
} }
@ -1023,7 +1023,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$descRemoved = ''; $descRemoved = '';
} }
$this->response->addHeader( $this->getResponse()->addHeader(
'X-Status', 'X-Status',
rawurlencode( rawurlencode(
_t( _t(
@ -1072,7 +1072,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$record->doRevertToLive(); $record->doRevertToLive();
$this->response->addHeader( $this->getResponse()->addHeader(
'X-Status', 'X-Status',
rawurlencode(_t( rawurlencode(_t(
'CMSMain.RESTORED', 'CMSMain.RESTORED',
@ -1099,7 +1099,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Delete record // Delete record
$record->delete(); $record->delete();
$this->response->addHeader( $this->getResponse()->addHeader(
'X-Status', 'X-Status',
rawurlencode(sprintf(_t('CMSMain.REMOVEDPAGEFROMDRAFT',"Removed '%s' from the draft site"), $record->Title)) rawurlencode(sprintf(_t('CMSMain.REMOVEDPAGEFROMDRAFT',"Removed '%s' from the draft site"), $record->Title))
); );
@ -1127,7 +1127,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Archive record // Archive record
$record->doArchive(); $record->doArchive();
$this->response->addHeader( $this->getResponse()->addHeader(
'X-Status', 'X-Status',
rawurlencode(sprintf(_t('CMSMain.ARCHIVEDPAGE',"Archived page '%s'"), $record->Title)) rawurlencode(sprintf(_t('CMSMain.ARCHIVEDPAGE',"Archived page '%s'"), $record->Title))
); );
@ -1151,7 +1151,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$record->doUnpublish(); $record->doUnpublish();
$this->response->addHeader( $this->getResponse()->addHeader(
'X-Status', 'X-Status',
rawurlencode(_t('CMSMain.REMOVEDPAGE',"Removed '{title}' from the published site", array('title' => $record->Title))) rawurlencode(_t('CMSMain.REMOVEDPAGE',"Removed '{title}' from the published site", array('title' => $record->Title)))
); );
@ -1200,15 +1200,15 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
); );
} }
$this->response->addHeader('X-Status', rawurlencode($message)); $this->getResponse()->addHeader('X-Status', rawurlencode($message));
// Can be used in different contexts: In normal page edit view, in which case the redirect won't have any effect. // Can be used in different contexts: In normal page edit view, in which case the redirect won't have any effect.
// Or in history view, in which case a revert causes the CMS to re-load the edit view. // Or in history view, in which case a revert causes the CMS to re-load the edit view.
// The X-Pjax header forces a "full" content refresh on redirect. // The X-Pjax header forces a "full" content refresh on redirect.
$url = Controller::join_links(singleton('CMSPageEditController')->Link('show'), $record->ID); $url = Controller::join_links(singleton('CMSPageEditController')->Link('show'), $record->ID);
$this->response->addHeader('X-ControllerURL', $url); $this->getResponse()->addHeader('X-ControllerURL', $url);
$this->getRequest()->addHeader('X-Pjax', 'Content'); $this->getRequest()->addHeader('X-Pjax', 'Content');
$this->response->addHeader('X-Pjax', 'Content'); $this->getResponse()->addHeader('X-Pjax', 'Content');
return $this->getResponseNegotiator()->respond($this->getRequest()); return $this->getResponseNegotiator()->respond($this->getRequest());
} }
@ -1351,7 +1351,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$restoredPage = $restoredPage->doRestoreToStage(); $restoredPage = $restoredPage->doRestoreToStage();
$this->response->addHeader( $this->getResponse()->addHeader(
'X-Status', 'X-Status',
rawurlencode(_t( rawurlencode(_t(
'CMSMain.RESTORED', 'CMSMain.RESTORED',
@ -1382,7 +1382,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$newPage->write(); $newPage->write();
} }
$this->response->addHeader( $this->getResponse()->addHeader(
'X-Status', 'X-Status',
rawurlencode(_t( rawurlencode(_t(
'CMSMain.DUPLICATED', 'CMSMain.DUPLICATED',
@ -1391,9 +1391,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
)) ))
); );
$url = Controller::join_links(singleton('CMSPageEditController')->Link('show'), $newPage->ID); $url = Controller::join_links(singleton('CMSPageEditController')->Link('show'), $newPage->ID);
$this->response->addHeader('X-ControllerURL', $url); $this->getResponse()->addHeader('X-ControllerURL', $url);
$this->getRequest()->addHeader('X-Pjax', 'Content'); $this->getRequest()->addHeader('X-Pjax', 'Content');
$this->response->addHeader('X-Pjax', 'Content'); $this->getResponse()->addHeader('X-Pjax', 'Content');
return $this->getResponseNegotiator()->respond($this->getRequest()); return $this->getResponseNegotiator()->respond($this->getRequest());
} else { } else {
@ -1414,7 +1414,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$newPage = $page->duplicateWithChildren(); $newPage = $page->duplicateWithChildren();
$this->response->addHeader( $this->getResponse()->addHeader(
'X-Status', 'X-Status',
rawurlencode(_t( rawurlencode(_t(
'CMSMain.DUPLICATEDWITHCHILDREN', 'CMSMain.DUPLICATEDWITHCHILDREN',
@ -1423,9 +1423,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
)) ))
); );
$url = Controller::join_links(singleton('CMSPageEditController')->Link('show'), $newPage->ID); $url = Controller::join_links(singleton('CMSPageEditController')->Link('show'), $newPage->ID);
$this->response->addHeader('X-ControllerURL', $url); $this->getResponse()->addHeader('X-ControllerURL', $url);
$this->getRequest()->addHeader('X-Pjax', 'Content'); $this->getRequest()->addHeader('X-Pjax', 'Content');
$this->response->addHeader('X-Pjax', 'Content'); $this->getResponse()->addHeader('X-Pjax', 'Content');
return $this->getResponseNegotiator()->respond($this->getRequest()); return $this->getResponseNegotiator()->respond($this->getRequest());
} else { } else {

View File

@ -51,24 +51,21 @@ class ModelAsController extends Controller implements NestedController {
$this->setDataModel($model); $this->setDataModel($model);
$this->pushCurrent(); $this->pushCurrent();
$this->getResponse();
// Create a response just in case init() decides to redirect
$this->response = new SS_HTTPResponse();
$this->init(); $this->init();
// If we had a redirection or something, halt processing. // If we had a redirection or something, halt processing.
if($this->response->isFinished()) { if($this->getResponse()->isFinished()) {
$this->popCurrent(); $this->popCurrent();
return $this->response; return $this->getResponse();
} }
// If the database has not yet been created, redirect to the build page. // If the database has not yet been created, redirect to the build page.
if(!DB::is_active() || !ClassInfo::hasTable('SiteTree')) { if(!DB::is_active() || !ClassInfo::hasTable('SiteTree')) {
$this->response->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null)); $this->getResponse()->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null));
$this->popCurrent(); $this->popCurrent();
return $this->response; return $this->getResponse();
} }
try { try {

View File

@ -119,9 +119,8 @@ class RootURLController extends Controller {
$this->init(); $this->init();
if(!DB::is_active() || !ClassInfo::hasTable('SiteTree')) { if(!DB::is_active() || !ClassInfo::hasTable('SiteTree')) {
$this->response = new SS_HTTPResponse(); $this->getResponse()->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null));
$this->response->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null)); return $this->getResponse();
return $this->response;
} }
$request->setUrl(self::get_homepage_link() . '/'); $request->setUrl(self::get_homepage_link() . '/');

View File

@ -257,7 +257,7 @@ class ErrorPage extends Page {
'Error opening file "{filename}" for writing. Please check file permissions.', 'Error opening file "{filename}" for writing. Please check file permissions.',
array('filename' => $errorFile) array('filename' => $errorFile)
); );
$this->response->addHeader('X-Status', rawurlencode($fileErrorText)); $this->getResponse()->addHeader('X-Status', rawurlencode($fileErrorText));
return $this->httpError(405); return $this->httpError(405);
} }
return true; return true;
@ -337,9 +337,9 @@ class ErrorPage_Controller extends Page_Controller {
*/ */
public function handleRequest(SS_HTTPRequest $request, DataModel $model = NULL) { public function handleRequest(SS_HTTPRequest $request, DataModel $model = NULL) {
$body = parent::handleRequest($request, $model); $body = parent::handleRequest($request, $model);
$this->response->setStatusCode($this->ErrorCode); $this->getResponse()->setStatusCode($this->ErrorCode);
return $this->response; return $this->getResponse();
} }
} }