I'm using working with cck fields, one of them has a to_date. In the field properties is set that it has to be as the value (date_from) if no value is provided fro the user BUT when i do the import with migrate module and i re-edit the nodes to check values imported, i get all value2 (date_to) witn no value set, empty...

Right now i solved with a "bulk operations" view and this php script:
if (!$object->field_date[0]['value2']) $object->field_date[0]['value2']= $object->field_date[0]['value']
node_save($object);

i would like to know id it's a bug, or something i'm doing wrong.

CommentFileSizeAuthor
#4 678524.patch798 bytesstella

Comments

amolinari’s picture

Title: problem with value2 cck date filed (date_to) » problem with value2 cck date field (date_to)
mikeryan’s picture

Project: Migrate » Migrate Extras
Version: 6.x-1.x-dev » master

CCK support has been moved to the migrate_extras module.

nauthiz693’s picture

Version: master » 6.x-1.0-alpha2
Component: Miscellaneous » Migrate Extras Features

This is a bug, as far as I can tell. The bug is in content.migrate.inc on line 164:
$node->$field_name += array($delta => array($column => $value));

The date fields that include a 'to' date are listed as one 'field' in the node - so what this code ends up trying to do is to add two arrays that look like this:

1. array(0 => (value => SOME_VALUE))
2. array(0 => (value2 => SOME_OTHER_VALUE))

With the goal to get an array that looks like this:

array(0 => (value => SOME_VALUE, value2 => SOME_OTHER_VALUE))

But php doesn't let you add arrays like this (at least in a couple a tests I did in PHP 5.2.12 - this might have been written for and work in PHP 5.3, but I don't know).

Anyway, if you replace the code (in content.migrate.inc line 164) with:

$field_columns =& $node->$field_name;
if (is_array($field_columns[$delta])) {
    $field_columns[$delta] += array($column => $value);
} else {
    $field_columns += array($delta => array($column => $value));
}

Alternately, you can implement the method hook_migrate_prepare_node and set the 'to date' there.

Also note, if the 'to date' is required and it doesn't find one (which it won't, because of this bug) migrate won't set the from date properly either.

stella’s picture

Status: Active » Needs review
StatusFileSize
new798 bytes

Here's a patch which implements a similar, but slightly different, solution. Note, this doesn't just affect date fields. For example a CCK textarea field also has the same problem as the 'format' value is never migrated.

stella’s picture

Title: problem with value2 cck date field (date_to) » problem with CCK fields with more than one column
nauthiz693’s picture

Hah, yay. I spent like an hour trying to do it that way, but I didn't know and couldn't figure out the syntax for telling php which variable to apply the array index to (putting the brackets around the variable). Thanks, good thing to learn!

frankcarey’s picture

committed to dev

frankcarey’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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