Invalid argument supplied for foreach() in taxonomy_xml.module on line 378.; Incorrect Count of Terms Updated
| Project: | Taxonomy import/export via XML |
| Version: | 6.x-1.2 |
| Component: | Code |
| Category: | bug report |
| Priority: | minor |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
When you import a new vocabulary from an XML (possibly other) file, you get the following error:
warning: Invalid argument supplied for foreach() in /home/d6/public_html/sites/all/modules/contrib/taxonomy_xml/taxonomy_xml.module on line 378.
If you re-import the same XML file with the same data you get the error:
Failed to import any new terms. This may be due to syntax or formattings errors in the import file.
<?php
368 // Conditionally include and invoke the appropriate format library
369 $incfile = dirname(drupal_get_filename('module', 'taxonomy_xml')) .'/'. $form_values['format'] .'.inc';
370 include_once($incfile);
371 $format_name = preg_replace('/_format$/', '', $form_values['format']);
372 $funcname = "taxonomy_xml_${format_name}_parse";
373 if ( function_exists($funcname) ) {
374 $modified_terms = $funcname($text, $vid, $form_values['url']);
375
376 if(!empty($modified_terms )) {
377 $term_list = array();
378 foreach ($modified_terms as $list_term) {
379 $term_list[] = l($list_term->name, 'admin/content/taxonomy/edit/term/'. $list_term->tid);
380 }
?>If the submission form was set to XML the function called would be taxonomy_xml_xml_parse and the return vaue for that is the total number of elements in the array--not an array, so that's why the foreach errors. The second message is just the "else" part of the condition also failing. It also results in an incorrect count of terms updated.
There are also some other problems... even if the array was returned instead of the number of items in the array the code goes on to reference the returned item as an object...
I would be glad to help clean up some of the code in the module. I sent you an email via your Drupal contact form....

#1
(issue queue cleanup)
There was a period when the API was being rewritten where it used to return an int count, and now returns an actual array of results. Some of the support libraries hadn't been updated to the new API, this probably led to the inconsistency in -dev.
This has been reviewed, and the result summary messages (That's all that section is) are all now generated quite differently.
I think this doesn't apply to current 6.2-dev code. Haven't been able to replicate anyway.
#2
Automatically closed -- issue fixed for 2 weeks with no activity.