I have several fields that should be left empty (NULL in SQL). But the module writes a zero in every field that is left empty. How could I avoid this?

Thank you in advance!

Comments

wflorian’s picture

Priority: Normal » Critical

I guess it has something to do with the following lines of code in node_import/supported/cck/content.inc:

      // Force a node value for missing data.
        if (empty($node->$dummy_name)) {
          $values = array(0 => $globals['fields'][$dummy_name]);
        }
        else {
          // Explode multiple values to create the $delta and $value for each.
          if ($field['multiple']) {
            $values = explode('||', $node->$dummy_name);
          }
          else {
            $values = array(0 => $node->$dummy_name);
          }
        }
        $value = ((!empty($field['widget']['default_value'][0]['value'])) ?  $field['widget']['default_value'][0]['value'] : '');

What to edit, so that there will be a NULL value when there is no entry in the csv...?

wflorian’s picture

Nobody any idea? It is actually really urgent.

The problem seems to occur only with cck created decimal fields.

I already tried so much with no efforts. I am actually not good enough for writing own php code..

I would be really thankful for any ideas and hints...

Florian.

Robrecht Jacques’s picture

Status: Active » Postponed (maintainer needs more info)

There is a problem with node_import and empty values. Empty values are considered not present.

In your case it seems that the code converts an empty string to a 0. This is probably because of

            case 'number_integer':
              // Make sure numeric data is brought in as numeric values.
              $value = intval($value);
              break;

            case 'number_decimal':
              $value = floatval($value);
              break;

in supported/cck/content.inc.

Could you try if replacing the code above with:

            case 'number_integer':
              // Make sure numeric data is brought in as numeric values.
              if (strlen($value) > 0) {
                $value = intval($value);
              }
              break;

            case 'number_decimal':
              if (strlen($value) > 0) {
                $value = floatval($value);
              }
              break;

But: because node_import assumes empty strings are "special" (non-mapped values), there might be other places where the conversion takes place unknowingly.

Please test and get back.

BTW: please test with node_import-5.x-1.7 release earlier today.

wflorian’s picture

Hey Jacques,

you made my day!!

Thank you, thank you, thank you! :D

Your code suggestions worked absolutely fine! Thanks a lot, again!

Greetings from Germany.

Florian

Robrecht Jacques’s picture

Version: 5.x-1.6 » 5.x-1.7
Component: Miscellaneous » Code
Category: support » bug
Status: Postponed (maintainer needs more info) » Needs review
Robrecht Jacques’s picture

Status: Needs review » Fixed

Committed. Will be included in the next release of node_import (5.x-1.8) release later this weekend.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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