Hello,
I've recently noticed this issue with my User Badges module. I'm using latest dev version and yesterday, new errors started to occur. I think it may be because of upgrade of Privatemsg module to dev version. I upgraded DB by running update.php but there were some table errors, so I downgraded it again. I've noticed few errors on msg page right after that. Though, I've removed it completly, but still, following errors occur on certain pages, this time in admin after adding a role to user:
key_exists() [<a href='function.key-exists'>function.key-exists</a>]: The second argument should be either an array or an object in file /data/b/l/bloosha.com/web/sites/all/modules/user_badges/user_badges.module on line 272
Second error I've noticed occurs after I set count limit for user badges:
Invalid argument supplied for foreach() in file /data/b/l/bloosha.com/web/sites/all/modules/user_badges/user_badges.module on line 215
I found, on these lines, there is always piece of code:
$account->badges_all
Maybe it's somehow broken for me? Maybe it's because I'm inserting manually values into user_roles table? I would be really thankful for any kind of help.
My version of UB: http://drupal.org/node/336964
Hope we'll figure it out :)
Numline1
Comment | File | Size | Author |
---|---|---|---|
#29 | user_badges-foreach-error-964546.patch | 2.16 KB | mstef |
#28 | user_badges-foreach-error-964546.patch | 2.12 KB | mstef |
#27 | user_badges-foreach-error-964546.patch | 1.8 KB | mstef |
Comments
Comment #1
NancyDruI cannot predict what will happen if you downgrade. Please re-upgrade and explain what the error is that you are reporting.
Comment #2
jweedman CreditAttribution: jweedman commentedI just installed the 6.x-1.6 version of User_Badges, and i get the following error immediately after enabling the module:
"warning: Invalid argument supplied for foreach() in /path_to_directory/modules/user_badges/user_badges.module on line 215."
Line 215: foreach ($account->badges_all as $bid => $badge) { ....
Any suggestions?
Comment #3
NancyDruHmm, I also enabled it on a new site today and it was okay. I'll do some more checking.
Comment #4
Numline1 CreditAttribution: Numline1 commentedNancyDru: Of course, it's not possible to catch everything after downgrade, but as I mentioned in the post above, it was completely uninstalled (via Drupal uninst) and new dev version was used after. You say, there was no error in your case, but have you tried to set # limit for badges to list? I may it for you on my beta site and I'll let you know. Hope we'll figure it out.
Now I'm using stable version of module and there are no errors for me.
Comment #5
Numline1 CreditAttribution: Numline1 commentedTesting done. No error occured right after install, though, error appeared after setting "Number of badges to display" to 10. Error:
Tested on new / fresh Drupal 6.19
Comment #6
jweedman CreditAttribution: jweedman commentedStrange - the error came when I had "Number of badges to display" to 1.
I had to hack the module on line 215 from
to
Probably not the safest fix, but I couldn't bear seeing the error on EVERY admin page. Please let me know if there is a safer / 'cleaner' fix. Cheers...
Comment #7
NeoID CreditAttribution: NeoID commentedSame errors, subscribing
Comment #8
darkdimsubscribing
I have error:
warning: key_exists() [function.key-exists]: The second argument should be either an array or an object in /usr/local/www/data/magadmin/data/www/magnolia-tv.com/sites/all/modules/user_badges/user_badges.module on line 244.
Comment #9
danneb CreditAttribution: danneb commentedsubscribing, guess ive got the same problem
warning: Invalid argument supplied for foreach() in /var/www/forum/modules/user_badges/user_badges.module on line 215.
Comment #10
Miria CreditAttribution: Miria commentedSubscribing.
6.x-1.6:
warning: Invalid argument supplied for foreach() in /. . ./sites/all/modules/user_badges/user_badges.module on line 215.
warning: key_exists() [function.key-exists]: The second argument should be either an array or an object in /. . ./sites/all/modules/user_badges/user_badges.module on line 244.
Comment #11
NancyDruCan someone with this problem do this for me, please:
At line 758 you will find:
Immediately following that, add:
Comment #12
Numline1 CreditAttribution: Numline1 commentedNancyDru: That fixed it, thx. You should update it in dev branch.
Comment #13
NancyDruI will do so later today.
Comment #14
venusrising CreditAttribution: venusrising commentedI rolled it back to prior stable as it is on a production site and the rollback code works with Author Pane and I did not see the duplicate badges anymore. Hope this helps.
Comment #15
venusrising CreditAttribution: venusrising commentedI am happy to test this fix on the dev site but was wondering if this code will also fix the Author Pane issue? if there is code to try for both I am happy to do it, if so please post all possible code bits to test and I am happy to do several tests.
Comment #16
Matt V. CreditAttribution: Matt V. commentedThe change in comment #11 above fixed the issue for me. Thanks!
Comment #17
NancyDru@venusrising: what is the author pane issue/
Comment #18
NancyDruFix from #11 committed to 6.x-1.x-dev.
Comment #19
venusrising CreditAttribution: venusrising commentedIn authorpane shows all badges at once even if only one is selected
Comment #20
venusrising CreditAttribution: venusrising commentedThis worked on dev site
Comment #21
venusrising CreditAttribution: venusrising commentedthis still does not address the authorpane issue, is there new code being used?
Comment #22
venusrising CreditAttribution: venusrising commentedchecking back in. I used the fix in #11 on a dev site and it fixes the issue. However the authorpane module still has issues where it shows all badges, does anyone know if there is any fix for this too? may be time to use a different solution other than authorpane as User Relationships new build has issues with it too now.
Comment #23
NancyDruThere is an issue on Authorpane, please use that for discussion of that issue.
Comment #25
mstef CreditAttribution: mstef commentedLooks like this still is an issue...
I'll make a patch
Comment #26
mstef CreditAttribution: mstef commentedI also noticed some unnecessary logic right before the foreach() which pertains to the variable limit that should be removed as well..
Comment #27
mstef CreditAttribution: mstef commentedPatch!
Comment #28
mstef CreditAttribution: mstef commentedBetter patch..
Comment #29
mstef CreditAttribution: mstef commentedLast fix. Was misusing the static cache which was causing some problems.
Patch attached
Comment #30
NancyDruCommitted to 6.x-1.x-dev (rolls out at Noon GMT). I have still not been able to recreate the issue, so I need some testers.
Comment #32
boftx CreditAttribution: boftx commentedI just encountered the same problem after setting the max number of badges to display. After reading this thread, and setting max back to 0, the problem went away.
This was on a new install of current release on D6. I can re-create at will just by setting a limit or removing it.
Comment #33
boftx CreditAttribution: boftx commentedI just changed from 6-1.6 to the latest dev version. I no longer get error msgs displayed when setting the limit to anything other than 0, but I see all role badges displayed in the AF author pane even when set to 1. It appears that they are not being limited by the count.
Comment #34
tyrusmanuel CreditAttribution: tyrusmanuel commentedAfter changing to the dev version I still get the following "warning: key_exists() [function.key-exists]: The first argument should be either a string or an integer in C:\xampp\htdocs\coax\modules\user_badges\user_badges.module on line 244." But I no longer get the earlier error from line 215.
I changed my badges to show to "0" and still get the error. Any help, I may have to remove the module and lose functionality rather than spend more time on something that is aesthetic or a nice to have.
Thanks.
Comment #35
NancyDruComment #36
venusrising CreditAttribution: venusrising commentedIs there a way someone can have a look at http://drupal.org/node/1223968#comment-4839570
Invalid argument supplied for foreach() sites/all/modules/user_badges/user_badges.module on line 215.
Think this might be related to the this issue. We have patched the module for the user badges all issue but we see the above error in the DB logs. Someone said the patch fixed it for them but no us however.
Comment #37
jsidigital CreditAttribution: jsidigital commentedOkay, i got the 215 error fixed.
However, i still cannot find a fix for the 248 error.
warning: key_exists() [function.key-exists]: The second argument should be either an array or an object in /home/jsi/public_html/sites/all/modules/user_badges/user_badges.module on line 248.
Anyone else seeing this after a registration? Do we even know what is causing it?
Comment #38
manuj_78 CreditAttribution: manuj_78 commentedthis is still an issue, can you please have a look at fixing this
Comment #39
NancyDruI'm very busy at the moment and also trying to get a D7 version at least half-way working as I'm learning Git.
Comment #40
ajfabb CreditAttribution: ajfabb commentedAfter upgrading a bunch of modules I hit this.
A added the patch on #11 and error message went away, but now I notice all my author panes (which include the badges) are missing. That could be unrelated I guess.
Comment #41
Media Crumb CreditAttribution: Media Crumb commentedI'm now getting even if I set the number to 0. None of the roles seem to work anymore. I'm using the latest Dev branch
Is there any fix to this? It's cause my site to apply the wrong badges to my roles!
Comment #42
dunx CreditAttribution: dunx commentedOkay, I have a solution. I think the cause is changes to PHP5.3 no longer accessing PHP objects as it used to using key_exists. Also worth noting that key_exists itself is deprecated.
I also removed the second array key check in both loops. It's no big deal - the two called functions cater for when the user already has/hasn't got the role.
At line 268 in user_badges.module (v1.6 not -dev), replace the two foreach loops with the following:
Not sure why the second loop doesn't consider $success or $message, but left that as is.
The drupal_set_message also now include the badge name as expected.
Comment #43
philalonso CreditAttribution: philalonso commentedThanks, Jeremy. Your fix worked for me.
Comment #44
shabana.navas CreditAttribution: shabana.navas commentedFixed in Version 7. Please upgrade to Version 7.x-3.x.
Comment #44.0
shabana.navas CreditAttribution: shabana.navas commentedCopied from forum