I have created a migration class for importing node data, but get the following error when I map data to the $node->changed field:
SQLSTATE[01000]: Warning: 1264 Out of range value for column 'changed' at row 1
Following the BeerMigration Example, I am successfully mapping timestamp data to the 'created', 'access', and 'login' fields for Users by formatting the fields using the prepare() method, but in node.inc, it looks like the 'changed' field is being stored in a local variable, then the prepare() method is being called, so my formatting is not being used when the 'changed' field is being updated after the node is saved:
// Save changed timestamp and set it later, node_save sets it unconditionally
if (isset($node->changed)) {
$changed = MigrationBase::timestamp($node->changed); // STEP 1: $changed value is not formatted
}
....
// Invoke migration prepare handlers
$this->prepare($node, $row); // STEP 2: $node->changed is formatted by my prepare() method
....
node_save($node);
....
if (isset($changed)) { //STEP 3: $changed is set but not formatted by prepare(), so SQL bombs :(
db_update('node')
->fields(array('changed' => $changed))
->condition('nid', $node->nid)
->execute();
$node->changed = $changed;
}
I think this problem could be fixed rearranging the sequence:
- call $this->prepare() to allow formatting
- put $node->changed to a separate variable
- save $node to DB
- check if $changed has been set, and if so, update node
Thanks!
Comments
Comment #1
moshe weitzman commentedNot so sure about changing the order as suggested. Some prepare handlers might expect a fixed up date already. So, I suggest you do your munging in the newish prepareRow($row) hook. You munge there before any importing of that row has begun.
Comment #2
clemens.tolboomFWIW I ran into similar problem. I needed changed === created
Unfortunately node_save does
I suspect this is not fixed yet. Looking at migrate/plugins/destination/node.inc does calculate a $changed but is misty to me still.
Old XREF:
Listed in node.inc #722688: Allow programmatic setting of node->changed
#322759: Allow hook_node_presave() to alter other node fields
Comment #3
clemens.tolboomI've created #1901898: Changed timestamp is not imported though node.inc