Closed (fixed)
Project:
User Terms
Version:
6.x-1.0-beta3
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
18 Mar 2010 at 20:55 UTC
Updated:
24 Jun 2010 at 10:00 UTC
Jump to comment: Most recent file
Comments
Comment #1
joachim commentedWhen do you get a single value out of it?
I tried going to the admin settings and enabling just one vocabulary, and that variable is still an array, just with only one entry.
Comment #2
kanani commentedExperiencing this behavior as well.
Invalid argument supplied for foreach() in /Users/davidhazel/workspace/pau_git/sites/all/modules/user_terms/user_terms.module on line 181.
If only one vocabulary is selected, $vids is a string when it gets passed to user_terms_view_profile_separated.
One work around is to cast it as an array before running the foreach.
$vids = (array) $vids;
/**
* Show terms on the user's profile by vocabulary.
*/
function user_terms_view_profile_separated(&$account, $vids) {
$terms = $account->user_terms;
$vids = (array) $vids;
foreach ($vids as $vid) {
$term_names = array();
foreach ($terms as $tid => $term) {
if ($term['vid'] == $vid) {
$term_names[] = check_plain($terms[$tid]['name']);
unset($terms[$tid]);
}
}
if (!empty($term_names)) {
$vocab = taxonomy_vocabulary_load($vid);
user_terms_view_profile_item($account, 'user_terms_' . $vid, $vocab->name, $term_names, $vocab->weight);
}
}
}
Another alternative is that in user_terms.admin.inc on line 28
$form['user_terms_vocabs'] = array(
'#type' => 'select',
'#title' => t('User vocabularies'),
'#options' => $options,
'#description' => t('Choose the vocabularies that will be used to tag users. To select multiple values, hold down the Control key while clicking. If you are using an Apple, hold down the Apple or Command key.'),
'#default_value' => variable_get('user_terms_vocabs', ''),
'#multiple' => TRUE,
);
to make sure that it gets saved as an array.
Comment #3
joachim commentedI'm really not able to reproduce this at all, so I'm going to need more information.
Are you using any other modules that might change the user form?
Comment #4
kanani commentedI think it might have to do with a legacy user_terms_vocabs value stored in {variable}.
I did a fresh drupal 6.17 install with just user_terms installed and verified that an array was indeed being returned if only one vocab was selected.
I then completely uninstalled/reinstalled user_terms from my client site, which has quite a few modules installed, and an array was being returned.
I then reverted to a db snapshot taken prior to the uninstall/reinstall and the error came back up again.
To fix, without uninstall/reinstall I just ran a query against the db
and updated the value stored in the {variable} table.
In my case the vocab id was 1 so I replaced
s:1:"1";with
a:1:{i:1;s:1:"1";}Problem solved.
Comment #5
joachim commentedWow that's some good detective work!
I've gone for a look in CVS for that variable in older versions, and this is how it got a bad value:
- version 1.1 of the user_terms.module file (corresponding to beta 1 of this whole module) had only a single vocabulary, and stored a flat number in the variable user_terms_vocabulary.
- the next version of the module file switches to allow multiple vocabs, stored in user_terms_vocabs.
- commit 1.1.2.1 of the .install file does a conversion for users coming from beta 1:
This is the culprit!
The new variable should be an array, and yet it is getting set to a flat value.
I'll write a patch :)
Comment #6
joachim commentedConfirming I can reproduce this bug if I install beta 1 then upgrade.
Here's a patch.
I've tested it by installing beta 1 of this module, and upgrading to the fixed code.
If you're getting this bug, the patch won't help you as you've already run the update function on your database. The simple fix however is to visit your user terms setting page and save the configuration -- that will overwrite the variables with the proper values.
Fixed. Thanks kanani for the debuging work!