1

I'm using the migrate module and Drupal 7 to update existing node content, much of which was not migrated. System of record is set to DESTINATION.

Everything works fine, but I'm having some trouble preserving the "changed" timestamp in Drupal, which I'd rather not update.

As explained here, the problem is that node_save() always updates this value, so the challenge is where in the migrate framework to (1) save the existing value and (2) restore the value?

Saving is pretty easy in prepareRow:

  function prepareRow($row) {
    $row->last_changed = node_last_changed($row->Nid);
    drush_print_r($row);
  }

Restoring the value is trickier. I was thinking I could use prepare, but that seems to be too early, and the value is reset to current time when the node is saved.

For the moment, I am using a hack in the complete method like this:

  public function complete($entity, stdClass $row) {
    db_update('node')
      ->fields(array('changed' => $row->last_changed))
      ->condition('nid', $row->Nid)
      ->execute();
  }

Complete fires after the node is saved, so this does work.

I believe hook_node_presave () would also work, but it seems awkward since it doesn't run in the context of the migration.

Is there a better way to do this?

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.