function gathercontent_on_entity_delete in GatherContent 8.5
Deletes the tracked table records for this entity and rolls back the migration.
Parameters
\Drupal\Core\Entity\EntityInterface $entity:
Throws
\Drupal\migrate\MigrateException
2 calls to gathercontent_on_entity_delete()
- gathercontent_entity_delete in ./
gathercontent.module - Implements hook_entity_delete().
- gathercontent_entity_translation_delete in ./
gathercontent.module - Implements hook_entity_translation_delete().
File
- ./
gathercontent.module, line 117 - Main module file for GatherContent module.
Code
function gathercontent_on_entity_delete(EntityInterface $entity, $skipLanguage = false) {
$entityId = $entity
->id();
$entityType = $entity
->getEntityTypeId();
$langcode = $entity
->language()
->getId();
/** @var \Drupal\Core\Database\Connection $connection */
$connection = \Drupal::service('database');
$query = $connection
->select('gathercontent_entity_mapping')
->fields('gathercontent_entity_mapping', [
'entity_id',
'entity_type',
'gc_id',
'migration_id',
])
->condition('entity_id', $entityId)
->condition('entity_type', $entityType);
if (!$skipLanguage) {
$query
->condition('langcode', $langcode);
}
$results = $query
->execute()
->fetchAll();
if (empty($results)) {
return;
}
$deleteQuery = $connection
->delete('gathercontent_entity_mapping')
->condition('entity_id', $entityId)
->condition('entity_type', $entityType);
if (!$skipLanguage) {
$deleteQuery
->condition('langcode', $langcode);
}
$deleteQuery
->execute();
foreach ($results as $result) {
$migration = \Drupal::service('plugin.manager.migration')
->createInstance($result->migration_id);
if ($migration) {
$messages = new MigrateMessageCapture();
$executable = new MigrateExecutable($migration, $messages, [
'idlist' => $result->gc_id,
]);
$executable
->rollback();
}
}
}