Hey Berdir and all,
It's very exciting to now have an official 7.x-1.x-dev branch! I'll be creating individual issues to fix the remaining bugs. Here are the bugs we need to fix related to Rules integration:
* USERPOINTS RULES CONDITIONS: None of the four Userpoints-related conditions appear to be working. When using "Check the transaction category," there is no field to specify which category to check. When using "Compare userpoints before the transaction," "Compare current userpoints," or "Compare the transaction amount," there is no field to actually input the number of points to be compared. As a result, when executing rules with these conditions it results in the following error message: "Notice: Undefined index: type in userpoints_rules_amount_before() (line 205 of /Users/benkaplan/git/drupal/sites/all/modules/userpoints/userpoints_rules.rules.inc)."
* USERPOINTS RULES CONDITIONS BRANDING: There are a few strings in Userpoints Rules Conditions that are not properly branded with the admin's branded points terminology. Pretty minor stuff.
* USERPOINTS RULES ACTIONS: The "grant points to a user" action is not yet working. In particular, a lot of data selectors seem to be incorrect and there seem to be a lot of extraneous fields on the configuration form.
Cheers,
Ben
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | rules_port4.patch | 20.79 KB | berdir |
| #16 | rules_port3.patch | 20.62 KB | berdir |
| #11 | rules_port2.patch | 19.78 KB | berdir |
| #1 | rules_port.patch | 13.77 KB | berdir |
Comments
Comment #1
berdirA first patch..
- The ultimate goal is to make userpoints transactions an entity, so that you can browse through it like you can with nodes for example when selecting data. However, that requires changes to userpoints.module I think and I don't quite get what's all required to do that.
- So, the current patch splits the data up in several separate things (points, category, user, total_category_points, total_points), so that you can directly access them.
- This also makes most of the conditions useless because you can use the default data comparator to check if the points are lesser/equal/... to a given amount. The only category left is a check for the category, since it is usefull to compare that against a select of the existing categories
- Updated the action, all fields should now have a description, some are optional (description, entity stuff) and they are limited to input mode if it makes sense so.
- If we get this right, we can imho drop quite a few modules of the userpoints_contrib project, things like mail notifications for example should be easy to do with rules.
Comment #2
BenK commentedHey Berdir,
I applied the patch in #1 successfully, but I can't find any Userpoints actions, conditions, or events in the Rules UI. I tried clearing my cache and updating to the latest versions of Rules and Entity. But still no luck....
Am I missing something? Or is it possible that there's a bug causing the actions, conditions, and events supplied by your patch not to be loaded?
Thanks,
Ben
Comment #3
berdirYou did enable the userpoints_roles.module ? :) Dumb question, but I had to ask it since you haven't said anything about that...
Comment #4
BenK commentedHmmm... that would be pretty embarrassing. Let me check...
Comment #5
BenK commentedWow, it looks like I did forget to enable the sub-module... sorry about that! ;-)
I just finished some initial testing of the "Grant points to a user" action. Wow, this is really working well, amazing for an initial patch. I've confirmed that the User, Points, Points Category, Description, and Operation fields are all working well. I was even able to use Rules' token replace to put tokens in the Description and Operation fields. I also confirmed that the entity type and entity id are working properly... I used this to automatically link the operation field to the node when using the "node is published" event.
Just a few UI things:
A. Maybe the "entity type" field should be a single-line textfield (or dropdown menu) instead of a text area? It just seems a little weird to have a huge text area and then type the word "node" in it. A dropdown menu could be handy if the dropdown menu could be populated with all entity types on the site. Since most sites won't have more than a dozen or so entities, this could be an easier way to choose.
B. I'm wondering if the "Operation" field should be a single-line or double-line textfield rather than a text area. While it is possible to have a long operation field, it seems like the Userpoints UI is mostly designed for this to be fairly short.
C. I'm wondering if there is any way to specify within rules the "Expiration date" for the points. This is available on the userpoints add form and it could be handy to specify this within rules. Not sure if this is possible.
D. I'm wondering if there is any way to specify within rules whether or not a points award is approved or not. For instance, if you're set to have all points moderated, it would be handy to set certain rules to be approved automatically (or vice versa). But not sure if this is possible.
--Ben
Comment #6
BenK commentedBerdir,
I've continued my testing with conditions now, but I'm a bit confused with how to use (and test) the new "Check the transaction category" condition. In the Rules UI, I'm getting two points category fields... one that has an autocomplete labeled "data selector" and one that has a downdown menu (select list). In the autocomplete, however, the available data selectors are blank.
So I'm not sure what exactly I'm supposed to compare. I'm trying to use this with a "node is published" event and the "Grant points to a user" action...
Is anything missing from the UI or am I just not understanding how to use this properly?
Thanks,
Ben
Comment #7
BenK commentedAlso, I just tried to use the "Data comparison" condition, but I'm not seeing any available data selectors related to userpoints.
More specifically, based on your comments in #1, I was looking for data selectors related to points, category, user, total_category_points, and total_points. But I'm not seeing any of these in the DATA SELECTORS fieldset.
Currently, I only see default data selectors for site and node. What are the data selectors that should be appearing?
As soon as I can find these, I will do more testing of conditions...
--Ben
Comment #8
BenK commentedOkay, in regard to my comments in #6 and #7, I've got this figured out now: Basically, the current Rules implementation only supplies conditions on the "User was awarded points" event. Since I was trying to use conditions with the "Grants points to a user" action, they weren't showing up properly.
I talked this over with Berdir in IRC and he suggested that we would need some conditions that don't just work on a userpoints transaction but also on a user. Then the conditions will always be available when a user object is available (which could be the current user, node author, user who gains points, etc.)
So based on my conversation with Berdir, here are a couple more to-dos (continuing the item list from #5):
E. Create Rules conditions that also work on a user (not just on a userpoints transaction). For instance, such a condition could be used to create a rule that grants points to a user on a certain event only if they already have accumulated more than 25 points.
F. Create a "status" condition. This would allow you to take an action on the "User was awarded points event" only if points have been approved, declined, added to the moderation queue, not added to the moderation queue, etc. Basically, this allows us to create Rules that respond to the various states in the points moderation system. One thing we'll have to check is whether the "User was awarded points" event fires even when the points award first goes to moderation queue. We'll also need to determine how a condition can be created for the case in which points were declined (since points aren't actually being awarded).
Finally, I should mention that I tested the "Grants points to a user" action and everything is working great. So that's it for testing on my end. I'll look forward to testing the next patch as soon as you have it! :-)
--Ben
Comment #9
BenK commentedBerdir and I continued our discussion in IRC and I'm documenting it in this comment. We agree that there is a need for a before/after event to do data comparisons.
A use case for this is preventing point totals from going negative. Basically, we need to be able to do a data comparison before the points are actually awarded/deducted... then we could see if the new points deduction would cause the total to be below zero and take the appropriate action.
So I'm adding one more item to the to-do list:
G. Create a "Before awarding points" event (similar to "Before saving a comment" or "Before saving content" that rules supplies). The idea would be to check the results of a points grant before the points are actually granted. We may also need a "Cancel points award" action as well.
--Ben
Comment #10
BenK commentedOne more thing:
H. I'm wondering if there is any way to specify within rules the "Reference" for the points. This is available on the userpoints add form and it could be handy to specify this within rules. I noticed this was missing for rules-generated transactions when creating a view of userpoints transactions.
--Ben
Comment #11
berdirA lot of changes :)
- There is now a userpoints_transaction data thing and all information inside that is available to rules
A. entity is now an entity object, you can either load one and specify it or provide an existing one (node, comment, user, term, private message, ..). Note that userpoints.module might not work correctly with entities other than node/comment yet (no links for example)
B. Changed.
C. Expiry date added to the action and event. Untested yet.
D. + F. Moderated and Display can be controled in the action and event. (It's status in the event which is a bit different than moderate)
E. Added an action to load points of a user in a specific category. This is just a starting point, we can always add more stuff.
G. there is a before and an after event, you can alter the transaction in the before event.
There will be bugs for sure, for example userpoints.module might not let you change/control some of the properties in the before event, but we have to figure out what works and what not before fixing it :) As you know, there is already an issue for the status.
Comment #12
BenK commentedWow, nice job. This will be fun to test. I'll get on it shortly.
--Ben
Comment #13
BenK commentedI've done some initial testing of the latest Rules patch (mostly the "Grant points to a user" action) and it's working very well. We've got a lot of functionality and control now. Here are some things I've noticed:
1. I'm getting the following error message on the top of the main Rules config page:
Notice: Undefined index: userpoints_event_points_awarded in RulesPluginUI::overviewTable() (line 636 of/Users/benkaplan/git/drupal-dev/sites/all/modules/rules/rules/ui/ui.core.inc).
2. If I add the 'Grant points to a user' action, I'm getting the following error message at the top of the page to configure the action:
Notice: Undefined property: RulesAction::$uid in userpoints_get_categories() (line 1070 of /Users/benkaplan/git/drupal-dev/sites/all/modules/userpoints-DRUPAL-7--1/userpoints.module).
3. For the 'Grant points to a user' action, only the "General" category is being shown in the Points category select list. This means you can't currently select a category other than General.
4. The word "Wether" is misspelled in the the following descriptive text. We also might take this as an opportunity to clean up some of this descriptive text:
a) Change: "Wether to show a message to the user for this transaction or not." To this: "Whether or not to show a message to the user when this !points transaction is added."
b) Change: "Wether this should be moderated or not." To this: "Whether or not this !points transaction should be moderated."
5. Change the label "Expiry Date" to "Expiration Date"
6. The expiry date is being successfully saved, but if you go to edit the action, the field appears blank. This makes it very easy to totally remove the expiration date if you are editing the action.
7. This may be something for a separate issue. But it was so minor that I thought I'd mention it. In the database, it looks like the "expired" field has an incorrect comment. It says "User ID" currently, but it looks like that field is meant to indicate if the transaction is expired or not.
--Ben
Comment #14
BenK commentedUpdate: I did some testing of the 'Load points of a user' action and it's working very well. I used it both as as a stand-alone action and as part of a condition (which was part of a rule set) and everything worked great.
Specifically, I tested whether I could award 100 bonus points to a user (when they published a new article) if their General points balance was greater than 4000 points. I used a similar rule set configuration to what we used when testing Private Message's 'Load unread messages' action. And it worked just how it was supposed to (with one small exception described below).
I did notice one quirk, however, that may be related to 3. above (in comment #13). When these 100 bonus points were awarded, the total points listed in the drupal_set_message was actually incorrect. The total points being listed was for all categories combined even though the message said if was for the general category. So this is the weird part: I had a separate 'Grant points' action being run first in the same rule... for that message, the total was correctly showing the General category points as the total. But when the bonus points action ran after that first action, the total for this second message was then incorrect (it was showing all categories, not the General category total).
If any of this is unclear, I can probably explain it better in IRC.
--Ben
Comment #15
BenK commentedUpdate #2: I noticed something interesting when using Rules in conjunction with our new /myuserpoints page. In the reason column on that page, the operation of the rules-drive points transaction is being displayed. But shouldn't the description be displayed here (assuming there is one as part of the rule)?
I noticed this when I had some rules set to be moderated. If you go to the moderation approval confirmation page, the "reason" being displayed (which is displayed in the description area in our latest patch) is the the transaction description. Yet, this doesn't match the reason on the /myuserpoints page because the "operation" is displayed as the "reason" on the page.
If available, the "description" should be used as the "reason" on rules-created points transactions. The "operation" would only be used if the description was not filled in as part of the rule.
--Ben
Comment #16
berdir#13:
1. Errors like these happen when a module that defines an event/action/whatever aren't present, maybe the module wasn't installed at that time. Since I renamed the name of the events, that could be a possible source for this error too if you had old configurations.
2. Fixed.
3. Was related to 2. and is also fixed.
4. & 5. Changed.
6. I think this is a rules issue. I just define that it is a date field, everything else is handled by rules.module.
7. Yep, that looks wrong, but lets handle that over in #945622: 'Reason' column: Description gets replaced by truncated operation when you edit point transactions created by other modules as there might be schema changes anyway there. If not, then a new issue..
#14. Weird. I'm not sure what happens here but I suspect a bug in userpoints.module, maybe somewhere in cache (= userpoints table) update mechanism. I reproduced your issue. And when I'm trying to give points manually after that, more weirdness happens. It actually gives much more points it seems and shows the wrong total (all instead of general). For example, when I give -10 points, the total amount increases by ~20. Not sure if that happened before too or not, I haven't actually checked. Can you try to do some more testing here?
#15. I can not reproduce this, the description is correctly shown for me at /muserpoints. Maybe I fixed that somehow with the other changes?
Attaching a new patch that should reproduce the errors reported in #13.
Comment #17
BenK commentedHey Berdir,
I've confirmed that all errors described above are now fixed.
I just noticed one additional error in my testing:
A. The expiration date field in the "Grant points to user" action appears to be overwritten by the Userpoints default expiration setting. Basically, I tried setting an expiration date in the rules action either with an absolute time or a data selector (such as the current time plus an offset). No matter what I choose, the expiration setting at admin/config/people/userpoints/settings is being used.
Also, if I leave the expiration setting blank on the "Grant points to user" action page (so that the points won't have an expiration date), it is still being given the UP default expiration date. Should there be a checkbox setting to use the default UP expiration setting (or not)?
--Ben
Comment #18
BenK commentedI just tested the "User was awarded points" event and it's working well. My test case is sending a Private Message to the points recipient when points are awarded.
Just one issue: The only replacement patterns available for the PM subject and message body fields are related to "Site Information" (or the "Fetched entity" if I loaded a User ID as the message sender). What we really need here is replacement patterns for the Userpoints transaction including points awarded, category of points, approved or moderated, reason, expiration, and timestamp. This way you can send a PM message that includes information about the specific points transaction.
Are those replacement patterns something that can be added?
--Ben
Comment #19
BenK commentedFinally, I also did testing of the new "User will be awarded points" event. It doesn't appear to be working properly yet in combination with the "Grant points to user" action.
To test it, I created a rule that was intended to alter the amount of points being awarded. To simply things, I didn't use a condition. I just figured I'd try to alter any points award coming through the system. So on the "User will be awarded points" event, I created an action to "Grant points to a user" and tried to award 3 points in a different category.
When I then tried to add points manually to a user through the UI, no points were awarded, there was no drupal set message, and after submitting the points I was returned back to a blank "add points" admin screen.
Any ideas? Or am I somehow configuring this wrong?
The use case for this would be to add a condition that, for instance, prevents points from going negative (by just setting total points to zero). Or would it be better to have a "Decline points to a user" action to prevent the points award altogether? Or should we have a "Set user's point total" action to just set the user's points to zero in a given category?
--Ben
P.S. I was able to get the "User will be awarded points" event working with PM's "Send user a message" action. Of course, that works pretty much identically to the "User was awarded points" event so I'm not sure if it's a good test.
Comment #20
berdir#17: expiry settings now actually work (They didn't before, didn't matter if you had a default expiration date or not). The default is however still used when there is no or an invalid expiration date given. Not sure about the checkbox, not sure how to implement that.
#18: No idea, will have to investigate. I guess userpoints.module needs to provide tokens, so nothing userpoints specific, but I will need to figure out what rules exactly does here.
#19. I really can't follow you there. When you want to *change* the transaction, you need the "set data value" action and change the existing transaction. To decline points, you can change the status to declined based on whatever conditions you want. To change the points, you need to change the points property, and so on. Anyway, I fixed some bugs and can now grant points during the before hook. What could be added additionally is a way to actually block the transaction, which does not save it. The problem there is, that this is a hidden action, since the error is just returned by the API function but nobody actually checks it.
Here is a new patch, let's try to get something working in soon and then improve it in follow-ups... :)
Comment #21
BenK commentedHey Berdir,
The new patch is working great. Expiration (#17) is now fully functioning and on #19 I just wasn't using the "set data value" action. So I tested that action (in conjunction with the "User will be awarded points" event) and it's working great as well. So this is ready to go and I'm marking this RTBC!
--Ben
P.S. As you suggested, I'll open up new threads for added rules functionality at a later time. Here's a quick summary of what we could add later:
a. When changing the transaction "status" on the "User will be awarded points" event, the "set data value" action won't save. The following message is displayed: "The selected data property doesn't support writing."
b. If the default Userpoints expiration setting is set to expire and you want the rules action to never expire, there is currently no way to do this. It would be nice if you could type "none" or "0" within Rules to avoid setting an expiration date on the transaction.
c. Create replacement patterns within Rules for the Userpoints transaction including points awarded, category of points, approved or moderated, reason, expiration, and timestamp. (#18 above).
Comment #22
berdirOk, commited!