You are here

public function MigrationGroup::delete in Migrate Plus 8.4

Same name and namespace in other branches
  1. 8.5 src/Entity/MigrationGroup.php \Drupal\migrate_plus\Entity\MigrationGroup::delete()
  2. 8 src/Entity/MigrationGroup.php \Drupal\migrate_plus\Entity\MigrationGroup::delete()
  3. 8.2 src/Entity/MigrationGroup.php \Drupal\migrate_plus\Entity\MigrationGroup::delete()
  4. 8.3 src/Entity/MigrationGroup.php \Drupal\migrate_plus\Entity\MigrationGroup::delete()

Deletes an entity permanently.

Throws

\Drupal\Core\Entity\EntityStorageException In case of failures an exception is thrown.

Overrides EntityBase::delete

File

src/Entity/MigrationGroup.php, line 52

Class

MigrationGroup
Defines the Migration Group entity.

Namespace

Drupal\migrate_plus\Entity

Code

public function delete() {

  // Delete all migrations contained in this group.
  $query = \Drupal::entityQuery('migration')
    ->condition('migration_group', $this
    ->id());
  $names = $query
    ->execute();

  // Order the migrations according to their dependencies.

  /** @var MigrationInterface[] $migrations */
  $migrations = \Drupal::entityTypeManager()
    ->getStorage('migration')
    ->loadMultiple($names);

  // Delete in reverse order, so dependencies are never violated.
  $migrations = array_reverse($migrations);
  foreach ($migrations as $migration) {
    $migration
      ->delete();
  }

  // Finally, delete the group itself.
  parent::delete();
}