Skip to Content Skip to Menu

🌲 Merry Christmas! Great savings on Professional and Developer Memberships! Get 25% off now with code XMAS-2024!

onUserAfterSave joomla event is triggered twice

  • zederis
  • zederis
  • OFFLINE
  • Posts: 9
  • Thanks: 2
  • Karma: 1
8 months 21 hours ago #337965 by zederis
Hi, I am trying to use onUserAfterSave joomla event:
Code:
public function onUserAfterSave($user, $isnew, $success, $msg): void     {         if($isnew === true)         {             //new user created         }         else         {             //existing user updated         }     }


but when Community Builder is installed, after new user registration, onUserAfterSave event is triggered twice and I get a 'new user created' and right after that - 'existing user updated'. It happens only on user registration.
Is it possible to avoid this double triggering?

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48622
  • Thanks: 8302
  • Karma: 1446
8 months 3 hours ago #337967 by krileon
That's normal. We have to create the user in order to use their user id in other processes, which may trigger an update. There is no avoiding this. Why is this causing a problem for your plugin? No plugin should be dependent on an event only firing once and if it is it should have at minimum static caching implemented to account for that.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • zederis
  • zederis
  • OFFLINE
  • Posts: 9
  • Thanks: 2
  • Karma: 1
7 months 4 weeks ago #337974 by zederis
It causes problem because upon user creation I cannot distinguish is it a new user creation or an update on existing user. To be honest I would like to use CB triggers but I don't know how to implement it in a joomla plugin script and I can't find an answer or example how to do it. This  using cb triggers document is too complicated for me to understand. I would love to see a working script... 

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48622
  • Thanks: 8302
  • Karma: 1446
7 months 3 weeks ago #337985 by krileon
If them being a new user is all that matters then check against $isNew and ignore if it's false. It will be true when CB first creates the user. You can also add static caching to the function to ignore subsequent calls to that event for a specific user id if the second call from CB is an issue for you.

As for CB triggers they're meant to be used in CB plugins not Joomla plugins. They can also be used in CB Auto Actions. You could try using CB Auto Actions as you may not need to code a plugin at all depending on what you're trying to do. I can make some recommendations if you provide more details about what you're trying to do.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • zederis
  • zederis
  • OFFLINE
  • Posts: 9
  • Thanks: 2
  • Karma: 1
7 months 3 weeks ago #337988 by zederis
Auto Actions is a very nice plugin :) I am using it. Thank you for your reply and suggestions.
The following user(s) said Thank You: krileon

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum