I have a node migration and I am not mapping the created field. On my initial import the created field defaults to the time of the migration which is what I would expect. If I update a source record and run the import again it updates my record and changes both the created field and the changed field to the time the import was ran. Shouldn't it only update the changed field and leave the created field to the original value since it was just updating an existing record not creating a new one? Not sure if this is as designed or if this is a bug.

Comments

mikeryan’s picture

Issue summary: View changes
Status: Active » Fixed

This is how it works because the default system-of-record for the migration is the source. That is, each time an item is reimported, the entire destination-side copy of it is replaced as if the item were being imported for the first time - no changes made on the destination side are preserved (otherwise, you would have an amalgam of source-side data and destination-side data).

What you can do to preserve select fields is to (if the item has been previously imported) explicitly load the destination-side data you want to keep and map it. E.g., map your 'created' field from 'custom_created', and in prepareRow if the destid1 field is set in $row, query the existing created value and set it in $row->custom_created.

Status: Fixed » Closed (fixed)

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

fonant’s picture

I have a migration that wants to both import new items and update previously-imported ones. I use the --update flag to migrate-import to do this. I can't use DESTINATION system-of-record because that won't import new items.

Here's another method that prevents Migrate from changing the created date on existing nodes:

/**
 * Implements hook_node_presave().
 */
function MYMODULE_node_presave($node) {
  // We don't want to change the "created" date.
  if (isset($node->original)) {
    $node->created = $node->original->created;
  }
}
ranavaibhav’s picture

Hard to understand as technically if the entity is being "updated" the Updated On field should have the date/time information of the migration and not the Post Date.

Could someone help understand how exact to use code in #3

Thanks