You are here

public static function MigrationBase::getInstance in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 includes/base.inc \MigrationBase::getInstance()

Return the single instance of the given migration.

Parameters

$machine_name: The unique machine name of the migration to retrieve.

string $class_name: Deprecated - no longer used, class name is retrieved from migrate_status.

array $arguments: Deprecated - no longer used, arguments are retrieved from migrate_status.

Return value

MigrationBase

9 calls to MigrationBase::getInstance()
drush_migrate_messages in ./migrate.drush.inc
Display messages for a migration.
drush_migrate_status in ./migrate.drush.inc
A simplified version of the dashboard page.
MigrateCommentUnitTest::testCommentImport in tests/plugins/destinations/comment.test
MigrateNodeUnitTest::testNodeImport in tests/plugins/destinations/node.test
MigrateXMLUnitTest::testNodeImport in tests/plugins/sources/xml.test

... See full list

File

includes/base.inc, line 621
Defines the base class for migration processes.

Class

MigrationBase
The base class for all objects representing distinct steps in a migration process. Most commonly these will be Migration objects which actually import data from a source into a Drupal destination, but by deriving classes directly from MigrationBase…

Code

public static function getInstance($machine_name, $class_name = NULL, array $arguments = array()) {
  $migrations =& drupal_static(__FUNCTION__, array());

  // Otherwise might miss cache hit on case difference
  $machine_name_key = drupal_strtolower($machine_name);
  if (!isset($migrations[$machine_name_key])) {

    // See if we know about this migration
    $row = db_select('migrate_status', 'ms')
      ->fields('ms', array(
      'class_name',
      'group_name',
      'arguments',
    ))
      ->condition('machine_name', $machine_name)
      ->execute()
      ->fetchObject();
    if ($row) {
      $class_name = $row->class_name;
      $arguments = unserialize($row->arguments);
      $arguments = self::decryptArguments($arguments);
      $arguments['group_name'] = $row->group_name;
    }
    else {

      // Can't find a migration with this name
      self::displayMessage(t('No migration found with machine name !machine', array(
        '!machine' => $machine_name,
      )));
      return NULL;
    }
    $arguments['machine_name'] = $machine_name;
    if (class_exists($class_name)) {
      try {
        $migrations[$machine_name_key] = new $class_name($arguments);
      } catch (Exception $e) {
        self::displayMessage(t('Migration !machine could not be constructed.', array(
          '!machine' => $machine_name,
        )));
        self::displayMessage($e
          ->getMessage());
        return NULL;
      }
    }
    else {
      self::displayMessage(t('No migration class !class found', array(
        '!class' => $class_name,
      )));
      return NULL;
    }
    if (isset($arguments['dependencies'])) {
      $migrations[$machine_name_key]
        ->setHardDependencies($arguments['dependencies']);
    }
    if (isset($arguments['soft_dependencies'])) {
      $migrations[$machine_name_key]
        ->setSoftDependencies($arguments['soft_dependencies']);
    }
  }
  return $migrations[$machine_name_key];
}