Drupal 8  8.0.2
Field API bulk data deletion
Collaboration diagram for Field API bulk data deletion:

Functions

 hook_field_purge_field_storage (\Drupal\field\Entity\FieldStorageConfig $field_storage)
 
 hook_field_purge_field (\Drupal\field\Entity\FieldConfig $field)
 
 field_purge_batch ($batch_size, $field_storage_uuid=NULL)
 
 field_purge_field (FieldConfigInterface $field)
 
 field_purge_field_storage (FieldStorageConfigInterface $field_storage)
 

Detailed Description

Cleans up after Field API bulk deletion operations.

Field API provides functions for deleting data attached to individual entities as well as deleting entire fields or field storages in a single operation.

When a single entity is deleted, the Entity storage performs the following operations:

Similar operations are performed on deletion of a single entity revision.

When a bundle, field or field storage is deleted, it is not practical to perform those operations immediately on every affected entity in a single page request; there could be thousands or millions of them. Instead, the appropriate field data items, fields, and/or field storages are marked as deleted so that subsequent load or query operations will not return them. Later, a separate process cleans up, or "purges", the marked-as-deleted data by going through the three-step process described above and, finally, removing deleted field storage and field records.

Purging field data is made somewhat tricky by the fact that, while $entity->delete() has a complete entity to pass to the various deletion steps, the Field API purge process only has the field data it has previously stored. It cannot reconstruct complete original entities to pass to the deletion operations. It is even possible that the original entity to which some Field API data was attached has been itself deleted before the field purge operation takes place.

Field API resolves this problem by using stub entities during purge operations, containing only the information from the original entity that Field API knows about: entity type, ID, revision ID, and bundle. It also contains the field data for whichever field is currently being purged.

See Field API for information about the other parts of the Field API.

Function Documentation

field_purge_batch (   $batch_size,
  $field_storage_uuid = NULL 
)

Purges a batch of deleted Field API data, field storages, or fields.

This function will purge deleted field data in batches. The batch size is defined as an argument to the function, and once each batch is finished, it continues with the next batch until all have completed. If a deleted field with no remaining data records is found, the field itself will be purged. If a deleted field storage with no remaining fields is found, the field storage itself will be purged.

Parameters
$batch_sizeThe maximum number of field data records to purge before returning.
string$field_storage_uuid(optional) Limit the purge to a specific field storage.

References Drupal\entityManager(), field_purge_field(), field_purge_field_storage(), and Drupal\state().

Referenced by ConfigImporterFieldPurger\process(), FieldConfigDeleteForm\submitForm(), CommentFieldsTest\testCommentInstallAfterContentModule(), CommentUninstallTest\testCommentUninstallWithoutField(), FieldImportDeleteTest\testImportDelete(), BulkDeleteTest\testPurgeField(), and BulkDeleteTest\testPurgeFieldStorage().

Here is the call graph for this function:

Here is the caller graph for this function:

field_purge_field ( FieldConfigInterface  $field)

Purges a field record from the database.

This function assumes all data for the field has already been purged and should only be called by field_purge_batch().

Parameters
$fieldThe field record to purge.

References Drupal\moduleHandler(), Drupal\state(), and EntityInterface\uuid().

Referenced by field_purge_batch().

Here is the call graph for this function:

Here is the caller graph for this function:

field_purge_field_storage ( FieldStorageConfigInterface  $field_storage)

Purges a field record from the database.

This function assumes all fields for the field storage has already been purged, and should only be called by field_purge_batch().

Parameters
\Drupal\field\FieldStorageConfigInterface$field_storageThe field storage to purge.
Exceptions
Drupal\field\FieldException

References Drupal\entityManager(), FieldStorageDefinitionInterface\getName(), FieldStorageDefinitionInterface\getTargetEntityTypeId(), Drupal\moduleHandler(), Drupal\state(), t(), and EntityInterface\uuid().

Referenced by field_purge_batch().

Here is the call graph for this function:

Here is the caller graph for this function:

hook_field_purge_field ( \Drupal\field\Entity\FieldConfig  $field)

Acts when a field is being purged.

In field_purge_field(), after the field definition has been removed from the system, the entity storage has purged stored field data, and the field info cache has been cleared, this hook is invoked on all modules to allow them to respond to the field being purged.

Parameters
$fieldThe field being purged.

References db_delete().

Here is the call graph for this function:

hook_field_purge_field_storage ( \Drupal\field\Entity\FieldStorageConfig  $field_storage)

Acts when a field storage definition is being purged.

In field_purge_field_storage(), after the storage definition has been removed from the system, the entity storage has purged stored field data, and the field definitions cache has been cleared, this hook is invoked on all modules to allow them to respond to the field storage being purged.

Parameters
$field_storageThe field storage being purged.

References db_delete().

Here is the call graph for this function: