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();
$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));
}
@ -553,7 +553,7 @@ JS
*/
public function doSync() {
$message = Filesystem::sync();
$this->response->addHeader('X-Status', rawurlencode($message));
$this->getResponse()->addHeader('X-Status', rawurlencode($message));
return;
}
@ -587,7 +587,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

@ -742,7 +742,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));
}
@ -939,7 +939,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);
}
@ -1023,7 +1023,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$descRemoved = '';
}
$this->response->addHeader(
$this->getResponse()->addHeader(
'X-Status',
rawurlencode(
_t(
@ -1072,7 +1072,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$record->doRevertToLive();
$this->response->addHeader(
$this->getResponse()->addHeader(
'X-Status',
rawurlencode(_t(
'CMSMain.RESTORED',
@ -1099,7 +1099,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))
);
@ -1127,7 +1127,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))
);
@ -1151,7 +1151,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)))
);
@ -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.
// 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());
}
@ -1351,7 +1351,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$restoredPage = $restoredPage->doRestoreToStage();
$this->response->addHeader(
$this->getResponse()->addHeader(
'X-Status',
rawurlencode(_t(
'CMSMain.RESTORED',
@ -1382,7 +1382,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$newPage->write();
}
$this->response->addHeader(
$this->getResponse()->addHeader(
'X-Status',
rawurlencode(_t(
'CMSMain.DUPLICATED',
@ -1391,9 +1391,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 {
@ -1414,7 +1414,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$newPage = $page->duplicateWithChildren();
$this->response->addHeader(
$this->getResponse()->addHeader(
'X-Status',
rawurlencode(_t(
'CMSMain.DUPLICATEDWITHCHILDREN',
@ -1423,9 +1423,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();
}
}