Closed (fixed)
Project:
Signup
Version:
5.x-2.4
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
12 Mar 2008 at 21:54 UTC
Updated:
15 Aug 2008 at 04:22 UTC
Jump to comment: Most recent file
When a user who is deleted from the list of users. The record of events that user has signed up for should also be deleted. Am I wrong in thinking this. In doing some testing I created 2 users, signed both up for an event then deleted 1 of the users. The signup administrations shows that 2 people have signed up for the event but only shows the one user who is still in the system. The record in the {signup_log} table in the DB should be deleted because that user who is deleted really isn't signed up. Plus if limit the number of signups that is just a wasted space.
Please let me know. Thank you,
~ Tom Cocca
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 233512_signup_hook_user.5x-2.11.patch | 2.52 KB | dww |
| #11 | 233512_signup_hook_user.5x-1.11.patch | 1.63 KB | dww |
| #10 | 233512_signup_hook_user.10.patch | 3.2 KB | dww |
| #7 | 233512_signup_hook_user.patch | 1.36 KB | dww |
Comments
Comment #1
dwwSure, sounds reasonable. Feel free to provide a patch.
Comment #2
tcocca commentedI have no problem writing the patch code but how does the signup hook into the user system. Would there need to be some kind of trigger when the user is deleted or would it be better to do the check on the Signup administration page. Do the check on the log and users table before the page loads.
~ Tom
Comment #3
dwwhttp://api.drupal.org/api/function/hook_user/5
Comment #4
tcocca commentedI think I have the solution. I have tested for both ways to delete a user, deleting multiple users at a time from the Admin->User managemt->Users page as well as deleting a single user from the User Account->Edit page.
here is the function I wrote that uses the hook_user():
Please let me know what you guys think and if the code can be cleaned up at all that would be great. Also, I don't know how to create .patch files if somebody could show me how than I can submit this as a .patch.
Thanks,
~ Tom Cocca
Comment #5
dwwThanks, that's a good start.
However, that's not going to handle cases where events were closed due to the signup limit, you deleted some users, and now the events have available space again. Signups for the event will still be marked as closed, even though the limit is no longer reached. Plus, there's a "hook_signup_cancel" that should be invoked whenever a signup is canceled, in case other modules need to know about it. All of this would be solved if you invoked signup_cancel_signup() for each uid/nid pair, instead of directly deleting from {signup_log}. So, basically, instead of deleting form {signup_log}, you need to
"SELECT nid FROM {signup_log} WHERE uid = %d", $uiditerate over the results, and invoke signup_cancel_signup() each time, passing in the uid.Also, the way you're constructing that query opens you up to a (granted, obscure/rare) chance of SQL injection. You're not using the db_query() placeholders correctly. However, it doesn't really matter, since your new patch shouldn't be doing the same thing with the IN (%s) anymore, but it'd be good for you to know for the future. See http://drupal.org/writing-secure-code for more.
Finally, see http://drupal.org/patch for info on creating and submitting .patch files.
Comment #6
tcocca commentedThanks for the feedback, I have modified my function, here is the update. Don't have time to figure out the patch file thing run now as I am unfortunately coding on a windows laptop.
Thanks for th safe coding link as well, realized what I was doing wrong with the implode on the placeholder. Each element has to be surrounded by '' even if it is an int? Anyway here is the new function:
Comment #7
dwwCool. Yeah, that's closer. However, a few code style problems:
A)
if(is_array(...we always put a space between the if and the (, like so:if (is_array(...B) Your 'delete' case in the switch has no 'break;', which doesn't technically matter since it's the only case now, but it's good style for defensive programming.
C) You duplicate a bunch of code just to handle the array vs. single case. It'd be better to always treat it like an array (see attached patch).
So, I just coded this all up and am attaching it as a patch. If you can, please test this and let me know if it works for you.
Cheers,
-Derek
p.s. No, the point about the db_query() placeholders is not that you want ' marks around ints. It's that you were using %s to escape something that wasn't a DB string. The user-supplied data was an int, so you want to use %d to escape that as an int (actually, cast the value in php to an int, which is what happens when you use %d)...
Comment #8
tcocca commentedThanks for creating the patch file. I was trying to figure out a way to re-use the statement that calls singup_cancel_signup but didn't have any great ideas. I like yours though.
Also, I'll know from now on to include a space after an if or else if or a foreach. Is this not the case with a while?
Also the break after the case is good practice.
Anyway I tested your patch and it works the exact same. Thanks for your help on this little issue.
~ Tom
Comment #9
dwwThanks to starbow testing this (I'm over at his house right now for some signup hacking), we discovered that this is broken if you don't use views, since signup_no_views.inc has a hook_user() implementation for the 'view' op. This needs a little love... stay tuned.
Comment #10
dwwLike so. Tested in the views case. How about no views? ;)
Comment #11
dwwNope, still broken. ;) Here's the final patch, along with a patch for DRUPAL-5.
Comment #12
starbow commentedLooks good to me.
Comment #13
dwwYay, committed to HEAD and DRUPAL-5. Thanks!
Comment #14
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.