3
0
Fork 0
mirror of https://github.com/farmOS/farmOS.git synced 2024-02-23 11:37:38 +01:00

Delete parent references to taxonomy terms during migration rollback.

This commit is contained in:
Michael Stenta 2021-09-15 15:32:05 -04:00
parent ff547ed8a5
commit a30acfb82e

View file

@ -126,6 +126,7 @@ class FarmMigrationSubscriber implements EventSubscriberInterface {
public function onMigratePreRowDelete(MigrateRowDeleteEvent $event) {
$this->deleteAssetParentReferences($event);
$this->deleteLogQuantityReferences($event);
$this->deleteTermParentReferences($event);
$this->deletePlantTypeCompanionReferences($event);
}
@ -324,6 +325,28 @@ class FarmMigrationSubscriber implements EventSubscriberInterface {
}
}
/**
* Delete parent references to taxonomy pterms.
*
* @param \Drupal\migrate\Event\MigrateRowDeleteEvent $event
* The row delete event object.
*/
public function deleteTermParentReferences(MigrateRowDeleteEvent $event) {
// If the migration is in the farm_migrate_taxonomy migration group, delete
// all parent references to the destination term.
// This is necessary to prevent entity reference integrity constraint errors
// if an attempt is made to roll back terms that are referenced as parents.
$migration = $event->getMigration();
if (isset($migration->migration_group) && $migration->migration_group == 'farm_migrate_taxonomy') {
$id_values = $event->getDestinationIdValues();
if (!empty($id_values['tid'])) {
$this->database->query('DELETE FROM {taxonomy_term__parent} WHERE parent_target_id = :tid', [':tid' => $id_values['tid']]);
$this->database->query('DELETE FROM {taxonomy_term_revision__parent} WHERE parent_target_id = :tid', [':tid' => $id_values['tid']]);
}
}
}
/**
* Delete companion references to plant type terms.
*