Well, as part of my personal coding Stalingrad, I was simply trying to insert a new record on behalf of a new user into my plugin's table. Simple 'nuff, I just needed the user's id, and I'd be on my way and the sun would shine, birds would sing and the world would smile on me.
I plugged in the code, registered a new user, my code snagged the object->ident from the listen_for_id call, checked the table, and found... user_id=0.
Uh-oh. Can you take a raincheck on sunshine?
I thought about it, and it came to me. There was nothing wrong with my code, or the database table, or the code to update it. Nor even of the event structure. The problem was...
When you register, receive your email, go back to the site to supply your password and announce you're older than 13, then the 'new' event happens. Then, the 'publish' event happens, if the db insert was successful.
Then the register.php code redirects you to a login page.
My problem, and the likely reason the oversight hadn't raised a ruckus is... my plugin happens whether you're logged in or not. So, it happens when the login page loads. And it catches the user's publish event. But there's no id. Seems the redirect wiped it.
And since nobody is logged in, there is no userid available from session either.
Now, being new with ELGG, I could be completely wrong about this. But I checked out the object, and it didn't have any data, even though plugin caught the event just fine. Can you confirm the issue? And if so, can you consider automatically logging in the new user after confirmation?
I didn't post this as a bug report cause I'm still fairly new at this, though I've been spending lots of time with your code. My less-than-perfect workaround was to query the User table for the max ident.
Summary: Post-registration redirect whacks the user publish event object's data. Workaround would be good, but it may be time to consider automatically logging newly-confirmed registered users to insure user_id is available from the environment.
Paul Wolborsky
'~~~~~~~~~~~~~~~ code snippet /mod/map/lib.php
function map_add_newUser($event_type,$event,$object)
{
$mapUser = new stdClass;
$mapUser->user_id = $object->ident;
$mapUser->owner = $object->ident;
$result = insert_record('_mapusers',$mapUser);
return $object;
}
... from map_init
listen_for_events('user','publish','map_add_newUser');
-- table after code
table 'elgg_mapusers'
ident=4
user_id=0
owner=0
Keywords: event_hooks, ident=0, listen_for_events, mishap, missing user_id, problem, publish, user, user_id=0