As title, I add some code to node_import/supported/cck/content.inc ...
notice: it only supports the "Allowed values list" like:
value1
value2
value3
don't support the "Allowed values list" like:
key1|value1
key2|value2
key3|value3
Find :
// Unset the dummy column value.
unset($node->$dummy_name);
in the function content_node_import_prepare (P.S. near end of function)
Add:
$option_type = array('options_select' => true, 'options_onoff' => true, 'options_buttons' => true);
if (isset($option_type[$field['widget']['type']])) {
$keys = array();
foreach($node->$field_name as $value_list) {
$keys[] = $value_list['value'];
}
if ($field['multiple'] || $field['widget']['type'] == 'options_onoff') {
$node->$field_name += array('keys' => $keys);
} else {
$node->$field_name += array('key' => reset($keys));
}
}
// Unset the dummy column value.
unset($node->$dummy_name);
now, please test it~
Comments
Comment #1
tokimeki commentedI am sorry to select wrong status.
It must be "patch (code needs review)".
Comment #2
danielb commentedThank you so much, you deserve a gold star.
I made a patch using your code.
Comment #3
kirikintha commentedWicked cool! Thanks so much!
Comment #4
asak commentedI can confirm this works like a charm.
Thank you, thank you - Thank you!
Comment #5
m4manas commentedThis works great!!
Comment #6
bshensky commentedThe patch has certainly helped... but...
We have several fields in the form that are normally presented as a set of radio buttons with allowable values ( NULL, 0, 1 ).
[ ] N/A => maps to null data in the database
[ ] No => maps to a database value of "0"
[ ] Yes => maps to a database value of "1"
It looks like this patch allows us to successfully import all radio button data where the data value in the imported file is "1", but if the imported file data is "0", this patch still reports the data in the database as NULL, rather than an integer value of "0".
Can anyone assist in a patch to the patch?
Comment #7
DanielJohnston commentedSubscribing. Works fine for me so far.
Comment #8
v1nce commentedRadio button fields now import correctly where default value is set to 1.
Comment #9
v1nce commentedUpdating status to account for #6 above.
Comment #10
Robrecht Jacques commentedPartially fixed. Will be included in next release of node_import (5.x-1.8) released this weekend.
If I understand #6 well, you have created a list of allowed values of
? Is this "Text" or "Integer" btw?
The problem is that this first value is an empty string and the empty string is handled by node_import as "there is no value present"... In this case the code tries to find a default value somewhere, eg from the options screen of the wizard. I probably should check if "" (empty string) is an allowed value before discarting it as not present. I will have a closer look at this.
Keeping this a "code needs work" because of #6, but if you don't use a empty (or NULL) value in the allowed values list, the code in node_import-5.x-1.8 (released this weekend) should work. Except maybe that node_import should also check if the value is the *value* of the "key|value" pair instead of assuming it is the key. Also, we could do some validation if the value is not in the allowed value list.
Comment #11
Robrecht Jacques commentedNow empty values (such as in #6, #10) will work too by fixing #321753 : Empty fields get a "0", but should get SQL-"NULL"-data. How to avoid this?. Will be included in next release of node_import (5.x-1.8) released later this weekend.
I still need to add the validation part of #10. So keeping it as active and changed the title.
Comment #12
bshensky commentedRobrecht:
Thanks for your involvement in this issue...
The field in question is defined as an "Integer", BTW... int(11) in the database, Integer in the app.
Those "null" integers will bite ya in the behind, eh?
-Brian
Comment #13
bshensky commentedBump!
Any chance we might be able to use and abuse 5.x-1.8? Tell me where to send the beer.
Thanks,
Brian
Comment #14
Robrecht Jacques commentedNow "Allowed values" validation has been fixed by fixing http://drupal.org/node/168919. So setting this issue as fixed.
The next node_import version (5.x-1.8) will be released within the hour. Thanks all!
Comment #15
bshensky commentedWe've loaded 5.x-1.8, and so a big THANK YOU for all the bug fixes. #10 continued to be an issue for us, however, because of the list of allowable values:
Our flat file was supplying zero ("0"), one ("1"), or an empty string ("") as input to node_import.
The file node_import/supported/cck/content.inc led us to line 193. Turns out that PHP's loose typing was wreaking havoc on the $allowed_keys hash, primarily because our allowable values were evaluating as integers throughout, and this probably had an ill effect on the strtolower() call:
Our fix was to add one line that cast $key as a string:
After doing this, our options_buttons values were correctly registered.
Hope this helps...
-Brian
Comment #16
Robrecht Jacques commentedThe "patch" of comment #15 has been added and will be included in the next release of node_import (5.x-1.9 - release date: probably around november 11th).