I configured legal module. when logging in with a user that never accepted the agreement, it displayed the agreement and i checked the box and clicked submit. I got this (changed the paths to generic names):
Warning: array_keys(): The first argument should be an array in /home/domain/modules/user.module on line 352
Warning: implode(): Bad arguments. in /home/domain/modules/user.module on line 352
Warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 query: SELECT DISTINCT(p.perm) FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN () in /home/domain/includes/database.mysql.inc on line 120
Warning: Cannot modify header information - headers already sent by (output started at /home/domain/modules/user.module:352) in /home/domain/includes/common.inc on line 266
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | accountload.patch | 570 bytes | budda |
| #11 | legal.module.diff.txt | 819 bytes | drumm |
Comments
Comment #1
webchickWe're seeing this here too on PHP 5.1 and MySQL 5. Investigating further...
Comment #2
robert castelo commentedMmmmh, tried to replicate the bug but couldnt.
1. Created a new user 'test1', logged in as test1.
2. Installed legal.module
3. Created T&C
4. T&C now shows up in test1 account, 'accepted' not checked
5. Logged out.
6. Logged in as test1, presented with T&C
7. Accept T&C, log in completely successful.
MySQL 4.1, PHP 4.4.1
I wonder if it could be a problem with MySQL 5 or maybe it's another module.
I get a similar message when I log out and devel.module is enabled.
Try switching devel.module off if you have it enabled.
whatistocome are you running Drupal 4.7.2?
I think user.module line 352 is probably line 349 on current version?
Comment #3
whatistocome commentedYep, 4.7.2
Comment #4
webchickHm. I also was unable to duplicate this on a clean install. Sigh. :P Time for process of elimination I guess. :P
Comment #5
robert castelo commentedwhatistocome what version of MySQL and PHP are you running?
One thing that's I don't understand....
Warning: array_keys(): The first argument should be an array in /home/domain/modules/user.module on line 352
Looking at line 352 in user.module
array_keys is used on line 349, is this the line where the problem is actually occuring?
In which case $account->roles not being an array would trigger the error.
Now to work out why that might be happening.....
Comment #6
webchickRegarding user roles, bear in mind that a somewhat last-minute change to 4.7 before it was released was to remove role 1 and 2 from the user roles array; now, only "extra" roles are stored there; if a user's not logged in, it's implied that they are in role 1, and if they are, it's implied that they're role 2.
Comment #7
robert castelo commentedI can't replicate this, so difficult for me to fix.
Does anyone have an install where this is a problem?
If so I can try and create a solution which you can test out.
Comment #8
advosuzi commentedThis set of errors appears for me ONLY when a user has registered prior to terms being set.
(user is old, legal module added after they registered)
At next login they must accept terms and this is when the mysql errors pop up.
New registrations are fine.
Comment #9
advosuzi commentedhit submit too soon - i'll investigate further but can test any fixes on my beta site.
Comment #10
plumbley commentedI don't follow all of this, but I wonder if its something to do with the simulated logout/login sequence that legal uses? E.g. in function legal_login_submit, line 571 of legal.module 4.7.x (v 1.12.2.2 2006/07/16 11:59:40) we have
while in user.module something similar-ish happens in user_load (lines 64-81):
So it looks like legal.module doesn't load any roles in this sequence. It may be that if any modules have a hook_user() that responds to type "login" by trying to check access on anything, that will call user_access() with the current global $user with $user->roles not set, so user_access() will barf.
This is pure guess mind, since I don't really follow what legal.module does.
As an aside...
user_access() currently assumes that $user->roles is an array (except for uid 1). Maybe it should protect itself against bugs in other modules by checking it really is first? It could be as simple as changing lines 349+ in user.module from
to
or even
which has the advantage of not generating Notices either if roles is not set. Anyway, at least this might prevent the nasty SQL error (and probably just give a user with no permissions until the next page load) while looking for what's not setting $user->roles properly.
Comment #11
drummThis patch corrects the user loading which is causing these issues. Users should always be loaded via user_load() to avoid the problems reported above and others.
Comment #12
robert castelo commentedThanks Neil, patch commited to 4.7 branch in CVS.
Can anyone who previously experienced this problem try out the new version and confirm the bug has been fixed.
I'm marking this as 'fixed', but will wait for confirmation before closing the issue.
Comment #13
fool2 commentedI'm not sure if this is related, but I'm getting all the same errors on a test site running the latest version of this module. I tried both the 4.7 and CVS versions (which seem to be identical anyway)
A couple of things: We're using logintoboggan, I don't think there are any collisions but there might be something with the logins?
Also, my uid=1 superadmin account is NOT affected by this bug. All other accounts are (including admin accounts that have all perms)
Anyway, I'm following the code all the way through; I'll check back if I find anything.
Comment #14
robert castelo commentedRe-opening issue.
Comment #15
fool2 commentedFound it!
Line 383:
$account in hook_user is passed by reference. This means this call tainted the $account variable further down the line when it is used later in the code, generating our error.
The solution is to rename this variable- I have done so and the module works great after that, but I'm not sure what naming should actually be used so I'll leave that up to the pros.
This took me 3 hours to figure out but it was worth it.
Comment #16
buddaFool2: thanks for spending 3 hours of your life so I don't have to. Your fix regarding the $account variable was spot on and resolved my issue here too!
Before the fix the site would simply crash on anybody (except uid 1) logging in - showing the same MySQL error as mentioned in an earlier post.
Comment #17
robert castelo commentedYeah, thanks Fool2, much appreciated.
I'll test it out at the weekend and commit it.
I'm not experiencing this bug, so I can't check if it fixes the problem (there seems to be consensus that it does), so if it doesn't cause any harm I'll happily commit it.
Comment #18
buddaAttached patch to resolve the problem. I changed the $account variable to $u. Thought I'd do it whilst I was rollin a patch for the other bug in legal.module
Comment #19
fool2 commentedIf only some people are experiencing the bug it must be a conflict with another module, either optional or contributed. I'm not sure what, though, since the code is supposed to exit with the goto() and that variable should be destroyed
Comment #20
m3avrck commentedConfirmed, this patch fixes my setup as well. I did some digging for a while, couldn't figure out what was conflicting and why this might work in some cases.
Regardless, renaming the variable makes sense. I'm not even sure how this *could* work with it the same name. :-p
Comment #21
kiz_0987 commentedI was having exactly the same issue with old users who had not signed an updated agreement. The patch fixed this for me and seems to have no other issues. Any chance of committing this?
Comment #22
robert castelo commentedThanks for the feedback.
Yes, I'll commit it as soon as I have time.
Comment #23
robert castelo commentedPatched the cvs version.
I'll patch the 4.7 version tomorrow if there's no complaints.
Comment #24
robert castelo commentedPatch commited to 4.7
Comment #25
(not verified) commented