Commit da39fcff0a649b8fa6110588b055db2f03cee07a (http://drupalcode.org/project/migrate.git/commit/da39fcff0a649b8fa611058...) related to #1896920: Remove auto-registration, and make sure migrations are only registered when explicitly asked broke my use of $this->addFieldMapping('og_group_ref')->defaultValue(1); in conjunction with migrate_d2d. (I want to set the Organic Group for each node I bring in.)

However, doing $this->addFieldMapping('created')->defaultValue(1); continues to work correctly so it appears I am registering properly.

Using a checkout of Migrate at the previous SHA works as I intend with regard to $this->addFieldMapping('og_group_ref')->defaultValue(1);.

So I must not be registering properly. I've tried different variations given at http://drupal.org/node/1824884 with no success.

Code:


/**
 * Implements hook_flush_caches().
 */
function unl_migrate_d2d_flush_caches() { 
  $common_arguments = array(
    'source_version' => 7, 
    'source_connection' => 'for_migration', 
  );

  $arguments = $common_arguments + array(
    'description' => t('Migration of users from source site'),
    'machine_name' => 'User',
  );

  Migration::registerMigration('DrupalUser7Migration', $arguments['machine_name'],
                               $arguments);

  $node_arguments = array(
    array(
      'class_name' => 'BasicPageMigration',
      'description' => t('Migration of basic page nodes'),
      'machine_name' => 'BasicPage',
      'source_type' => 'page',
      'destination_type' => 'page',
    ),
  );

  $common_node_arguments = $common_arguments + array(
    'user_migration' => 'User',
  );
  foreach ($node_arguments as $arguments) {
    $arguments = array_merge_recursive($arguments, $common_node_arguments);
    Migration::registerMigration($arguments['class_name'], $arguments['machine_name'],
                                 $arguments);
  }
}

/**
 * Implements hook_migrate_api().
 */
function unl_migrate_d2d_migrate_api() {
  $api = array(
    'api' => 2,
//     'migrations' => array(
//       'User' => array('class_name' => 'DrupalUser7Migration'),
//       'BasicPage' => array('class_name' => 'BasicPageMigration'),
//     ),
  );
  return $api;
}

abstract class NodeMigration extends DrupalNode7Migration {
  public function __construct(array $arguments) {
    parent::__construct($arguments);

    // Setting the Group does not work
    $this->addFieldMapping('og_group_ref')->defaultValue(1);
    // These do work
    $this->addFieldMapping('created')->defaultValue(865620662);
    $this->addFieldMapping('log')->defaultValue('Created via migration.');
  }
}
 
class BasicPageMigration extends NodeMigration {
  public function __construct(array $arguments) {
    parent::__construct($arguments);
  }
}

Comments

ericras’s picture

Issue summary: View changes

Use proper php code tags

mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

What is the field type of og_group_ref? It seems like the issue is the field handler for that field (whether it's in OG, or entity_reference) is not getting registered.

ericras’s picture

og_group_ref is an Entity Reference

ericras’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)

Thanks @mikeryan for bringing up that it might be an Entity Reference issue.

I upgraded from Entity Reference 1.0 to latest dev because I think you already fixed it: #1845986: Can't migrate to entity reference field

ericras’s picture

Issue summary: View changes

intend typo