Hi all,

Using a guide by Unibia.net (http://tinyurl.com/moah3b), I succesfully imported data from a CSV file into nodes with CCK fields. The first record always goes correct. Unfortunately, all the following records always go wrong. The problem is that it adds extra taxonomy terms to the following nodes, which happens even while I do not even touch functions like taxonomy_node_save() etc.

For the source code, see paragraph '1. Source code for the import' below. With init(), I bootstrap the whole Drupal Enviroment. With createNode(), I create a company node, fill it with the data and save it using drupal_execute(). I used both Ubibia.net and the documentation on drupal_execute as example (http://api.drupal.org/api/drupal/includes--form.inc/function/drupal_exec...).

The first node after importing is correct. The taxonomy terms look like as shown in paragraph '2. Normal node without taxonomy terms' below. However, for all others, the taxonomy terms consist of extreme amounts of data, see paragraph '3. Normal node with abnormal taxonomy terms' below.

Possible causes + what I already tried

  • It saves information in the super-globals (like $GLOBAL, $_POST, etc.). To try if this is the case, I emptied all these super-globals before continuing. However, the problem still occurred.
  • It might be the data I imported. However, I tried with different kinds of data in different orders.
  • I uninstalled the hierarchical_select module, and yes it is fixed. However, I really need this module.

Question:

How can I solve the problem without un-installing the hierarchical_select module?

1. Source code for the import

<?
###
# Create node from our own array of values
###
function createNode($company){
###
# Build new company content object with default values 
###
	$new_company_node = array('type' => 'company');
	$values = array();
	$form_state = array();
	global $user;
	$values['status'] = 1;
	$values['uid'] = $user->uid;
	$values['name'] = $user->name;
	$values['body'] = "";
	$values['op'] = t('Save');

###
# Build new Company content object with our own values 
###
	$values['title'] = $company['4'];
	$values['field_company_website'][0] = array('url' => 'http://' . $company['2'], 'title' => '', 'attributes' => array());
	$values['field_record_source'][0] = array('value'=> $company['27']);
	$values['field_general_phone_number'][0] = array('value'=> $company['15']);
	$values['field_general_fax_number'][0] = array('value'=> $company['16']);
	$values['field_email'][0] = array('email'=> $company['17']);
	$values['field_company_summary'][0] = array('value'=> $company['17']);
	$form_state['values'] = $values;

###
# Save the node
###
	$result = drupal_execute('company_node_form', $form_state, (object)$new_company_node);
	$errors = form_get_errors();
	if(is_array($errors)){
		return $errors;
	} else {
		$nid = $form_state['nid'];
		return $nid;
	}
}

###
# Bootstrap Drupal 6.x enviroment
###
function init(){
	require_once('./includes/bootstrap.inc');
	drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
	module_load_include('inc', 'node', 'node.pages');
	global $user;
	$user = user_load(array(uid => 3));
}
?>

<?
###
# Bootstrap Drupal
###
init();

###
# Walk through all the data. Each company variable contains an array with key-valye pairs.
###
foreach ($companies as $company){
	$nid = createCompany($company);	
}
?>

2. Normal node without taxonomy terms

taxonomy terms: - Array
(
    [7] => Array
        (
        )
    [6] => Array
        (
        )
    [2] => Array
        (
        )
    [9] => Array
        (
        )
    [12] => Array
        (
        )
)

3. Normal node with abnormal taxonomy terms

    [7] => Array
        (
            [hsid] => 14
            [hierarchy] => stdClass Object
                (
                    [lineage] => Array
                        (
                            [0] => none
                        )

                    [levels] => Array
                        (
                            [0] => Array
                                (
                                    [none] => 
                                    [190] => Accounting and Taxes
                                    [211] => Business Intelligence / Data Warehousing
                                    [218] => Business Planning / Continuity
 .....
                                    [526] => Statistics and Mathematics
                                    [527] => Transportation and Logistics & Inventory Management
                                )

                        )

                    [childinfo] => Array
                        (
                            [0] => Array
                                (
                                    [190] => 20
                                    [211] => 6
                                    [218] => 5
......
                                    [510] => 15
                                    [526] => 0
                                    [527] => 14
                                )

                        )

                    [build_time] => Array
                        (
                            [total] => 62.275
                            [lineage] => 1.671
                            [levels] => 1.676
                            [childinfo] => 58.92
                        )

                )

            [hierarchical_select] => Array
                (
                    [selects] => Array
                        (
                            [0] => none
                        )

                    [dropbox_add] => Add
                )

            [dropbox] => Array
                (
                    [visible] => Array
                        (
                            [title] => All selected applications
                            [separator] => ›
                            [is_empty] => 1
                        )

                )

            [nojs] => Array
                (
                    [update_button] => Update
                )

        )
.....