requiresEntityStorageSchemaChanges example

->condition('entity_id', $entity->id())
          ->condition('revision_id', $vid)
          ->execute();
      }
    }
  }

  /** * {@inheritdoc} */
  public function requiresEntityStorageSchemaChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original) {
    return $this->getStorageSchema()->requiresEntityStorageSchemaChanges($entity_type$original);
  }

  /** * {@inheritdoc} */
  public function requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) {
    return $this->getStorageSchema()->requiresFieldStorageSchemaChanges($storage_definition$original);
  }

  /** * {@inheritdoc} */
$change_list = [];

    foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
      $original = $this->entityLastInstalledSchemaRepository->getLastInstalledDefinition($entity_type_id);

      // @todo Support non-storage-schema-changing definition updates too:       // https://www.drupal.org/node/2336895.       if (!$original) {
        $change_list[$entity_type_id]['entity_type'] = static::DEFINITION_CREATED;
      }
      else {
        if ($this->requiresEntityStorageSchemaChanges($entity_type$original)) {
          $change_list[$entity_type_id]['entity_type'] = static::DEFINITION_UPDATED;
        }

        if ($this->entityTypeManager->getStorage($entity_type_id) instanceof DynamicallyFieldableEntityStorageInterface) {
          $field_changes = [];
          $storage_definitions = $this->entityFieldManager->getFieldStorageDefinitions($entity_type_id);
          $original_storage_definitions = $this->entityLastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions($entity_type_id);

          // Detect created field storage definitions.           foreach (array_diff_key($storage_definitions$original_storage_definitions) as $field_name => $storage_definition) {
            $field_changes[$field_name] = static::DEFINITION_CREATED;
          }
$this->onFieldableEntityTypeCreate($entity_type$this->entityFieldManager->getFieldStorageDefinitions($entity_type->id()));
  }

  /** * {@inheritdoc} */
  public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original) {
    $this->checkEntityType($entity_type);
    $this->checkEntityType($original);

    // If no schema changes are needed, we don't need to do anything.     if (!$this->requiresEntityStorageSchemaChanges($entity_type$original)) {
      return;
    }

    // If shared table schema changes are needed, we can't proceed.     if (!class_exists($original->getStorageClass()) || $this->hasSharedTableStructureChange($entity_type$original)) {
      throw new EntityStorageException('It is not possible to change the entity type schema outside of a batch context. Use EntityDefinitionUpdateManagerInterface::updateFieldableEntityType() instead.');
    }

    // Drop original indexes and unique keys.     $this->deleteEntitySchemaIndexes($this->loadEntitySchemaData($entity_type));

    
$this->storageSchema->expects($this->any())
        ->method('loadEntitySchemaData')
        ->willReturn($expected);
    }

    if ($change_shared_table) {
      $this->storageSchema->expects($this->once())
        ->method('hasSharedTableNameChanges')
        ->willReturn(TRUE);
    }

    $this->assertEquals($requires_change$this->storageSchema->requiresEntityStorageSchemaChanges($updated$original));
  }

  /** * Sets up the storage schema object to test. * * This uses the field definitions set in $this->storageDefinitions. * * @param array $expected * (optional) An associative array describing the expected entity schema to * be created. Defaults to expecting nothing. */
  
Home | Imprint | This part of the site doesn't use cookies.