Merge remote-tracking branch 'tractorcow/pulls/handle-request-cleanup'

This commit is contained in:
Damian Mooyman 2016-05-23 16:57:23 +12:00
commit 3be0f394bf
4 changed files with 48 additions and 21 deletions

View File

@ -48,7 +48,7 @@ class AssetAdmin extends LeftAndMain implements PermissionProvider{
public function currentPageID() {
if(is_numeric($this->getRequest()->requestVar('ID'))) {
return $this->getRequest()->requestVar('ID');
} elseif (is_numeric($this->urlParams['ID'])) {
} elseif (isset($this->urlParams['ID']) && is_numeric($this->urlParams['ID'])) {
return $this->urlParams['ID'];
} elseif(Session::get("{$this->class}.currentPage")) {
return Session::get("{$this->class}.currentPage");

View File

@ -131,7 +131,7 @@ class ContentController extends Controller {
* @return SS_HTTPResponse
* @throws SS_HTTPResponse_Exception
*/
public function handleRequest(SS_HTTPRequest $request, DataModel $model = null) {
public function handleRequest(SS_HTTPRequest $request, DataModel $model) {
$child = null;
$action = $request->param('Action');
$this->setDataModel($model);

View File

@ -40,6 +40,20 @@ class ModelAsController extends Controller implements NestedController {
parent::init();
}
protected function beforeHandleRequest(SS_HTTPRequest $request, DataModel $model) {
parent::beforeHandleRequest($request, $model);
// If the database has not yet been created, redirect to the build page.
if(!DB::is_active() || !ClassInfo::hasTable('SiteTree')) {
$this->getResponse()->redirect(Controller::join_links(
Director::absoluteBaseURL(),
'dev/build',
'?' . array(
'returnURL' => isset($_GET['url']) ? $_GET['url'] : null,
)
));
}
}
/**
* @uses ModelAsController::getNestedController()
* @param SS_HTTPRequest $request
@ -47,12 +61,7 @@ class ModelAsController extends Controller implements NestedController {
* @return SS_HTTPResponse
*/
public function handleRequest(SS_HTTPRequest $request, DataModel $model) {
$this->setRequest($request);
$this->setDataModel($model);
$this->pushCurrent();
$this->getResponse();
$this->init();
$this->beforeHandleRequest($request, $model);
// If we had a redirection or something, halt processing.
if($this->getResponse()->isFinished()) {

View File

@ -106,6 +106,22 @@ class RootURLController extends Controller {
self::$cached_homepage_link = null;
}
protected function beforeHandleRequest(SS_HTTPRequest $request, DataModel $model) {
parent::beforeHandleRequest($request, $model);
self::$is_at_root = true;
if(!DB::is_active() || !ClassInfo::hasTable('SiteTree')) {
$this->getResponse()->redirect(Controller::join_links(
Director::absoluteBaseURL(),
'dev/build',
'?' . array(
'returnURL' => isset($_GET['url']) ? $_GET['url'] : null,
)
));
}
}
/**
* @param SS_HTTPRequest $request
* @param DataModel|null $model
@ -113,24 +129,26 @@ class RootURLController extends Controller {
*/
public function handleRequest(SS_HTTPRequest $request, DataModel $model = null) {
self::$is_at_root = true;
$this->setDataModel($model);
$this->beforeHandleRequest($request, $model);
$this->pushCurrent();
$this->init();
if (!$this->getResponse()->isFinished()) {
if (!DB::is_active() || !ClassInfo::hasTable('SiteTree')) {
$this->getResponse()->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null));
return $this->getResponse();
}
if(!DB::is_active() || !ClassInfo::hasTable('SiteTree')) {
$this->getResponse()->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null));
return $this->getResponse();
$request->setUrl(self::get_homepage_link() . '/');
$request->match('$URLSegment//$Action', true);
$controller = new ModelAsController();
$response = $controller->handleRequest($request, $model);
$this->prepareResponse($response);
}
$request->setUrl(self::get_homepage_link() . '/');
$request->match('$URLSegment//$Action', true);
$controller = new ModelAsController();
$this->afterHandleRequest();
$result = $controller->handleRequest($request, $model);
$this->popCurrent();
return $result;
return $this->getResponse();
}
}