Preserve nids script add in migrate d2d What is the file name I have to add the following script in it?


  This is actually easy to do. In the prepare() function of the node
  migration class, just set the nid and is_new to true:

public function prepare($node, $row) {
  // Preserve old nid so that old links to nodes using /node/nid still work
  $node-&gt;is_new = TRUE;
  $node-&gt;nid = $row-&gt;nid;
}

  
  Source link:
  How can I preserve nids during a migration?
Unfortunately, sometimes answers on stackexchange are misleading.  It doesn't look like ANY classes within migrate_d2d extend MigrateDestinationEntity, that invokes a "prepare" hook.  So I think the question itself is misguided.

Looking in the migrate code, it looks like any class that extends abstract class MigrateDestinationEntity can call this process function see
/migrate/plugins/destinations/entity.inc,

on line 140:

// Then call any entity-specific handlers
migrate_handler_invoke_all($this-&gt;entityType, 'prepare', $entity, $source_row);


Rather than trying to find a place to call this from DrupalNodeMigration, which will never call this function, what you need to do is add a mapping for nid, and a mapping for "is_new".

In your class that extends the DrupalNodeMigration class, in the __contruct() function, just make sure to add a mapping for nid and is_new.

$this-&gt;addFieldMapping('nid', 'nid');
$this-&gt;addFieldMapping('is_new')-&gt;defaultValue(TRUE);


Otherwise, nid will be automatically assigned.