1

I am trying to follow the guidance from https://www.drupal.org/node/1819738 "Extending migrate_d2d classes". I am using the Migrate d2d UI. It brings back the nodes I want to migrate, but there are a couple of fields I need to add. Essentially I want to extend the DrupalNode6Migration class to add these fields to the source query used by the UI.

I created this class (which appears to be exactly like the example given in the d2d document above):

<?php
class CadeMigrateFields extends DrupalNode6Migration {

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

  protected function query() {
    // Get the default query 
    $query = parent::query();

    // Get OG stuff as per: https://www.drupal.org/node/2033293#comment-9371471

    $query->leftJoin('og_ancestry','oga','n.nid = oga.nid');
    $query->addExpression('GROUP_CONCAT(DISTINCT og.group_nid)', 'og_group_ref');       

    $query->addField('oga', 'group_nid', 'gid');
    $query->addField('oga', 'is_public', 'is_public');

    return $query;
  }
}
?>

This is supposed to include the additinal fields I want in the parent query. I added the path to this file to my module.info file:

; Migrate from 6.x to 7.x
files[] = cade_fields.migrate.inc

My question is: How do I declare it in the Migrate api so that Migrate sees it and executes it correctly?

If I don't add it anywhere in the api, Migrate doesn't see it. It is ignored and doesn't work.

If I code it as a migration,

   $migrations = array();

   $migrations['CadeFields'] = array(
        'class_name' => 'CadeMigrateFields',
   );

  $api = array(
    'api' => 2,
    'migrations' => $migrations,
   );


  return $api;

I get errors saying that several arguments (source type, description, destination type, etct) are missing. And it still doesn't work. This missing information should be provided by the arguments passed to the parent query (created by DrupalNode6Migration) by the UI, whose query I am simply trying to extend, not override.

So, how do I declare this type of class so that:

  1. Migrate (d2d) sees it?
  2. Migrate passes the arguments from the parent class (created by UI) it is extending to it?
  3. It extends the parent class query to include the desired fields?

Thanks so much for any assistance!

2 Answers 2

2

Change your code like and try

 $migrations['CadeFields'] = array(
  'class_name' => 'CadeMigrateFields',
  'description' => t('Give your description abt this migration'),
  'source_type' => 'GIVE THE DRUPAL 6 NODE TYPE YOU ARE MIGRATING',
  'destination_type' => 'GIVE THE DRUPAL 7 NODE TYPE',
 );
3
  • Adding the above code results in a new migration group being created in the Migrate d2d UI called "default". It requires that I additionally add source_version and destination_version to $migrations. Yes, the query now includes the original DrupalNode6Migration query plus my additions, but I now have to create a CadeMigrateFields class for every content type I wish to migrate. The d2d UI has already mapped my 6->7 content types and all I want to do is add these additional fields to that node query. Is that possible without hacking migrate_d2d node.inc file (DrupalNode6Migration). Apr 17, 2015 at 16:57
  • As far as I know, you can't hook into d2d UI query. But the above mentioned way you need not create separate class for each content type, you can use the same class for the all the content type.
    – msmani
    Apr 17, 2015 at 19:36
  • Got it. Thanks. Can you point me where I can find documentation on how to code to use one class to migrate multiple content types? Apr 18, 2015 at 0:04
0

I answered my own question here: https://www.drupal.org/node/2471863#comment-9840131

What I wanted:

I run migrate d2d ui and save settings. I go to dashboard, click on group, get a list migration tasks. I click on a listed node task, then click on "Source" for that node migration. I see a query.

I need two fields added to this query. So, I figure I can use "Extending migrate_d2d classes" code to "extend" this query so that the next time I run this migration, go to the dashboard, locate the same node task and look at it's source, the two fields I need will be included in the query and available to map.

To me, and I suspect to others, that is what "Extending migrate d2d classes" means.

The way it works:

You have to create a new migration class. Just follow existing documentation on how this is done. If you want to use, for example, the node query from the DrupalNode6Migration class, then you create the class with

<?php
 class MyNewClass extends DrupalNode6Migration class 
?>

Then, you insert into your MyNewClass:

<?php
  protected function query() {
    // Get the default query 
    $query = parent::query();
    ...
   }
?>

Now, you can "extend" this query to be used in your new Migration class, which now should also appear in the Migration dashboard -- but in a different migration group from that created by the migrate_d2d ui.

It would be nice if there was a way to pass the arguments dynamically generated in the migrate_d2d ui and pop them into our "extending" class. Then we'd really be "extending" as opposed to re-creating.

But, that's a question for another day.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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