You are here

public function SqlContentEntityStorageSchema::requiresEntityDataMigration in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::requiresEntityDataMigration()
  2. 9 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::requiresEntityDataMigration()

Checks if existing data would be lost if the schema changes were applied.

If there are no schema changes needed, then no data needs to be migrated, but it is not the responsibility of this function to recheck what requiresEntityStorageSchemaChanges() checks. Rather, the meaning of what this function returns when requiresEntityStorageSchemaChanges() returns FALSE is undefined. Callers are expected to only call this function when requiresEntityStorageSchemaChanges() is TRUE.

This function can return FALSE if any of these conditions apply:

  • There are no existing entities for the entity type.
  • There are existing entities, but the schema changes can be applied without losing their data (e.g., if the schema changes can be performed by altering tables rather than dropping and recreating them).
  • The only entity data that would be lost are ones that are not valid for the new definition (e.g., if changing an entity type from revisionable to non-revisionable, then it's okay to drop data for the non-default revision).

When this function returns FALSE, site administrators will be unable to perform an automated update, and will instead need to perform a site migration or invoke some custom update process.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The updated entity type definition.

\Drupal\Core\Entity\EntityTypeInterface $original: The original entity type definition.

Return value

bool TRUE if data migration is required, FALSE otherwise.

Overrides EntityStorageSchemaInterface::requiresEntityDataMigration

See also

self::requiresEntityStorageSchemaChanges()

File

core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php, line 322

Class

SqlContentEntityStorageSchema
Defines a schema handler that supports revisionable, translatable entities.

Namespace

Drupal\Core\Entity\Sql

Code

public function requiresEntityDataMigration(EntityTypeInterface $entity_type, EntityTypeInterface $original) {

  // If the original storage has existing entities, or it is impossible to
  // determine if that is the case, require entity data to be migrated.
  $original_storage_class = $original
    ->getStorageClass();
  if (!class_exists($original_storage_class)) {
    return TRUE;
  }

  // Data migration is not needed when only indexes changed, as they can be
  // applied if there is data.
  if (!$this
    ->hasSharedTableStructureChange($entity_type, $original)) {
    return FALSE;
  }
  return $this->storage
    ->hasData();
}