Problem/Motivation
Currently redhen_engagement includes three module-specific rules actions enabling scoring engagements for comments, registrations, and webform submissions. These rules use either a user ID or an email address to match contact records.
However, it would be good to have more flexible actions that are not specific to given modules. More flexible actionis would make it possible to configure rules for any entity that provides an email address or user ID.
Also, engagement scores in rules are stored, and therefore exported, by ID. It would be better to use the machine name (the 'name' field) so that exported rules will import consistently.
Proposed resolution
- Convert existing rules to use the machine name field for engagement scores rather than the ID field. For consistency, also convert the filtering on engagements, which uses the same helper function as the rules to generate a list of options for engagement scores.
- Introduce two new rules actions,
score_engagement_by_mailandscore_engagement_by_uid. Both take four arguments: score, entity_type, entity_id, and either mail or uid. - Rework the three existing redhen_engagement rules actions to use these new generic actions.
- Add a new API function,
redhen_contact_load_by_mail()and, in parallel, reworks the existingredhen_contact_load_by_user()to avoid using the deprecated$conditionsargument toentity_load().
Remaining tasks
Not tested yet. Needs review.
Consider dropping some or all of the existing comment, registration, and webform rules actions. For example, if this patch is successful, the comment action should be superfluous as it will be possible to construct a rules scoring comment engagements using the newly introduced generic actions--though two rules might be required, one for anonymous (using email address) and another for authenticated (using UID).
User interface changes
Users building rules will see two new rules actions.
API changes
Adds a new API function, redhen_contact_load_by_mail().
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | redhen_engagement-rules-1796944-3.patch | 11.34 KB | nedjo |
| #2 | redhen_engagement-rules-1796944-2.patch | 9.16 KB | nedjo |
| #1 | redhen_engagement-rules-1796944-1.patch | 8.89 KB | nedjo |
Comments
Comment #1
nedjoI've only conceptually sketched this in and done no testing, so marking needs work.
I'm working on this partly as an enabler for #1772710: Enhance default rules integration for RedHen contacts.
Comment #2
nedjoFixed up some problems with the patch. Haven't fully tested. Here's a sample rule to test with, to score an engagement when a comment is posted. Requires an engagement type with the ID of 1.
Comment #3
nedjoWe should really be using the machine name of engagement scores rather than IDs in rules so that they will export and import dependably.
Revised patch attached makes this change. Note: this will break existing rules that use the score IDs.
This also changes the existing engagement type filtering to use the 'name' field rather than the 'engagement_score_id' field.
Needs more testing.
Comment #3.0
nedjoConsider dropping some existing rules actions.
Comment #4
nedjoHere's an updated sample rule to try with the patch in #3. Assumes an engagement score with the machine name "standard".
Comment #5
levelos commentedGreat concept @nedjo, I whole heartedly support the approach. I'm unable to get your patch working, though. In particular,
Type list does not work on my end. Setting it back to integer works, but the list is allowing multiple options.
Should be $score.
Comment #6
levelos commentedComment #7
tauno commentedWorking on this. Committed changes to 1.x-dev that changes engagements to use the machine names of engagement scores and adds some additional metadata handling. The rules actions still need to be updates. I like the generic approach in the patch, so we'll probably work off of that.
Comment #8
tauno commentedRe-worked the patch and committed it. Thanks for getting it started nedjo!
Comment #9.0
(not verified) commentedUse machine name rather than IDs for storing engagement scores in rules.