In node_convert.module, function node_convert_node_convert, we have the following code, starting on line 620:
foreach ($source_fields as $key => $field) { // Conversion process for each field
$additional_data = node_convert_field_convert($nid, $field, $dest_fields[$key]);
}
if (!empty($additional_data)) {
db_query("UPDATE {node_revisions} SET body = '%s', teaser = '%s' WHERE nid = %d AND vid = %d",
$additional_data['body'], $additional_data['teaser'], $node->nid, $node->vid);
}
So, $additional_data is expected to be an array with the keys "body" and "teaser", containing data from the source node. When I tried converting a set of nodes to Book pages, none of the data from CCK text fields was copied over, and I determined that $additional_data was empty, and so the UPDATE query was never run. $additional_data is empty because in the function node_convert_field_convert, we have this code, starting on line 756:
// A single value
}
elseif (!is_array($values) && !empty($values)) {
if ($dest_field == APPEND_TO_BODY) {
$node_body = $node_body . "\n" . $values;
$node_teaser = $node_teaser . "\n" . $values;
}
elseif ($dest_field == REPLACE_BODY) {
$node_body = $values;
$node_teaser = $values;
}
return; // We return because there's only a single value, and the rest are vid and nid -> unuseful.
}
}
return array('body' => $node_body, 'teaser' => $node_teaser);
This means that if the field contains a single value, we append/replace it to $node_body and $node_teaser, then return to the calling function, since further iterations of the foreach loop will contain nid, vid, etc and we don't care about those. However, by doing this we return nothing and the line:
return array('body' => $node_body, 'teaser' => $node_teaser);
is unreachable. If the field is single-valued, we should break out of the loop and let this line of code execute, not simply return null to the caller.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | node_convert_body.patch | 2.29 KB | krayz |
| #1 | node_convert-1133752-1.patch | 820 bytes | mdm |
Comments
Comment #1
mdm commentedHere is a patch against the 6.x-1.x branch to correct the problem.
Comment #2
krayz commentedin addition to this and in reference to http://drupal.org/node/553974#comment-4182608, i found that depending on field orders the body field may not get set correctly. the attached patch works for me. it makes sure we break instead of return as described above and it sets the body field as soon as $additional_data returns with the desired values.
patch was against 6.x-1.7 version