You are here

public static function MigrateGroup::groups in Migrate 6.2

Same name and namespace in other branches
  1. 7.2 includes/group.inc \MigrateGroup::groups()
2 calls to MigrateGroup::groups()
drush_migrate_status in ./migrate.drush.inc
A simplified version of the dashboard page.
migrate_migrations in ./migrate.module
Retrieve a list of all active migrations, ordered by dependencies. To be recognized, a class must be non-abstract, and derived from MigrationBase.

File

includes/group.inc, line 35
Definition for a migration group.

Class

MigrateGroup
@file Definition for a migration group.

Code

public static function groups() {
  $groups = array();
  $dependent_groups = array();
  $required_groups = array();
  foreach (self::$groupList as $name => $group) {
    $dependencies = $group
      ->getDependencies();
    if (count($dependencies) > 0) {

      // Set groups with dependencies aside for reordering
      $dependent_groups[$name] = $group;
      $required_groups += $dependencies;
    }
    else {

      // No dependencies, just add
      $groups[$name] = $group;
    }
  }
  $iterations = 0;
  while (count($dependent_groups) > 0) {
    if ($iterations++ > 20) {
      $group_names = implode(',', array_keys($dependent_groups));
      throw new MigrateException(t('Failure to sort migration list - most likely due ' . 'to circular dependencies involving groups !group_names', array(
        '!group_names' => $group_names,
      )));
    }
    foreach ($dependent_groups as $name => $group) {
      $ready = TRUE;

      // Scan all the dependencies for this group and make sure they're all
      // in the final list
      foreach ($group
        ->getDependencies() as $dependency) {
        if (!isset($groups[$dependency])) {
          $ready = FALSE;
          break;
        }
      }
      if ($ready) {

        // Yes they are! Move this group to the final list
        $groups[$name] = $group;
        unset($dependent_groups[$name]);
      }
    }
  }
  return $groups;
}