Merge pull request #1259 from stevie-mayhew/pulls/get_response

UPDATE: make all response code use getResponse() method
This commit is contained in:
Daniel Hensby 2015-09-25 12:23:43 +01:00
commit f7985b34f2
5 changed files with 281 additions and 285 deletions

View File

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

View File

@ -743,7 +743,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$this->extend('updateChildFilter', $disallowedChildren, $parentID);
return $this
->response
->getResponse()
->addHeader('Content-Type', 'application/json; charset=utf-8')
->setBody(Convert::raw2json($disallowedChildren));
}
@ -940,7 +940,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
if(!is_subclass_of($className, $parentClass) && strcasecmp($className, $parentClass) != 0) {
$response = Security::permissionFailure($this);
if (!$response) {
$response = $this->response;
$response = $this->getResponse();
}
throw new SS_HTTPResponse_Exception($response);
}
@ -1024,7 +1024,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$descRemoved = '';
}
$this->response->addHeader(
$this->getResponse()->addHeader(
'X-Status',
rawurlencode(
_t(
@ -1073,7 +1073,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$record->doRevertToLive();
$this->response->addHeader(
$this->getResponse()->addHeader(
'X-Status',
rawurlencode(_t(
'CMSMain.RESTORED',
@ -1100,7 +1100,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Delete record
$record->delete();
$this->response->addHeader(
$this->getResponse()->addHeader(
'X-Status',
rawurlencode(sprintf(_t('CMSMain.REMOVEDPAGEFROMDRAFT',"Removed '%s' from the draft site"), $record->Title))
);
@ -1128,7 +1128,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Archive record
$record->doArchive();
$this->response->addHeader(
$this->getResponse()->addHeader(
'X-Status',
rawurlencode(sprintf(_t('CMSMain.ARCHIVEDPAGE',"Archived page '%s'"), $record->Title))
);
@ -1152,7 +1152,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$record->doUnpublish();
$this->response->addHeader(
$this->getResponse()->addHeader(
'X-Status',
rawurlencode(_t('CMSMain.REMOVEDPAGE',"Removed '{title}' from the published site", array('title' => $record->Title)))
);
@ -1201,15 +1201,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.
// 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.
$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->response->addHeader('X-Pjax', 'Content');
$this->getResponse()->addHeader('X-Pjax', 'Content');
return $this->getResponseNegotiator()->respond($this->getRequest());
}
@ -1352,7 +1352,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$restoredPage = $restoredPage->doRestoreToStage();
$this->response->addHeader(
$this->getResponse()->addHeader(
'X-Status',
rawurlencode(_t(
'CMSMain.RESTORED',
@ -1383,7 +1383,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$newPage->write();
}
$this->response->addHeader(
$this->getResponse()->addHeader(
'X-Status',
rawurlencode(_t(
'CMSMain.DUPLICATED',
@ -1392,9 +1392,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
))
);
$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->response->addHeader('X-Pjax', 'Content');
$this->getResponse()->addHeader('X-Pjax', 'Content');
return $this->getResponseNegotiator()->respond($this->getRequest());
} else {
@ -1415,7 +1415,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$newPage = $page->duplicateWithChildren();
$this->response->addHeader(
$this->getResponse()->addHeader(
'X-Status',
rawurlencode(_t(
'CMSMain.DUPLICATEDWITHCHILDREN',
@ -1424,9 +1424,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
))
);
$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->response->addHeader('X-Pjax', 'Content');
$this->getResponse()->addHeader('X-Pjax', 'Content');
return $this->getResponseNegotiator()->respond($this->getRequest());
} else {

View File

@ -51,24 +51,21 @@ class ModelAsController extends Controller implements NestedController {
$this->setDataModel($model);
$this->pushCurrent();
// Create a response just in case init() decides to redirect
$this->response = new SS_HTTPResponse();
$this->getResponse();
$this->init();
// If we had a redirection or something, halt processing.
if($this->response->isFinished()) {
if($this->getResponse()->isFinished()) {
$this->popCurrent();
return $this->response;
return $this->getResponse();
}
// If the database has not yet been created, redirect to the build page.
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();
return $this->response;
return $this->getResponse();
}
try {

View File

@ -119,9 +119,8 @@ class RootURLController extends Controller {
$this->init();
if(!DB::is_active() || !ClassInfo::hasTable('SiteTree')) {
$this->response = new SS_HTTPResponse();
$this->response->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null));
return $this->response;
$this->getResponse()->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null));
return $this->getResponse();
}
$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.',
array('filename' => $errorFile)
);
$this->response->addHeader('X-Status', rawurlencode($fileErrorText));
$this->getResponse()->addHeader('X-Status', rawurlencode($fileErrorText));
return $this->httpError(405);
}
return true;
@ -337,9 +337,9 @@ class ErrorPage_Controller extends Page_Controller {
*/
public function handleRequest(SS_HTTPRequest $request, DataModel $model = NULL) {
$body = parent::handleRequest($request, $model);
$this->response->setStatusCode($this->ErrorCode);
$this->getResponse()->setStatusCode($this->ErrorCode);
return $this->response;
return $this->getResponse();
}
}