Commit e14126d6 authored by alexpott's avatar alexpott

Issue #3052467 by amateescu, Rick Bergmann: System update 8702 fails with "...

Issue #3052467 by amateescu, Rick Bergmann: System update 8702 fails with " Error: Call to a member function getKey() on null in core\modules\system\system.install"
parent 7dfb49ba
......@@ -2275,6 +2275,13 @@ function system_update_8702() {
// definitions to use the value of the live (in-code) entity type definitions
// in cases when the key has not been populated yet.
foreach ($last_installed_definitions as $entity_type_id => $entity_type) {
// The live (in-code) entity type definition might not exist anymore, while
// an update function that would remove its last installed definition didn't
// run yet. We don't need to update it in that case.
if (!isset($live_definitions[$entity_type_id])) {
continue;
}
$revision_translation_affected_key = $live_definitions[$entity_type_id]->getKey('revision_translation_affected');
if (!$entity_type->hasKey('revision_translation_affected') && !empty($revision_translation_affected_key) && $entity_definition_update_manager->getFieldStorageDefinition($revision_translation_affected_key, $entity_type_id)) {
$entity_keys = $entity_type->getKeys();
......
......@@ -43,7 +43,13 @@ function entity_test_update_entity_field_storage_info(EntityTypeInterface $entit
*/
function entity_test_update_entity_type_alter(array &$entity_types) {
// Allow entity_test_update tests to override the entity type definition.
$entity_types['entity_test_update'] = \Drupal::state()->get('entity_test_update.entity_type', $entity_types['entity_test_update']);
$entity_type = \Drupal::state()->get('entity_test_update.entity_type', $entity_types['entity_test_update']);
if ($entity_type !== 'null') {
$entity_types['entity_test_update'] = $entity_type;
}
else {
unset($entity_types['entity_test_update']);
}
}
/**
......
......@@ -32,6 +32,11 @@ class EntityUpdateAddRevisionTranslationAffectedTest extends UpdatePathTestBase
*/
protected $state;
/**
* {@inheritdoc}
*/
protected static $modules = ['entity_test_update'];
/**
* {@inheritdoc}
*/
......@@ -85,4 +90,32 @@ public function testAddingTheRevisionTranslationAffectedField() {
$this->assertTrue($entity->revision_translation_affected->value);
}
/**
* Tests the 'revision_translation_affected' field on a deleted entity type.
*/
public function testDeletedEntityType() {
// Delete the entity type before running the update. This tests the case
// where the code of an entity type has been removed but its definition has
// not yet been uninstalled.
$this->deleteEntityType();
\Drupal::entityTypeManager()->clearCachedDefinitions();
// Check that the test entity type does not have the
// 'revision_translation_affected' field before running the updates.
$field_storage_definitions = \Drupal::service('entity.last_installed_schema.repository')->getLastInstalledFieldStorageDefinitions('entity_test_update');
$this->assertFalse(isset($field_storage_definitions['revision_translation_affected']));
$this->runUpdates();
// Check that the 'revision_translation_affected' field has not been added
// by system_update_8402().
$field_storage_definitions = \Drupal::service('entity.last_installed_schema.repository')->getLastInstalledFieldStorageDefinitions('entity_test_update');
$this->assertFalse(isset($field_storage_definitions['revision_translation_affected']));
// Check that the entity type definition has not been updated with the new
// 'revision_translation_affected' key.
$entity_type = \Drupal::entityDefinitionUpdateManager()->getEntityType('entity_test_update');
$this->assertFalse($entity_type->getKey('revision_translation_affected'));
}
}
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