From d4b8db27afddc49f5ff37b25ed13490f6ec5c608 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 16 Jul 2012 23:30:59 +0200 Subject: [PATCH] Marking fake LeftAndMain->redirect() responses as finished Introduce new LeftAndMain_HTTPResponse class for this purpose, to mark a response as finished regardless of HTTP status. This is required for ajax responses which do redirects on app layer rather than HTTP (to avoid double processing). Specifically required to decorate LeftAndMain->init() in the 'translatable' module (TranslatableCMSMainExtension), which marks the response as finished through its redirect, avoiding further processing after init(). --- admin/code/LeftAndMain.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/admin/code/LeftAndMain.php b/admin/code/LeftAndMain.php index 0e488c48f..16914770e 100644 --- a/admin/code/LeftAndMain.php +++ b/admin/code/LeftAndMain.php @@ -358,6 +358,17 @@ class LeftAndMain extends Controller implements PermissionProvider { if($this->request->getHeader('X-Pjax') && !$this->response->getHeader('X-Pjax')) { $this->response->addHeader('X-Pjax', $this->request->getHeader('X-Pjax')); } + $oldResponse = $this->response; + $newResponse = new LeftAndMain_HTTPResponse( + $oldResponse->getBody(), + $oldResponse->getStatusCode(), + $oldResponse->getStatusDescription() + ); + foreach($oldResponse->getHeaders() as $k => $v) { + $newResponse->addHeader($k, $v); + } + $newResponse->setIsFinished(true); + $this->response = $newResponse; return ''; // Actual response will be re-requested by client } else { parent::redirect($url, $code); @@ -1471,3 +1482,19 @@ class LeftAndMainMarkingFilter { } } +/** + * Allow overriding finished state for faux redirects. + */ +class LeftAndMain_HTTPResponse extends SS_HTTPResponse { + + protected $isFinished = false; + + function isFinished() { + return (parent::isFinished() || $this->isFinished); + } + + function setIsFinished($bool) { + $this->isFinished = $bool; + } + +} \ No newline at end of file