Skip to content

Commit

Permalink
BUG Do database migrations before default records
Browse files Browse the repository at this point in the history
Fixes #7703
  • Loading branch information
Damian Mooyman committed Dec 18, 2017
1 parent d9d1e13 commit ce07e47
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/ORM/DatabaseAdmin.php
Expand Up @@ -318,22 +318,6 @@ public function doBuild($quiet = false, $populate = true, $testMode = false)
}
}

foreach ($dataClasses as $dataClass) {
// Check if class exists before trying to instantiate - this sidesteps any manifest weirdness
// Test_ indicates that it's the data class is part of testing system
if (strpos($dataClass, 'Test_') === false && class_exists($dataClass)) {
if (!$quiet) {
if (Director::is_cli()) {
echo " * $dataClass\n";
} else {
echo "<li>$dataClass</li>\n";
}
}

singleton($dataClass)->requireDefaultRecords();
}
}

// Remap obsolete class names
$schema = DataObject::getSchema();
foreach ($this->config()->classname_value_remapping as $oldClassName => $newClassName) {
Expand All @@ -353,7 +337,7 @@ public function doBuild($quiet = false, $populate = true, $testMode = false)
$updateQueries = [sprintf($updateQuery, '')];

// Remap versioned table ClassName values as well
$class = singleton($newClassName);
$class = DataObject::singleton($newClassName);
if ($class->has_extension(Versioned::class)) {
if ($class->hasStages()) {
$updateQueries[] = sprintf($updateQuery, '_Live');
Expand All @@ -367,6 +351,23 @@ public function doBuild($quiet = false, $populate = true, $testMode = false)
}
}

// Require all default records
foreach ($dataClasses as $dataClass) {
// Check if class exists before trying to instantiate - this sidesteps any manifest weirdness
// Test_ indicates that it's the data class is part of testing system
if (strpos($dataClass, 'Test_') === false && class_exists($dataClass)) {
if (!$quiet) {
if (Director::is_cli()) {
echo " * $dataClass\n";
} else {
echo "<li>$dataClass</li>\n";
}
}

DataObject::singleton($dataClass)->requireDefaultRecords();
}
}

if (!$quiet && !Director::is_cli()) {
echo "</ul>";
}
Expand Down

0 comments on commit ce07e47

Please sign in to comment.