You are here

function migrate_migrations in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 migrate.module \migrate_migrations()

Retrieve a list of all active migrations, ordered by dependencies. To be recognized, a class must be non-abstract, and derived from MigrationBase.

Parameters

$reset: If TRUE, the static cache of migrations will be flushed before attempting to reinstantiate all active migrations. This can be important for script runs where migration classes may be dynamically registered.

Return value

Array of migration objects, keyed by the machine name.

11 calls to migrate_migrations()
drush_migrate_get_migrations in ./migrate.drush.inc
drush_migrate_migrations in ./migrate.drush.inc
drush_migrate_status in ./migrate.drush.inc
A simplified version of the dashboard page.
MigrateUIWizard::formPerformImport in migrate_ui/migrate_ui.wizard.inc
Run the import process for the migration group we've defined.
migrate_ui_edit_mappings in migrate_ui/migrate_ui.pages.inc
Page callback to edit field mappings for a given migration.

... See full list

File

./migrate.module, line 55
API and drush commands to support migration of data from external sources into a Drupal installation.

Code

function migrate_migrations($reset = NULL) {
  static $migrations = array();
  if (!empty($migrations) && empty($reset)) {
    return $migrations;
  }

  // Get list of modules implementing Migrate API - mainly, we're looking to
  // make sure any dynamic migrations defined in hook_migrate_api() get registered.
  migrate_get_module_apis(TRUE);
  $dependencies_list = array();
  $dependent_migrations = array();
  $required_migrations = array();
  $result = db_select('migrate_status', 'ms')
    ->fields('ms', array(
    'machine_name',
    'class_name',
  ))
    ->execute();
  foreach ($result as $row) {
    if (class_exists($row->class_name)) {
      $reflect = new ReflectionClass($row->class_name);
      if (!$reflect
        ->isAbstract() && $reflect
        ->isSubclassOf('MigrationBase')) {
        $migration = MigrationBase::getInstance($row->machine_name);
        if ($migration) {
          $dependencies = $migration
            ->getDependencies();
          $dependencies_list[$row->machine_name] = $dependencies;
          if (count($dependencies) > 0) {

            // Set classes with dependencies aside for reordering
            $dependent_migrations[$row->machine_name] = $migration;
            $required_migrations += $dependencies;
          }
          else {

            // No dependencies, just add
            $migrations[$row->machine_name] = $migration;
          }
        }
      }
      else {
        MigrationBase::displayMessage(t('Class !class is no longer a valid concrete migration class', array(
          '!class' => $row->class_name,
        )));
      }
    }
    else {
      MigrationBase::displayMessage(t('Class !class could not be found', array(
        '!class' => $row->class_name,
      )));
    }
  }
  $ordered_migrations = migrate_order_dependencies($dependencies_list);
  foreach ($ordered_migrations as $name) {
    if (!isset($migrations[$name])) {
      $migrations[$name] = $dependent_migrations[$name];
    }
  }

  // The migrations are now ordered according to their own dependencies - now order
  // them by group
  $groups = MigrateGroup::groups();

  // Seed the final list by properly-ordered groups.
  $final_migrations = array();
  foreach ($groups as $name => $group) {
    $final_migrations[$name] = array();
  }

  // Fill in the grouped list.
  foreach ($migrations as $machine_name => $migration) {
    if (!method_exists($migration, 'getGroup')) {
      MigrationBase::displayMessage(t('Migration !machine_name is not a valid Migration dependency.', array(
        '!machine_name' => $machine_name,
      )));
    }
    else {
      $final_migrations[$migration
        ->getGroup()
        ->getName()][$machine_name] = $migration;
    }
  }

  // Flatten the grouped list.
  $migrations = array();
  foreach ($final_migrations as $group_name => $group_migrations) {
    foreach ($group_migrations as $machine_name => $migration) {
      $migrations[$machine_name] = $migration;
    }
  }
  return $migrations;
}