From ce07e4781e8fbb5d46b2ff4d9d9115fb37be36dc Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Thu, 14 Dec 2017 16:49:20 +1300 Subject: [PATCH] BUG Do database migrations before default records Fixes #7703 --- src/ORM/DatabaseAdmin.php | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/ORM/DatabaseAdmin.php b/src/ORM/DatabaseAdmin.php index 945b787e8..4d87bc98c 100644 --- a/src/ORM/DatabaseAdmin.php +++ b/src/ORM/DatabaseAdmin.php @@ -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 "
  • $dataClass
  • \n"; - } - } - - singleton($dataClass)->requireDefaultRecords(); - } - } - // Remap obsolete class names $schema = DataObject::getSchema(); foreach ($this->config()->classname_value_remapping as $oldClassName => $newClassName) { @@ -353,7 +337,7 @@ class DatabaseAdmin extends Controller $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'); @@ -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 "
  • $dataClass
  • \n"; + } + } + + DataObject::singleton($dataClass)->requireDefaultRecords(); + } + } + if (!$quiet && !Director::is_cli()) { echo ""; }