Problem/Motivation

The core database update process invokes the entity definition updates prior to any other update hooks. This will throw exceptions on sufficiently old databases/betas (see #2530940: Provide beta7 update tests for instance). Since these exceptions are unhandled, no update hooks that attempt to resolve those very same exceptions can be run.

Proposed resolution

Replace the core service with one provided by this module that can disable the entity definition updates using a flag stored via the State API.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhedstrom’s picture

Status: Active » Needs review
FileSize
2.06 KB

This works remarkably well (testing in #2530940: Provide beta7 update tests).

amateescu’s picture

+++ b/beta2beta/beta2beta.services.yml
@@ -0,0 +1,4 @@
+services:
+  entity.definition_update_manager:
+    class: Drupal\beta2beta\Entity\EntityDefinitionUpdateManager
+    arguments: ['@entity.manager', '@state']

Wow, this is the only thing needed in order to override a core service? That's awesome :)

+++ b/beta2beta/src/Entity/EntityDefinitionUpdateManager.php
@@ -0,0 +1,53 @@
+use Drupal\Core\State\State;
...
+   * @var \Drupal\Core\State\State
...
+   * @param \Drupal\Core\State\State $state
...
+  public function __construct(EntityManagerInterface $entity_manager, State $state) {

A tiny nitpick: we should use StateInterface here.

Berdir’s picture

#2533282: Make schema methods' visibility public in SqlContentEntityStorage made me think...

What if.... we change the order of update functions to always run entity updates *last*? That gives update functions the changes to run first and correct whatever needs manual correction and then entity update can jump in and take care of the remaining stuff?

Then this wouldn't be needed anymore I think.

jhedstrom’s picture

What if.... we change the order of update functions to always run entity updates *last*?

That makes sense to me. That would effectively do the same thing that gets done here, except one could potentially only need to run updates once.

jhedstrom’s picture

However, changing the order would not provide a workaround for #2533282: Make schema methods' visibility public in SqlContentEntityStorage.

jhedstrom’s picture

-enzo-’s picture

I did a small local change to patch #1 to force disable_entity_definition_updates in a migration from Beta11 to Beta12

/**
    * {@inheritdoc}
    */
  public function applyUpdates() {
    if ($this->state->get('beta2beta.disable_entity_definition_updates', TRUE)) {
      // Automatic updates are disabled.
      drupal_set_message($this->t('Automatic entity definition updates are disabled by the Beta 2 Beta module.'), 'warning');
      return;
    }
    parent::applyUpdates();
  }

Maybe we could use the beta2beta settings or maybe provide instructions to modify the update.

Outside this the patch works like a charm thank @jhedstrom

jhedstrom’s picture

Status: Needs review » Closed (won't fix)