Problem/Motivation

Currently entity type schema is created only when installing the module providing the definitions. However it may happen that a new definition is added in an already installed module. Currently the related schema will never be created nor it will be detected as a missing schema update.

Proposed resolution

Make the EntityDefinitionUpdateManager detect also new entity type definitions and apply the related updates.

Remaining tasks

  • Validate the proposed solution
  • Write a patch
  • Review it

User interface changes

None

API changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

plach’s picture

Status: Active » Needs review
FileSize
9.57 KB

Let's see how many things break.

plach’s picture

A diff -w version to ease reviewing.

plach’s picture

Status: Needs review » Needs work

The last submitted patch, 1: entity-on_create-2423213-1.patch, failed testing.

catch’s picture

Issue tags: +D8 upgrade path
plach’s picture

@catch:

I'm not sure this affects the upgrade path: once this is fixed, we just need to apply the regular db updates, I think.

plach’s picture

Status: Needs work » Needs review
FileSize
11.08 KB
1.51 KB

This should fix test failures, additional test coverage still to do.

catch’s picture

@plach doesn't this mean that:

1. Install a module
2. Module adds an entity type in a new release
3. Update that module
4. Site is hosed without manual intervention

If so I think the upgrade path tag is right, but feel free to untag if this isn't the case.

plach’s picture

I meant the 4 can be fixed by just running update.php, if this is fixed when we already support the upgrade path.

plach’s picture

Issue tags: -Needs tests
FileSize
4.89 KB
15.97 KB

And now with tests. Interdiff is the test-only patch.

The last submitted patch, 10: entity-on_create-2423213-10-test.patch, failed testing.

Berdir’s picture

  1. +++ b/core/modules/locale/src/Tests/LocaleTranslatedSchemaDefinitionTest.php
    @@ -31,6 +31,8 @@ protected function setUp() {
         $this->config('system.site')->set('langcode', 'fr')->save();
    +    // Make sure new entity type definitions are processed.
    +    \Drupal::service('entity.definition_update_manager')->applyUpdates();
         // Clear all caches so that the base field definition, its cache in the
         // entity manager, the t() cache, etc. are all cleared.
    

    Why is this needed here?

  2. +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestNew.php
    @@ -0,0 +1,35 @@
    + *   label = @Translation("Test entity new"),
    + *   handlers = {
    + *     "storage_schema" = "Drupal\entity_test\EntityTestStorageSchema"
    + *   },
    + *   base_table = "entity_test_new",
    + *   fieldable = TRUE,
    + *   persistent_cache = FALSE,
    

    I think we don't need the custom handler and fieldable/cache definitions, to keep this as short as possible?

    Also, I think "New test entity" reads a bit better?

RTBC apart from those nitpicks I think.

plach’s picture

FileSize
15.82 KB
790 bytes

Why is this needed here?

Because also config entities trigger the on create event, and for some reason those are not registered in the entity manager state when setting up the test.

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Great, this looks good to me then.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue addresses a critical bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 8007ab1 and pushed to 8.0.x. Thanks!

  • alexpott committed 8007ab1 on 8.0.x
    Issue #2423213 by plach: Schema for newly defined entity types is never...
plach’s picture

Assigned: plach » Unassigned
Issue tags: -sprint

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

xjm’s picture