From a1e48eff8e6c426bd04da395525d7aaae4bc7a6e Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 5 Mar 2009 04:43:37 +0000 Subject: [PATCH] ENHANCEMENT: Database will fix itself if you view the site and the database doesn't exist git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@72497 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/control/ModelAsController.php | 8 ++++++++ core/control/RootURLController.php | 7 +++++++ core/model/DatabaseAdmin.php | 9 ++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/core/control/ModelAsController.php b/core/control/ModelAsController.php index 6f8352abe..dfb0b2700 100644 --- a/core/control/ModelAsController.php +++ b/core/control/ModelAsController.php @@ -13,6 +13,14 @@ class ModelAsController extends Controller implements NestedController { $this->urlParams = $request->allParams(); $this->init(); + + // If the basic database hasn't been created, then build it. + if(!DB::isActive() || !ClassInfo::hasTable('SiteTree')) { + $this->response = new HTTPResponse(); + $this->redirect("dev/build?returnURL=" . urlencode($_GET['url'])); + return $this->response; + } + $result = $this->getNestedController(); if(is_object($result) && $result instanceOf RequestHandler) { diff --git a/core/control/RootURLController.php b/core/control/RootURLController.php index 3f2330df4..56f0b0863 100755 --- a/core/control/RootURLController.php +++ b/core/control/RootURLController.php @@ -19,6 +19,13 @@ class RootURLController extends Controller { $this->init(); + // If the basic database hasn't been created, then build it. + if(!DB::isActive() || !ClassInfo::hasTable('SiteTree')) { + $this->response = new HTTPResponse(); + $this->redirect("dev/build?returnURL="); + return $this->response; + } + $controller = new ModelAsController(); $request = new HTTPRequest("GET", self::get_homepage_urlsegment().'/', $request->getVars(), $request->postVars()); diff --git a/core/model/DatabaseAdmin.php b/core/model/DatabaseAdmin.php index b231b7bba..e2a3f7cdb 100644 --- a/core/model/DatabaseAdmin.php +++ b/core/model/DatabaseAdmin.php @@ -78,7 +78,14 @@ class DatabaseAdmin extends Controller { ManifestBuilder::create_manifest_file(); require(MANIFEST_FILE); - $this->doBuild(isset($_REQUEST['quiet']) || isset($_REQUEST['from_installer']), !isset($_REQUEST['dont_populate'])); + if(isset($_GET['returnURL'])) { + echo "

Setting up the database; you will be returned to your site shortly....

"; + $this->doBuild(true); + echo "

Done!

"; + Director::redirect($_GET['returnURL']); + } else { + $this->doBuild(isset($_REQUEST['quiet']) || isset($_REQUEST['from_installer']), !isset($_REQUEST['dont_populate'])); + } } /**