Merge pull request #7704 from open-sausages/pulls/4.0/before-class-migration

BUG Do database migrations before default records
This commit is contained in:
Chris Joe 2017-12-19 12:02:09 +13:00 committed by GitHub
commit 7e4ff1fb90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -318,22 +318,6 @@ class DatabaseAdmin extends Controller
} }
} }
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 // Remap obsolete class names
$schema = DataObject::getSchema(); $schema = DataObject::getSchema();
foreach ($this->config()->classname_value_remapping as $oldClassName => $newClassName) { foreach ($this->config()->classname_value_remapping as $oldClassName => $newClassName) {
@ -353,7 +337,7 @@ class DatabaseAdmin extends Controller
$updateQueries = [sprintf($updateQuery, '')]; $updateQueries = [sprintf($updateQuery, '')];
// Remap versioned table ClassName values as well // Remap versioned table ClassName values as well
$class = singleton($newClassName); $class = DataObject::singleton($newClassName);
if ($class->has_extension(Versioned::class)) { if ($class->has_extension(Versioned::class)) {
if ($class->hasStages()) { if ($class->hasStages()) {
$updateQueries[] = sprintf($updateQuery, '_Live'); $updateQueries[] = sprintf($updateQuery, '_Live');
@ -367,6 +351,23 @@ class DatabaseAdmin extends Controller
} }
} }
// 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()) { if (!$quiet && !Director::is_cli()) {
echo "</ul>"; echo "</ul>";
} }