FEATURE: Add dev/build/defaults to call requireDefaultRecords (from r104093)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112334 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-10-14 23:57:02 +00:00
parent ea32270eac
commit d50097e905
2 changed files with 38 additions and 1 deletions

View File

@ -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<br/>";
}
}
/**
* Returns the timestamp of the time that the database was last built

View File

@ -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 "<div style=\"margin: 0 2em\">";
}
$da->buildDefaults();
if (!Director::is_cli()) {
echo "</div>";
$renderer->writeFooter();
}
}
function reset() {
$link = BASE_URL.'/dev/tests/startsession';