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

tokimeki’s picture

Status: Reviewed & tested by the community » Needs review

I am sorry to select wrong status.
It must be "patch (code needs review)".

danielb’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new876 bytes

Thank you so much, you deserve a gold star.

I made a patch using your code.

kirikintha’s picture

Wicked cool! Thanks so much!

asak’s picture

I can confirm this works like a charm.

Thank you, thank you - Thank you!

m4manas’s picture

This works great!!

bshensky’s picture

The 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?

DanielJohnston’s picture

Subscribing. Works fine for me so far.

v1nce’s picture

Radio button fields now import correctly where default value is set to 1.

v1nce’s picture

Status: Reviewed & tested by the community » Needs work

Updating status to account for #6 above.

Robrecht Jacques’s picture

Partially 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

|N/A
0|Off
1|On

? 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.

Robrecht Jacques’s picture

Title: Import text field with option widget (select list, checkbox, radio) » Option widget "allowed values" validation
Version: 5.x-1.6 » 5.x-1.7
Status: Needs work » Active

Now 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.

bshensky’s picture

Robrecht:

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

bshensky’s picture

Bump!

Any chance we might be able to use and abuse 5.x-1.8? Tell me where to send the beer.

Thanks,
Brian

Robrecht Jacques’s picture

Status: Active » Fixed

Now "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!

bshensky’s picture

We'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:

|N/A
0|Off
1|On

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:

            foreach ($allowed_values as $key => $value) {
              $allowed_keys[strtolower($key)] = $key;
              $allowed_keys[strtolower($value)] = $key;
            }

Our fix was to add one line that cast $key as a string:

            foreach ($allowed_values as $key => $value) {
              $key = (string) $key; // <--- CAST $key AS A STRING, SO $allowed_keys REMAINS a HASH
              $allowed_keys[strtolower($key)] = $key;
              $allowed_keys[strtolower($value)] = $key;
            }

After doing this, our options_buttons values were correctly registered.

Hope this helps...

-Brian

Robrecht Jacques’s picture

The "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).

Status: Fixed » Closed (fixed)

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