Skip to content
Snippets Groups Projects
Select Git revision
  • 6a1b93247e1730eadf57588e69e65db7095b6ee8
  • 11.x default protected
  • 10.5.x protected
  • 10.6.x protected
  • 11.2.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
41 results

update_order_test.install

Blame
  • Nathaniel Catchpole's avatar
    Issue #2535082 by alexpott, jhedstrom, xjm, plach, Fabianx, effulgentsia,...
    catch authored
    Issue #2535082 by alexpott, jhedstrom, xjm, plach, Fabianx, effulgentsia, Berdir: Allow hook_update_N() implementations to run before the automated entity updates
    4f60dd53
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    update_order_test.install 2.33 KiB
    <?php
    
    /**
     * @file
     * Update hooks for the update_order_test module.
     */
    
    use Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface;
    
    /**
     * Only declare the update hooks once the test is running.
     *
     * @see \Drupal\system\Tests\Entity\Update\SqlContentEntityStorageSchemaIndexTest
     */
    if (\Drupal::state()->get('update_order_test', FALSE)) {
    
      /**
       * Runs before entity schema updates.
       */
      function update_order_test_update_8001() {
        // Store whether the node__default_langcode index exists when this hook is
        // invoked.
        \Drupal::state()->set('update_order_test_update_8001', db_index_exists('node_field_data', 'node__default_langcode'));
      }
    
      /**
       * Runs before entity schema updates.
       */
      function update_order_test_update_8002() {
        // Check and store whether the update_order_test field exists when this
        // hook is first invoked.
        \Drupal::state()->set('update_order_test_update_8002_update_order_test_before', db_field_exists('node_field_data', 'update_order_test'));
    
        // Attempt to apply the update for the update_order_test field and then
        // check and store again whether it exists.
        if (\Drupal::service('entity.definition_update_manager')->applyFieldUpdate(EntityDefinitionUpdateManagerInterface::DEFINITION_CREATED, 'node', 'update_order_test')) {
          \Drupal::state()->set('update_order_test_update_8002_update_order_test_after', db_field_exists('node_field_data', 'update_order_test'));
        }
    
        // Attempt to apply all node entity type updates.
        if (\Drupal::service('entity.definition_update_manager')->applyEntityUpdate(EntityDefinitionUpdateManagerInterface::DEFINITION_UPDATED, 'node')) {
          // Node updates have now run. Check and store whether the updated node
          // indices now exist.
          \Drupal::state()->set('update_order_test_update_8002_node__default_langcode', db_index_exists('node_field_data', 'node__default_langcode'));
          \Drupal::state()->set('update_order_test_update_8002_node__id__default_langcode__langcode', db_index_exists('node_field_data', 'node__id__default_langcode__langcode'));
    
          // User updates have not yet run. Check and store whether the updated
          // user indices now exist.
          \Drupal::state()->set('update_order_test_update_8002_user__id__default_langcode__langcode', db_index_exists('users_field_data', 'user__id__default_langcode__langcode'));
        }
      }
    
    }