2

I have several sites that are being migrated from Drupal 6 to Drupal 7.

However, most of these sites are very small and all have a lot in common (similar content types, fields, views, etc...). So, instead of migrating each site individually, I am migrating the content for all sites into a single site, changing the instances of each D6 site into an Organic Group on the D7 site.

Since the content types are the same (or similar), I'm re-using the same node migration classes (extensions of DrupalNode6Migration in the node.inc file).

I'm passing along the group id in the arguments array to associate the nodes with the D7 Organic Group. However, I'm not sure how to go about doing this.

The code (I believe) for programmatically associating a node with an organic group is this:

og_group('sub_site', $arguments['group_id'], array(
  "entity_type" => 'node',
  "entity" => null, // need current entity 
));

However, I don't believe I have a reference to the created entity within the migration class itself (at least not in the construct() or prepareRow() functions).

You know what? I think I just solved my own problem. I'm going to try using the complete() function, which has access to the finished node, like this:

class myClass extends DrupalNode6Migration{

    public $group_id = '';

    public function __construct($arguments) {
        parent::__construct($arguments);

        // set group id member variable to use in complete() function
        $this->group_id = $arguments['group_id'];

        // mappings and stuff

    }

    public function complete($node, stdClass $row) {
        if (parent::complete($node, $row) === FALSE) {
            return FALSE;
        }

        og_group('sub_site', $this->group_id, array(
            "entity_type" => 'node',
            "entity" => $node, 
        ));
    }
}

Leaving this here in case it helps somebody else.

I can't test this yet, unfortunately. When I do, I'll try to remember this post to let people know how it worked out.

Your Answer

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

Browse other questions tagged or ask your own question.