I'm having a heck of a time trying to set the "updated" field of an entity. I thought it would just be a matter of a field mapping and converting to a Unix timestamp:

In my migration class:
$this->addFieldMapping('updated', 'DATEMOD');

In my prepareRow():
$current_row->DATEMOD = strtotime($current_row->DATEMOD);

If I dsm the entity in the prepare() function, it's showing the timestamp in the "updated" field but a timestamp of the current date/date is what gets saved to the database. Am I missing something?

Thanks,
Mickey

Comments

mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

It depends on how that particular entity handles its 'updated' field. I would bet that (like nodes with the 'changed' field) it's got the timestamp hard-coded:

   $node->changed = REQUEST_TIME;

If that's the case, you'll need to write it out yourself after the entity is saved:

public function complete($entity, $row) {
  $entity->updated = strtotime($row->DATEMOD);
  entity_save($entity);
}
mikeryan’s picture

Status: Postponed (maintainer needs more info) » Fixed

No further info provided.

micnap’s picture

Sorry, haven't gotten back to this. It's on the agenda for the next week.

Thanks,
Mickey

Canadaka’s picture

I cannot figure out how to get the updated time of the nodes being migrated to not be set my time() but instead use the value from my source.

tried this but doesn't work, still gets current time.

public function complete($entity, $row) {
    $entity->updated = $row->posterTime;
    $entity->changed = $row->posterTime;
    entity_save('node', $entity);
  }
micnap’s picture

Finally got back to this...

The suggested solution didn't work for me either but it put me on the right track. My entity was overriding the date on entity_save so I just did a db_update query in the complete function.

public function complete($entity, $row) {
    db_update('redhen_contact')
    ->fields(array(
      'updated' => $row->DATEMOD,
    ))
    ->condition('contact_id', $entity->contact_id, '=')
    ->execute();
}

Thank you!
Mickey

Status: Fixed » Closed (fixed)

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