1

I have created migrations for most of my D6 site to a new D7 site. In the D6 site I have users with profile nodes. Those profile nodes are linked to another type of node via node reference. In D7 the other node will be an organic group.

I would like to be able to transfer the node reference relationship in D6 to organic group membership in D7. Has anyone done this?

Thanks in advance for any help given.

0

I ended up using the advanced method as described in the semi-official documentation (https://drupal.org/node/2023273). It all came down to modifying the query to get the nid and new group nid.

class MemberCompanyMembershipMigration extends DrupalMigration {
    /**
     * Construct a migration.
     *
     * @param array $args
     *   Constructor arguments passed at migration-registration time.
     */
    public function __construct($args) {

        parent::__construct($args);


        // Set the fields we want; document in the UI.

        $this->sourceFields += array(
                'nid' => t('Group node ID.'),
                'is_active' => t('User status in the group.'),
                'is_admin' => t('Group admin or not.'),
                'uid' => t('User ID.'),
        );
        $this->sourceOptions['map_joinable'] = FALSE;
        // Set the query as the migration source.
        $this->source = new MigrateSourceSQL(
                $this->query(), $this->sourceFields, NULL, $this->sourceOptions
        );
        // Map source rows to destination rows with uid+gid.
        $this->map = new MigrateSQLMap($this->machineName,
                array(
                        'field_contact_member_company_nid' => array(
                                'type' => 'int',
                                'not null' => TRUE,
                                'description' => 'ID of the group.',
                        ),
                        'uid' => array(
                                'type' => 'int',
                                'not null' => TRUE,
                                'description' => 'ID of the user.',
                        ),
                ),
                MigrateDestinationOGMembership::getKeySchema()
        );
        // Destination is group membership.
        $this->destination = new MigrateDestinationOGMembership();
        // Field mappings.
        $this->addFieldMapping('group_type')
        ->defaultValue('node');
        $this->addFieldMapping('entity_type')
        ->defaultValue('user');
        // Let the user migration map the uids.
        $this->addFieldMapping('etid', 'uid')
        ->sourceMigration('ClickUser');
        $this->addFieldMapping('state', 'is_active');
        $this->addFieldMapping('is_admin', 'is_admin');
        // Group migration maps the gid via the OG Node migration.
        $this->addFieldMapping('gid', 'field_contact_member_company_nid')
        ->sourceMigration('MemberCompany');
        // Minimal source config means we just set a default
        // instead of looking for roles to map.
        $this->addFieldMapping('group_roles')
        ->defaultValue(array(OG_ADMINISTRATOR_ROLE));
        // Accept defaults for these destination fields.
        $no_input = array(
                'created',
        );
        $this->addUnmigratedDestinations($no_input, t('Do Not Migrate'));
    }
    /**
     * Query for the source group data.
     *
     * @return QueryConditionInterface
     *   Provides a connection and query for getting OGMembership records.
     */
    protected function query() {
        $query = Database::getConnection('click2', $this->sourceConnection)
        ->select('content_type_contact_content','p')
        ->fields('p', array('field_contact_member_company_nid'));
        $query->join('node','n','n.vid = p.vid');
        $query->addField('n', 'uid');
        $query->isNotNull('field_contact_member_company_nid');
        return $query;
    }
    public function prepareRow($row) {
        if (parent::prepareRow($row) === FALSE) {
            return FALSE;
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.