mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Merge remote-tracking branch 'tractorcow/pulls/handle-request-cleanup'
This commit is contained in:
commit
3be0f394bf
@ -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");
|
||||
|
@ -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);
|
||||
|
@ -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()) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user