From 1be18b792cad486015459845ef185c015f7fab5c Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 25 Sep 2008 00:03:09 +0000 Subject: [PATCH] EHANCEMENT #2853 - You can now use db/build instead of db/build?flush=1 git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63020 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/ManifestBuilder.php | 2 +- core/model/DatabaseAdmin.php | 10 ++++------ tests/ManifestBuilderTest.php | 18 ++++++++++++++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/core/ManifestBuilder.php b/core/ManifestBuilder.php index ca09b4f32..f3320aedb 100644 --- a/core/ManifestBuilder.php +++ b/core/ManifestBuilder.php @@ -175,7 +175,7 @@ class ManifestBuilder { $manifestInfo["require_once"][] = "$baseDir/$filename/_config.php"; // Include this so that we're set up for connecting to the database // in the rest of the manifest builder - require("$baseDir/$filename/_config.php"); + require_once("$baseDir/$filename/_config.php"); } } diff --git a/core/model/DatabaseAdmin.php b/core/model/DatabaseAdmin.php index dcec5800f..686201a44 100644 --- a/core/model/DatabaseAdmin.php +++ b/core/model/DatabaseAdmin.php @@ -87,6 +87,9 @@ class DatabaseAdmin extends Controller { set_time_limit(600); } + // Get all our classes + ManifestBuilder::compileManifest(); + $this->doBuild(isset($_REQUEST['quiet']) || isset($_REQUEST['from_installer'])); } @@ -129,8 +132,6 @@ class DatabaseAdmin extends Controller { * @param boolean $populate Populate the database, as well as setting up its schema */ function doBuild($quiet = false, $populate = true, $testMode = false) { - $conn = DB::getConn(); - if($quiet) { DB::quiet(); } else { @@ -152,10 +153,6 @@ class DatabaseAdmin extends Controller { // ManifestBuilder::compileManifest(); } - // Get all our classes - // ManifestBuilder::compileManifest(); - // ManifestBuilder::includeEverything(); - // Build the database. Most of the hard work is handled by DataObject $dataClasses = ClassInfo::subclassesFor('DataObject'); array_shift($dataClasses); @@ -165,6 +162,7 @@ class DatabaseAdmin extends Controller { else echo "\n

Creating database tables

\n\n"; } + $conn = DB::getConn(); $conn->beginSchemaUpdate(); foreach($dataClasses as $dataClass) { $SNG = singleton($dataClass); diff --git a/tests/ManifestBuilderTest.php b/tests/ManifestBuilderTest.php index 2951f61c2..6d215bca8 100644 --- a/tests/ManifestBuilderTest.php +++ b/tests/ManifestBuilderTest.php @@ -7,6 +7,7 @@ class ManifestBuilderTest extends SapphireTest { function testManifest() { $baseFolder = TEMP_FOLDER . '/manifest-test'; $manifestInfo = ManifestBuilder::get_manifest_info($baseFolder, DB::getConn()->tableList()); + global $project; $this->assertEquals("$baseFolder/sapphire/MyClass.php", $manifestInfo['globals']['_CLASS_MANIFEST']['MyClass']); $this->assertEquals("$baseFolder/sapphire/subdir/SubDirClass.php", $manifestInfo['globals']['_CLASS_MANIFEST']['SubDirClass']); @@ -33,8 +34,10 @@ class ManifestBuilderTest extends SapphireTest { function testManifestIgnoresClassesInComments() { $baseFolder = TEMP_FOLDER . '/manifest-test'; + global $project; + $manifestInfo = ManifestBuilder::get_manifest_info($baseFolder, DB::getConn()->tableList()); - + /* Our fixture defines the class MyClass_InComment inside a comment, so it shouldn't be included in the class manifest. */ $this->assertNotContains('MyClass_InComment', array_keys($manifestInfo['globals']['_CLASS_MANIFEST'])); $this->assertNotContains('MyClass_InComment', array_keys($manifestInfo['globals']['_ALL_CLASSES']['exists'])); @@ -51,7 +54,7 @@ class ManifestBuilderTest extends SapphireTest { function testManifestIgnoresClassesInStrings() { $baseFolder = TEMP_FOLDER . '/manifest-test'; $manifestInfo = ManifestBuilder::get_manifest_info($baseFolder, DB::getConn()->tableList()); - + /* If a class defintion is listed in a single quote string, then it shouldn't be inlcuded. Here we have put a class definition for MyClass_InSingleQuoteString inside a single-quoted string */ $this->assertNotContains('MyClass_InSingleQuoteString', array_keys($manifestInfo['globals']['_CLASS_MANIFEST'])); $this->assertNotContains('MyClass_InSingleQuoteString', array_keys($manifestInfo['globals']['_ALL_CLASSES']['exists'])); @@ -73,6 +76,7 @@ class ManifestBuilderTest extends SapphireTest { protected $originalClassManifest, $originalProject, $originalAllClasses; + protected static $test_fixture_project; function setUp() { // Trick the auto-loder into loading this class before we muck with the manifest @@ -108,13 +112,23 @@ class ManifestBuilderTest extends SapphireTest { } global $_CLASS_MANIFEST, $_ALL_CLASSES, $project; + $this->originalAllClasses = $_ALL_CLASSES; $this->originalClassManifest = $_CLASS_MANIFEST; $this->originalProject = $project; + + // Because it's difficult to run multiple tests on a piece of code that uses require_once, we keep a copy of the + // $project value. + if(self::$test_fixture_project) $project = self::$test_fixture_project; + + global $project; } function tearDown() { global $_CLASS_MANIFEST, $_ALL_CLASSES, $project; + + if(!self::$test_fixture_project) self::$test_fixture_project = $project; + $project = $this->originalProject; $_CLASS_MANIFEST = $this->originalClassManifest; $_ALL_CLASSES = $this->originalAllClasses;