mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Fixes relating to Controller cleanup
This commit is contained in:
parent
933a294478
commit
e04e992c73
@ -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,12 +129,10 @@ 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(!DB::is_active() || !ClassInfo::hasTable('SiteTree')) {
|
||||
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();
|
||||
}
|
||||
@ -127,10 +141,14 @@ class RootURLController extends Controller {
|
||||
$request->match('$URLSegment//$Action', true);
|
||||
$controller = new ModelAsController();
|
||||
|
||||
$result = $controller->handleRequest($request, $model);
|
||||
$response = $controller->handleRequest($request, $model);
|
||||
|
||||
$this->popCurrent();
|
||||
return $result;
|
||||
$this->prepareResponse($response);
|
||||
}
|
||||
|
||||
$this->afterHandleRequest();
|
||||
|
||||
return $this->getResponse();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user