public SqlContentEntityStorageSchema::onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original)
Reacts to the update of the entity type.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The updated entity type definition.
\Drupal\Core\Entity\EntityTypeInterface $original: The original entity type definition.
Overrides EntityTypeListenerInterface::onEntityTypeUpdate
File
- core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php, line 292
Class
- SqlContentEntityStorageSchema
- Defines a schema handler that supports revisionable, translatable entities.
Namespace
Drupal\Core\Entity\Sql
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | 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 a migration is required, we can't proceed. if ( $this ->requiresEntityDataMigration( $entity_type , $original )) { throw new EntityStorageException( 'The SQL storage cannot change the schema for an existing entity type (' . $entity_type ->id() . ') with data.' ); } // If we have no data just recreate the entity schema from scratch. if ( $this ->isTableEmpty( $this ->storage->getBaseTable())) { if ( $this ->database->supportsTransactionalDDL()) { // If the database supports transactional DDL, we can go ahead and rely // on it. If not, we will have to rollback manually if something fails. $transaction = $this ->database->startTransaction(); } try { $this ->onEntityTypeDelete( $original ); $this ->onEntityTypeCreate( $entity_type ); } catch (\Exception $e ) { if ( $this ->database->supportsTransactionalDDL()) { $transaction ->rollback(); } else { // Recreate original schema. $this ->onEntityTypeCreate( $original ); } throw $e ; } } else { // Drop original indexes and unique keys. $this ->deleteEntitySchemaIndexes( $this ->loadEntitySchemaData( $entity_type )); // Create new indexes and unique keys. $entity_schema = $this ->getEntitySchema( $entity_type , TRUE); $this ->createEntitySchemaIndexes( $entity_schema ); // Store the updated entity schema. $this ->saveEntitySchemaData( $entity_type , $entity_schema ); } } |
Please login to continue.