Commit 47381094 authored by alexpott's avatar alexpott

Issue #2342543 by fago, dixon_, jeqq: Applying entity schema updates fail when...

Issue #2342543 by fago, dixon_, jeqq: Applying entity schema updates fail when both entity type and base field definitions change at the same time
parent 01d9799d
......@@ -70,12 +70,6 @@ public function getChangeSummary() {
$summary = array();
foreach ($this->getChangeList() as $entity_type_id => $change_list) {
// Process entity type definition changes.
if (!empty($change_list['entity_type']) && $change_list['entity_type'] == static::DEFINITION_UPDATED) {
$entity_type = $this->entityManager->getDefinition($entity_type_id);
$summary[$entity_type_id][] = $this->t('Update the %entity_type entity type.', array('%entity_type' => $entity_type->getLabel()));
}
// Process field storage definition changes.
if (!empty($change_list['field_storage_definitions'])) {
$storage_definitions = $this->entityManager->getFieldStorageDefinitions($entity_type_id);
......@@ -97,6 +91,11 @@ public function getChangeSummary() {
}
}
}
// Process entity type definition changes.
if (!empty($change_list['entity_type']) && $change_list['entity_type'] == static::DEFINITION_UPDATED) {
$entity_type = $this->entityManager->getDefinition($entity_type_id);
$summary[$entity_type_id][] = $this->t('Update the %entity_type entity type.', array('%entity_type' => $entity_type->getLabel()));
}
}
return $summary;
......@@ -107,13 +106,6 @@ public function getChangeSummary() {
*/
public function applyUpdates() {
foreach ($this->getChangeList() as $entity_type_id => $change_list) {
// Process entity type definition changes.
if (!empty($change_list['entity_type']) && $change_list['entity_type'] == static::DEFINITION_UPDATED) {
$entity_type = $this->entityManager->getDefinition($entity_type_id);
$original = $this->entityManager->getLastInstalledDefinition($entity_type_id);
$this->entityManager->onEntityTypeUpdate($entity_type, $original);
}
// Process field storage definition changes.
if (!empty($change_list['field_storage_definitions'])) {
$storage_definitions = $this->entityManager->getFieldStorageDefinitions($entity_type_id);
......@@ -135,6 +127,15 @@ public function applyUpdates() {
}
}
}
// Process entity type definition changes after storage definitions ones
// as entity type updates might create base fields as well. That way, if
// both occur at the same time it does not lead to problems due to the
// base field creation being applied twice.
if (!empty($change_list['entity_type']) && $change_list['entity_type'] == static::DEFINITION_UPDATED) {
$entity_type = $this->entityManager->getDefinition($entity_type_id);
$original = $this->entityManager->getLastInstalledDefinition($entity_type_id);
$this->entityManager->onEntityTypeUpdate($entity_type, $original);
}
}
}
......
......@@ -477,6 +477,25 @@ public function testDefinitionEvents() {
$this->assertTrue($event_subscriber->hasEventFired(EntityTypeEvents::DELETE), 'Entity type delete event successfully dispatched.');
}
/**
* Tests updating entity schema and creating a base field at the same time when there are no existing entities.
*/
public function testEntityTypeSchemaUpdateAndBaseFieldCreateWithoutData() {
$this->updateEntityTypeToRevisionable();
$this->addBaseField();
// Entity type updates create base fields as well, thus make sure doing both
// at the same time does not lead to errors due to the base field being
// created twice.
try {
$this->entityDefinitionUpdateManager->applyUpdates();
$this->pass('Successfully updated entity schema and created base field at the same time.');
}
catch (\Exception $e) {
$this->fail('Successfully updated entity schema and created base field at the same time.');
throw $e;
}
}
/**
* Updates the 'entity_test_update' entity type to revisionable.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment