I'm new to Migrate, and am trying to set up a migration closely based on the example advanced migration (Wine). The Wine migration has two migration classes (abstract class AdvancedExampleMigration and class WinePrepMigration) that call the parent constructor like so:

parent::__construct(MigrateGroup::getInstance('wine', array('default')));

This seems to work fine in the example, but when I duplicate the code in my own module, and visit /admin/content/migrate, I get the following error message:

MigrateException: Failure to sort migration list - most likely due to circular dependencies involving groups wine in MigrateGroup::groups() (line 55 of /srv/www/pixelscrapper/public_html/sites/all/modules/contrib/migrate/includes/group.inc).

The error goes away when I remove the arguments from the second constructor, and replace it simply with "parent::__construct();"

I'm a bit baffled why this code is running okay in the example, but not when I copy it exactly to my own module?

Here's the code I have in my custom module's inc file, that is throwing the error (copied directly from Wine.inc, have only changed the class names):

abstract class AssetMigration extends Migration {
  public $basicFormat;

  public function __construct() {
    // TIP: Migrations can be organized into groups. In this case, all the migrations
    // derived from AdvancedExampleMigration will be part of the 'wine' group.
    // This enables us to easily run just the wine example migrations:
    //  drush migrate-import --group=wine
    // The second argument to MigrateGroup::getInstance is an array of groups
    // which should come before this when viewing migration statuses, or running
    // migration operations using --all. Since the beer migrations in this module
    // did not specify a group, it is in the 'default' group, so this constructor
    // indicates that the wine migrations come after the beer migrations.
    parent::__construct(MigrateGroup::getInstance('wine', array('default')));

    $this->team = array(
      new MigrateTeamMember('Jack Kramer', 'jkramer@example.com', t('Taster')),
      new MigrateTeamMember('Linda Madison', 'lmadison@example.com', t('Winemaker')),
    );
    $this->issuePattern = 'http://drupal.org/node/:id:';

    // A format of our own, for testing migration of formats
    $this->basicFormat = filter_format_load('migrate_example');
  }
}

/**
 * TIP: While usually you'll create true migrations - processes that copy data
 * from some source into Drupal - you can also define processing steps for either
 * the import or rollback stages that take other actions. In this case, we want
 * to disable auto_nodetitle while the migration steps run.
 */
class AssetPrepMigration extends MigrationBase {
  // Remember whether the auto_nodetitle was originally enabled, so we know whether
  // to re-enable it
  public static $wasEnabled = FALSE;

  public function __construct() {
    // Because we're derived directly from migrationBase rather than AdvancedExampleMigration,
    // we must specify the group again here.
    parent::__construct(MigrateGroup::getInstance('wine', array('default')));
    $this->description = t('If auto_nodetitle is present, disable it for the duration');
  }
  // Define isComplete(), returning a boolean, to indicate whether dependent
  // migrations may proceed
  public function isComplete() {
    // If Auto Node Title is disabled, other migrations are free to go
    if (module_exists('auto_nodetitle')) {
      return FALSE;
    }
    else {
      return TRUE;
    }
  }
  // Implement any action you want to occur during an import process in an
  // import() method (alternatively, if you have an action which you want to
  // run during rollbacks, define a rollback() method).
  public function import() {
    if (module_exists('auto_nodetitle')) {
      self::$wasEnabled = TRUE;
      module_disable(array('auto_nodetitle'));
      $this->showMessage(t('Disabled auto_nodetitle module'), 'success');
    }
    else {
      self::$wasEnabled = FALSE;
      $this->showMessage(t('Auto_nodetitle is already disabled'), 'success');
    }
    // Must return one of the MigrationBase RESULT constants
    return MigrationBase::RESULT_COMPLETED;
  }
}

Any help is appreciated!

Comments

drewish’s picture

Status: Active » Fixed

I think the problem is with the array('default') you're passing. It lets you specify group dependencies. Putting your group after another, in this case default. If you don't have any migrations in the default group you'll run into problems. Just remove it.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

sinasalek’s picture

Thanks @drewish , that helped

prathK’s picture

Thanks drewish it worked for me too. It is not necessary to specify group when we migrate.