Invalid Argument
9dots - December 31, 2008 - 15:03
| Project: | autocategorise |
| Version: | 6.x-1.3 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
Seem to be getting an error when multiple categories / terms can apply to a post. Only one term is associated with the content and an error message is displayed at the top of the page after submission.
Error message is as follows :
warning: Invalid argument supplied for foreach() in ...../sites/all/modules/autocategorise/auto_categorise.module on line 121.

#1
#2
Hi,
If the module has been updated after fixing this problem. I am still getting this error.
#3
#4
This is occurring because on line 121 the module tries to run a foreach on the array of tids in a vocab. If there aren't any tids added yet then this breaks the code. There should probably be a check on the tid array before calling the _apply_terms_to_node function.
We should change this code on line 113:
$terms=get_synonyms($vid);foreach ($nodes as $node){
$misc[] =_apply_terms_to_node($node, $terms, $catch_all, $multiple=0);
}
To this:
$terms = get_synonyms($vid);if (!empty($terms)) {
foreach ($nodes as $node){
$misc[] = _apply_terms_to_node($node, $terms, $catch_all, $multiple=0);
}
}
And this code on line 70:
$terms=get_synonyms($result->vid);$vocab= taxonomy_vocabulary_load($result->vid);
$multiple=$vocab->multiple;
$misc=_apply_terms_to_node($node, $terms, $catch_all, $multiple);
To this:
$terms = get_synonyms($result->vid);$vocab = taxonomy_vocabulary_load($result->vid);
$multiple = $vocab->multiple;
if (!empty($terms)) {
$misc = _apply_terms_to_node($node, $terms, $catch_all, $multiple);
}
Otherwise you will get errors when the foreach tries to run on an empty array.
#5
I have a bunch of terms added under the vocabulary . But it just adds one terms (alphabetically heaviest term). If i put a check if the terms are empty i don't get the errors but no terms are added (not even one).
#6
ok i figured out the problem, even if you have a term but no synonym associated with it, then the problem arises. Add synonyms to the terms and it works. Problem lies in the query under get_synonym function, "WHERE vid = %d AND s.name IS NOT NULL" where s.name are for synonyms, and not all terms have synonyms necessarily.
#7
Yes, I have a patch for that issue that I posted at this page http://drupal.org/node/356506 and it points to the same solution you mentioned. We should probably keep these issues separate though so that it doesn't get marked as a duplicate.
#8
Hi,
For the benefit of those who may come across this problem.
You get this error under these two cases:
1) If no terms are defined
2) If no synonyms are defined
Both of these result in an empty array hence the error.
To solve this problem put a check for the empty array as mentioned in comment #4 by Aaron and then apply the patch posted here http://drupal.org/node/356506 (posted by Aaron).
OR
if you don't want to apply these patch and want to wait till the next official release of the module with these bugs fixed, define a bunch of terms and assign a synonym to all the defined terms (you can find the option for declaring a synonym while you add/edit a term under Advanced section, it remains collapsed by default)
With this i take the liberty to mark this thread closed.
Thanks Aaron.
--Cheers
#9
Automatically closed -- issue fixed for two weeks with no activity.
#10
A bug report should be set as fixed if the maintainer has committed the fixed code in CVS, not when somebody fixes his own copy of the module.
#11
I am still seeing the OP error message in 6.x-1.3 when adding a node.
#12
#13
Automatically closed -- issue fixed for 2 weeks with no activity.