Skip to content
Snippets Groups Projects
Unverified Commit 84e5e8e4 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2655162 by amateescu, Berdir, bradjones1, Maria Kvitova, joachim,...

Issue #2655162 by amateescu, Berdir, bradjones1, Maria Kvitova, joachim, plach, effulgentsia, tim.plunkett, xjm: Fatal error when updating or deleting an entity type after removing its class/definition from the codebase
parent aae94ed6
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -83,11 +83,13 @@ public function onEntityTypeCreate(EntityTypeInterface $entity_type) {
* {@inheritdoc}
*/
public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original) {
$entity_type_id = $entity_type->id();
// An entity type can be updated even when its live (in-code) definition has
// been removed from the codebase, so we need to instantiate a custom
// storage handler that uses the passed-in entity type definition.
$storage = $this->entityTypeManager->createHandlerInstance($entity_type->getStorageClass(), $entity_type);
// @todo Forward this to all interested handlers, not only storage, once
// iterating handlers is possible: https://www.drupal.org/node/2332857.
$storage = $this->entityTypeManager->getStorage($entity_type_id);
if ($storage instanceof EntityTypeListenerInterface) {
$storage->onEntityTypeUpdate($entity_type, $original);
}
......@@ -103,9 +105,13 @@ public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeI
public function onEntityTypeDelete(EntityTypeInterface $entity_type) {
$entity_type_id = $entity_type->id();
// An entity type can be deleted even when its live (in-code) definition has
// been removed from the codebase, so we need to instantiate a custom
// storage handler that uses the passed-in entity type definition.
$storage = $this->entityTypeManager->createHandlerInstance($entity_type->getStorageClass(), $entity_type);
// @todo Forward this to all interested handlers, not only storage, once
// iterating handlers is possible: https://www.drupal.org/node/2332857.
$storage = $this->entityTypeManager->getStorage($entity_type_id);
if ($storage instanceof EntityTypeListenerInterface) {
$storage->onEntityTypeDelete($entity_type);
}
......
......@@ -138,6 +138,65 @@ public function testEntityTypeUpdateWithEntityStorageChange() {
}
}
/**
* Tests updating an entity type that doesn't exist in code anymore.
*
* @covers ::updateEntityType
*/
public function testUpdateEntityTypeWithoutInCodeDefinition() {
$entity_type = clone $this->entityManager->getDefinition('entity_test_update');
// Remove the entity type definition. This is the same thing as removing the
// code that defines it.
$this->deleteEntityType();
// Add an entity index, update the entity type and check that the index has
// been created.
$this->addEntityIndex();
$this->entityDefinitionUpdateManager->updateEntityType($entity_type);
$this->assertTrue($this->database->schema()->indexExists('entity_test_update', 'entity_test_update__new_index'), 'Index created.');
}
/**
* Tests updating a fieldable entity type that doesn't exist in code anymore.
*
* @covers ::updateFieldableEntityType
*/
public function testUpdateFieldableEntityTypeWithoutInCodeDefinition() {
$entity_type = clone $this->entityManager->getDefinition('entity_test_update');
$field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions('entity_test_update');
// Remove the entity type definition. This is the same thing as removing the
// code that defines it.
$this->deleteEntityType();
// Rename the base table, update the fieldable entity type and check that
// the table has been renamed.
$entity_type->set('base_table', 'entity_test_update_new');
$this->entityDefinitionUpdateManager->updateFieldableEntityType($entity_type, $field_storage_definitions);
$this->assertTrue($this->database->schema()->tableExists('entity_test_update_new'), 'The base table has been renamed.');
$this->assertFalse($this->database->schema()->tableExists('entity_test_update'), 'The old base table does not exist anymore.');
}
/**
* Tests uninstalling an entity type that doesn't exist in code anymore.
*
* @covers ::uninstallEntityType
*/
public function testUninstallEntityTypeWithoutInCodeDefinition() {
$entity_type = clone $this->entityManager->getDefinition('entity_test_update');
// Remove the entity type definition. This is the same thing as removing the
// code that defines it.
$this->deleteEntityType();
// Now uninstall it and check that the tables have been removed.
$this->entityDefinitionUpdateManager->uninstallEntityType($entity_type);
$this->assertFalse($this->database->schema()->tableExists('entity_test_update'), 'Base table for entity_test_update does not exist anymore.');
}
/**
* Tests creating, updating, and deleting a base field if no entities exist.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment