[SOLVED] In Auto Actions, is onAfterNewUser the Right Event?

3 months 3 weeks ago - 3 months 2 weeks ago #317672 by bascherz
I am trying to force a cb field to a particular value after a new user is approved. I know the database query is correct because I've issued it manually via phpMyAdmin. I am using Auto Actions and triggering on onAfterNewUser. I've also tried onAfterUserApproval with no better luck. In either case, after the user is approved, the field is not set as the query should have set it. This makes me wonder if:
  1. I am using the right event
  2. CB is messing with the profile values after this action is handled.
Anyone know?

Thanks in advance,
Bruce

______________________
Bruce S - Vienna, VA

Please Log in to join the conversation.

3 months 3 weeks ago #317673 by bascherz
As often happens with me, I end up answering my own question. I was using a Query action which had an UPDATE query rather than keeping it simple by using a Field action. The difference is a Field action has the "Save Directly" option, which keeps it from generating a profile update event, whereas a Query action does not have that option. So I suspect the query in my auto-action was actually somehow causing another event to trigger and somehow undo what that query did. Switching to a Field action and using the Save Directly option made it work.

I would love to know how a direct database UPDATE can trigger a CB event.

Bruce

______________________
Bruce S - Vienna, VA

Please Log in to join the conversation.

3 months 3 weeks ago #317697 by krileon
Query action doesn't fire any profile update triggers, but it doesn't update the user object like a Field action will. By updating the user object subsequent stores on the user object will be aware of the changed field value. So it just kind of depends on what you're doing after the auto action. If changing field values though always try to use a Field action when possible.


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 to join the conversation.

3 months 3 weeks ago #317703 by bascherz
Hi Kyle!

Thanks immensely for your response.

Well, truth be told I am trying to fix a piece of code I wrote years ago that reacts to one of the three possible events along the path to getting a new user approved (depending on how CB is setup). How to update the profile choices (multi-select checkbox fields) depends on data queried from non-Joomla database tables based on email address. The desire is to "check all the appropriate boxes" in the user field based on the way my CB plugin is configured. In other words, this started out as my own plugin but this part of it has never worked and I never figured out why.

In the query style Auto-Action the query looks like this:
UPDATE #__comprofiler SET cb_fieldname = 'Account Email' WHERE user_id=[user_id];

The code in my plugin does the exact same thing but obviously doesn't have the luxury of [user_id] like an Auto-Action does and obviously has to use Joomla API database query methods. Anyway, when this is done in response to any of the three events (from memory, so pardon if not exact names) onAfterUserApproval, onAfterUserConfirmed, or onAfterUserRegistration, whether in my plugin or as an Auto-Action, the value 'Account Email' never appears in the comprofiler cb_fieldname column (checked via phpMyAdmin), which appears untouched (still NULL).

Using the Auto-Action Query action type was my attempt to see if it is WHEN I am trying to do this that is the issue versus HOW I am doing it. I know the query is valid because I can issue it in phpMyAdmin and it works perfectly. So my take-away is that something is either blocking the UPDATE query or something else happens later in the time line (after the event is handled) that undoes it.

My plugin code still uses the "old style" Joomla database methods:
db->setQuery("UPDATE ...");
db->execute();

In this plugin, those non-Joomla database tables are also being updated this way and all those queries work. So I've just started to believe something else is going on that is thwarting my queries. Although the Auto-Action "fix" (with the Field action) does work, it's disjoint from my plugin, so not an ideal solution.

Thanks again for your assistance. :)

Bruce

______________________
Bruce S - Vienna, VA

Please Log in to join the conversation.

3 months 3 weeks ago #317735 by krileon
My guess is you've a user object ->store() happening somewhere after the events you're acting on. If that's the case your changes will be lost since you're just doing a database query which isn't updating the current in memory user object. A Field action always updates the user object which could explain why it's working.


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 to join the conversation.

3 months 3 weeks ago - 3 months 3 weeks ago #317741 by bascherz
I don't have any such thing in my code, though I thought perhaps CB may have something like that going on that overwrites my update after the fact. How is that sort of thing circumvented? I don't yet know why it seems associated with these CB user approval-related events. Remember, the same thing happens if in response to onAfterUserApproval I do the same update query in a Query auto-action. Does such an object->store() happen some time later after a new user is approved? I have seen the same exact query not work (or get superseded) after a onUserLogin event also. The same method with that query gets called in both places (in my plugin) in an effort to better ensure it happens. But the update never "takes".

Edit: I setup a trigger on #__comprofiler to record changes in one of the two profile fields my plugin is updating. In the attached screen clip showing all the updates to that table after approving a new user, you can see the field being set to 'Account Email' (done by my plugin) and then later getting overwritten with an empty value.



I don't know what the first two updates are, but they happen before my plugin runs. It's the two that happen 5 SECONDS AFTER my plugin runs (at 16:39:02) that are a mystery.

______________________
Bruce S - Vienna, VA
Attachments:

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.472 seconds

Facebook Twitter LinkedIn