I have some nodes on my D6 site that I'd like to migrate to an entity type on my D7 site as they no longer need to be a nodes. I've been trying to find an example somewhere of how this can be done but not had much luck, so any guidance would be appreciated.

Comments

mikeryan’s picture

Project: Migrate » Migrate Extras
Component: Code » Entity API
Status: Active » Postponed (maintainer needs more info)

You need to use migrate_extras, which has a destination handler MigrateDestinationEntityAPI. If you use that for your destination (passing the entity type and bundle you're migrating into), then you can map fields from incoming nodes to the entity fields in the normal way.

marcus178’s picture

Ok thanks seem to have got it working using the following, not sure if my method is the best but it works. Sure there's probably a cleaner way of doing it.

class TicketCountMigrate extends Migration {
  public function __construct() {
    parent::__construct(MigrateGroup::getInstance('TicketCount'));

    // Select fields from the Drupal 6 node ticket count table. 
    $query = Database::getConnection('default', 'legacy')
                        ->select('node', 'n');
     $query->innerJoin('node_revisions', 'nr', 'n.vid=nr.vid');
     $query->leftJoin('content_type_ticket_count', 'f', 'n.vid=f.vid');                    
     $query->fields('n', array('nid','vid','changed'));
     $query->fields('f', array('field_count_plug_value'));
     $query->condition('n.type', 'ticket_count');
     $query->orderBy('changed');


    // Set source and destination.
    $this->source = new MigrateSourceSQL($query);
    $this->destination = new MigrateDestinationEntityAPI(
      'ticket_count',  // Entity type
      'ticket_count'   // bundle
    );
    // Set up database maping.
    $this->map = new MigrateSQLMap($this->machineName,
      array(
        'nid' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'description' => 'D6 Unique Node ID',
          'alias' => 'n',
        )
      ),
      MigrateDestinationNode::getKeySchema()
    );
    
    $this->addFieldMapping('field_count_plug_book', 'field_count_plug_value');
    
  }
}
mikeryan’s picture

Status: Postponed (maintainer needs more info) » Fixed

That looks just right.

Status: Fixed » Closed (fixed)

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