From 281e22b71e6af169692cf81783778aaff7acf6f3 Mon Sep 17 00:00:00 2001 From: Luke Hudson Date: Tue, 4 May 2010 23:19:51 +0000 Subject: [PATCH] FEATURE: Add dev/build/defaults to call requireDefaultRecords git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@104093 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/DatabaseAdmin.php | 12 ++++++++++++ dev/DevelopmentAdmin.php | 27 ++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/core/model/DatabaseAdmin.php b/core/model/DatabaseAdmin.php index 91299d497..6422c8769 100644 --- a/core/model/DatabaseAdmin.php +++ b/core/model/DatabaseAdmin.php @@ -119,6 +119,18 @@ class DatabaseAdmin extends Controller { } } + /** + * Build the default data, calling requireDefaultRecords on all + * DataObject classes + */ + function buildDefaults() { + $dataClasses = ClassInfo::subclassesFor('DataObject'); + array_shift($dataClasses); + foreach($dataClasses as $dataClass){ + singleton($dataClass)->requireDefaultRecords(); + print "Defaults loaded for $dataClass
"; + } + } /** * Returns the timestamp of the time that the database was last built diff --git a/dev/DevelopmentAdmin.php b/dev/DevelopmentAdmin.php index d97e9cb27..6e6157fee 100644 --- a/dev/DevelopmentAdmin.php +++ b/dev/DevelopmentAdmin.php @@ -12,6 +12,7 @@ class DevelopmentAdmin extends Controller { static $url_handlers = array( '' => 'index', + 'build/defaults' => 'buildDefaults', '$Action' => '$Action', '$Action//$Action/$ID' => 'handleAction', ); @@ -134,7 +135,31 @@ class DevelopmentAdmin extends Controller { $renderer->writeFooter(); } } - + + /** + * Build the default data, calling requireDefaultRecords on all + * DataObject classes + * Should match the $url_handlers rule: + * 'build/defaults' => 'buildDefaults', + */ + function buildDefaults() { + $da = new DatabaseAdmin(); + + if (!Director::is_cli()) { + $renderer = new DebugView(); + $renderer->writeHeader(); + $renderer->writeInfo("Defaults Builder", Director::absoluteBaseURL()); + echo "
"; + } + + $da->buildDefaults(); + + if (!Director::is_cli()) { + echo "
"; + $renderer->writeFooter(); + } + } + function reset() { $link = BASE_URL.'/dev/tests/startsession';