0

The process of registration is taking way too long (22 secs) so I've been profiling the plugin execution to see what is happening. My registration process is something I do with a custom component (for mobile registration). I've also got a couple of plugins that are fired with onUserAfterSave and a third custom plugin. So I though the problem was with my plugins but they seem pretty quick. What is slow is the time between and the fact that my plugins are called twice. This is the execution flow:

2014-05-06T18:39:50+00:00 INFO - mobileregister..START Joomla save

2014-05-06T18:39:56+00:00 INFO - Start of onUserAfterSave in RegRedirect 2014-05-06T18:39:56+00:00 INFO
2014-05-06T18:40:02+00:00 INFO - Start of onUserAfterSave in RegRedirect 2014-05-06T18:40:02+00:00 INFO
- End of onUserAfterSave in RegRedirect

2014-05-06T18:40:02+00:00 INFO - ResetToken START - onUserAfterSave 2014-05-06T18:40:02+00:00 INFO -
ResetToken END - onUserAfterSave

2014-05-06T18:40:11+00:00 INFO - ResetToken START - onUserAfterSave 2014-05-06T18:40:11+00:00 INFO -
ResetToken END - onUserAfterSave

2014-05-06T18:40:12+00:00 INFO - mobileregister..END Joomla save

My plugins RegRedirect and ResetToken are being called twice (not SetLimits). The time between that is several seconds. Any ideas on what I can do to figure out what is going on?

EDIT:

I have a bit more clues of what is going on. It seems the code to add a user to a group triggers all the onUserAfterSave events again. This is the code I have in RegRedirect.

JUserHelper::addUserToGroup($user['id'], $service_provider["usergroup_id"]);

Is there any way to avoid this?

  • Are you sure you have two events running? For example it would appear that in your supplied info there is only 1 end End of onUserAfterSave in RegRedirect so I'm wondering if it's more something odd with your log dumps? – George Wilson May 7 '14 at 10:05
  • @GeorgeWilson Not 100% sure but I don't see anything wrong with the logging. It is odd that there is only 1 End of onUserAfterSave in RegRedirect. You can also see that there are 2 ResetToken plugins called as well. Very confused... – Tom May 7 '14 at 10:59
  • Can you not add the correct usergroup when creating the user? – George Wilson May 7 '14 at 14:51
  • @GeorgeWilson What do you mean? That's what I'm doing. I'm adding a user to the correct usergroup. The problem is that using addUserToGroup then launches all the onUserAfterSave events again. Makes sense but it is duplicating things. Seems like a good practice is to never use addUserToGroup in onUserAfterSave. I need to figure out how to add a user to a group during registration without addUserToGroup. – Tom May 7 '14 at 14:56
  • Ahh okay right this makes more sense now if you're adding the user to group in the plugin. I would advise doing a cursory check on the user to see if he's new. If so abort in the plugin early. I don't think you can really avoid running the plugin twice – George Wilson May 7 '14 at 22:35
2

Well, I've found one solution. This works for my mobile registration but won't work for typical registration. I wonder how many people realize that this call:

JUserHelper::addUserToGroup($user_id, $group_id);

will execute the onUserAfterSave event again. I've seen numerous posts with this recommendation. In terms of registration this is not what you want. But Joomla is not at fault here. It correctly recognizes you are changing the user by adding them to a group so it triggers the onUserAfterSave.

To get around this for my mobile registration I basically just do what the current registration component does:

$user = JFactory::getUser(0);
jimport('joomla.application.component.helper');
$usersParams = &JComponentHelper::getParams( 'com_users' );
$userdata = array();
//pull in other user data during registration...        
$defaultUserGroup = $usersParams->get('new_usertype', 2);
//here you need to add your usergroup id
$userdata['groups']=array($defaultUserGroup, $usergroup_id);

A different way to do the same thing. Works for me and has made my registration almost twice as fast. Web registration is also a problem but I haven't found a way around that (I don't have the usergroup id available like I do in mobile registration).

0

Make sure that you wrap your code around if (!$isNew) { ... }

The first call to public function onUserAfterSave($data, $isNew, $result, $error) {} will set $isNew to true but the second call that sets the group will set it to false.

And when it is set to false, that means that the account is most likely settled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.