mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
Issue #3189740 by m.stenta: Cannot rollback farm_migrate_asset_parent group migrations
This commit is contained in:
parent
14bb01e681
commit
f3ec44d43e
|
@ -51,18 +51,12 @@ Follow the steps below to migrate your farmOS 1.x data to farmOS 2.x:
|
|||
drush migrate:import --group=farm_migrate_taxonomy
|
||||
drush migrate:import --group=farm_migrate_asset
|
||||
drush migrate:import --group=farm_migrate_area
|
||||
drush migrate:import --group=farm_migrate_asset_parent
|
||||
drush migrate:import --group=farm_migrate_sensor_data
|
||||
drush migrate:import --group=farm_migrate_quantity
|
||||
drush migrate:import --group=farm_migrate_log
|
||||
drush migrate:import --group=farm_migrate_plan
|
||||
|
||||
7. Confirm that all the above migrations were successful before running the
|
||||
final migration, which focuses only on populating the "Parents" field of
|
||||
assets. This migration cannot be rolled back (see
|
||||
[Issue #3189740](https://www.drupal.org/project/farm/issues/3189740)):
|
||||
|
||||
drush migrate:import --group=farm_migrate_asset_parent
|
||||
|
||||
To view the status of all farmOS 1.x migrations:
|
||||
|
||||
drush migrate:status --tag="farmOS 1.x"
|
||||
|
|
|
@ -114,6 +114,7 @@ class FarmMigrationSubscriber implements EventSubscriberInterface {
|
|||
* The row delete event object.
|
||||
*/
|
||||
public function onMigratePreRowDelete(MigrateRowDeleteEvent $event) {
|
||||
$this->deleteAssetParentReferences($event);
|
||||
$this->deleteLogQuantityReferences($event);
|
||||
}
|
||||
|
||||
|
@ -278,4 +279,30 @@ class FarmMigrationSubscriber implements EventSubscriberInterface {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete parent references from assets.
|
||||
*
|
||||
* @param \Drupal\migrate\Event\MigrateRowDeleteEvent $event
|
||||
* The row delete event object.
|
||||
*/
|
||||
public function deleteAssetParentReferences(MigrateRowDeleteEvent $event) {
|
||||
|
||||
// If the migration is in the farm_migrate_asset or farm_migrate_area
|
||||
// migration groups, delete all parent references to the destination asset.
|
||||
// This is necessary because the field is populated by migrations in the
|
||||
// farm_migrate_asset_parent group, which ONLY set the parent field on
|
||||
// existing assets, and rolling back those migrations does not remove the
|
||||
// parent references. This causes entity reference integrity constraint
|
||||
// errors if an attempt is made to roll back assets that are referenced as
|
||||
// parents.
|
||||
$migration = $event->getMigration();
|
||||
if (isset($migration->migration_group) && in_array($migration->migration_group, ['farm_migrate_asset', 'farm_migrate_area'])) {
|
||||
$id_values = $event->getDestinationIdValues();
|
||||
if (!empty($id_values['id'])) {
|
||||
$this->database->query('DELETE FROM {asset__parent} WHERE parent_target_id = :id', [':id' => $id_values['id']]);
|
||||
$this->database->query('DELETE FROM {asset_revision__parent} WHERE parent_target_id = :id', [':id' => $id_values['id']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue