Closed (fixed)
Project:
User Points
Version:
6.x-1.x-dev
Component:
Code: userpoints_rules/userpoints_workflow_ng
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
22 Apr 2009 at 17:27 UTC
Updated:
3 Jan 2014 at 00:07 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
off commentedcool
Comment #2
fagoDon't tried it, but the looks fine.
@existing rules integration:
* Imo this could also go into a .rules.inc file, just the rules_invoke_event call would have to go to a .module.
* Loading the user account for the event should happen in a argument loading handler, so it gets loaded when necessary.
Comment #3
jcmarco commented@fago
I have made changes in the patch with your recommendations:
- moved all rules but rules_invoke_event call to rules.inc file (it is needed to clear the cache in order to update the rules.inc)
- And you were right, it was not needed using the $account with a user_load, when it was just needed the uid.
- There is some code style cleaning
Hopefully this patch could be added to the module as I have to patch the new condition rules everytime there is a new dev release.
Comment #4
kbahey commentedCommitted.
Thank you!
Comment #5
drupup commentedDid I do something wrong?
I just did an uninstall/reinstall with the latest .dev, and after reassigning points and recreating rules it seems that the userpoints condition is returning TRUE no matter what the user's point level, FALSE if NEGATE is checked. Again, the user's actual point levels don't seem to be registering. This previously worked just fine.
This is adding a condition to a "User has logged in" rule. This was working before.
Comment #6
jcmarco commentedI have a rule that check userpoints number with a level:
ON event User was awarded points
IF
conditionUserpoints amount is >= than x indent
addAdd a condition
DO
actionAdd user role
actionShow a configurable message on the site
And it is working fine.
That last patch only added a new condition and left using the user_load was removed.
When I updated to new dev version I had issues loading the new rules.inc file, try to clean the cache.
Comment #7
drupup commentedShould have thought of the cache. But now that I've done that, it's gotten more interesting.
Condition works when it checks and verifies.
Condition DOESN'T work when it is set to negate.
Basically, I'm using point levels to add/subtract a user role. I've got two rules:
ADD ROLE
ON event User Has Logged In
Condition: User has role (Premium account)
Condition: Userpoint amount is >= 200
DO Add User Role (Create Special Offers)
This is working fine
REMOVE ROLE
ON event User Has Logged In
Condition: User has role (Create Special Offers)
Condition: NEGATE Userpoint amount is >= 200
DO Remove User Role (Create Special Offers)
THIS is not working. I take away the userpoint condition, and it works (so it's not the other condition, and it's not the action). Also, if I set the Userpoint conditions so the REMOVE ROLE condition is not negated (it looks for a low point total, the ADD ROLE rule condition looks for a higher total), both conditions respond correctly. Something is not right with how it's evaluating negated conditions.
As I said, this all was working before. I'm baffled. Perhaps I should backtrack and patch, but I'd rather not.
Comment #8
jcmarco commentedI don't know what to say.
I have created a rule that check when some points have been awarded, with the conditions that if it is not >= than a number then it shows a warning message.
After that I have configure to add a point with every new comment and I have been playing with that, also considering that if you delete a comment it deducts a point, so I have check that works fine.
Then I created a new rule with the action every time you see a page, and the condition that if you don't have >= than 310 points then show a warning message saying: 'Ey! Earn more points!!'. And while I don't have 310 points on each page I got the message, then I create a new comment I earn 1 point to have this number and I don't see any more the message.
Are you comparing with the same category of userpoints than the ones owned by the user?
Even you can try to delete the condition and create it again.
Comment #9
drupup commentedBelive me, I've tested this extensively, and something went seriously wrong when the functions got ported over to the rule.inc file. I don't use point categories, and I created a bunch of different rules using a bunch of different events and a bunch of different actions. NEGATE was not working correctly...sometimes it was never, sometimes it was all the time.
I created another rule, just to take the roles and the user login out of the equation, where opening a page granted points to the user. All actions granted points to the admin, rather than the logged in user.
Then I just took everything back to where it was before, went back to 6.x - 1.0 and put the functions back in userpoints.rules.module, and everything is working correctly again. Even highly complex mixes of conditions with and without NEGATED userpoint conditions are doing exactly what they are supposed to.
I wish I could offer more guidance on what's going on, but all I can do is report my experience as a user. I'm not sure you want to commit this just yet.
Comment #10
jcmarco commentedWhat rules version are you running?
I am testing with last Rules 6.x-1.x-dev (2009-Aug-20)
Comment #11
drupup commentedI'm using the 6.x-1.0. I'll try loading up the dev, load up the dev of Userpoints, and report back.
Comment #12
drupup commentedOkay: using an all-.dev setup, rules work for the uid=1 admin account, but not for any others. I created a second Drupal install, nothing but Rules and Userpoints as added modules, and I got the same results.
Again, revert to previous setup, and everything works correctly.
This account is hosted on Bluehost...but then again, lots of Drupal sites are hosted on Bluehost.
Went and did another uninstall/flush/reinstall, and yep, works for uid=1, no one else.
For the moment, I'm reverting.
Comment #13
jcmarco commentedNo clues! I have tried as well with a registered user and last testing rules worked fine as well.
This is the rule I am playing with:
Try it but remember to change userpoints types to your ones.
Everytime you earn some points and you are below 500 you get a warning message.
Tested with registered user and admin user.
Check also permissions with:
view own userpoints
view userpoints
Comment #14
drupup commentedCheck out the test site:
http://www.ecovision360.com/test/
Admin is
username: admin_test
password: 4nwvYjJ7
Authenticated user is
username: testuser
password: testuser
There's one added role: page creator
There are two rules
One adds the page creator role when the userpoints are >= 30
One removes the page creator role when the userpoints are NOT >= 30
Just figured out what's happening....the rule is evaluating the admin's account, not the account of the user who is logging in. That would explain why it was granting points to the admin account earlier. It evaluates to TRUE or FALSE based on the points in the admin account, not the points in the test user's account. Change the point totals for either of them and you'll see.
Comment #15
jcmarco commentedThanks to @drupup and his perseverance, I was testing his configuration and I realized that the problem is when using actions/events/conditions different from the userpoints ones.
Userpoints uses internally user->uid and events/actions/conditions were running with the uid instead of $user as rules module does internally.
So when using userpoint events with userpoint conditions/actions everything worked fine.
But when using other modules actions/events, then their actions/events are using $account/$user, and they send this parameters to userpoint rules integration. So it fails reading the uid.
Please test this patch, I have tested it locally with the commented old test actions and a new one that cross actions from other modules with userpoint conditions and in my installation works fine.
Comment #16
jcmarco commentedComment #17
himagarwal commentedWhen the author of node/comment changes I want to subtract userpoints from the previous node/comment poster and add userpoints to new node/comment poster. But I think this is not possible with the rules or if I messed the whole thing. It is getting very complicated.
Features Requested:
1. It would be nice if default rules are already loaded when module gets installed
OR
2. After module installation there is a button (in userpoint rules setting page) saying load default rules and those who want default rules can click on button otherwise leave it as it is and create new rules on their own.
However, It was nice and simple in drupal 5 where rules were already defined.
Comment #18
jcmarco commented@himagarwal
this rules integration just add some basic triggers/actions/conditions, any other complex rule or feature can be programmed in a module or trying to write a rule set.
Now, the condition added with last patch is really independent or any combination of modules-rules-conditions-behaviors you could define with the module rules and other modules.
IMHO requests #1 and #2 should go to the rules project where core rules are defined and default rules could be defined (rules module is very powerful and already give you options to do so, but you need to add them in a custom module or with a manual import).
Comment #19
drupup commentedjcmarco:
I'm guessing "perseverence" wasn't the first word that came to your mind (insert emoticon of your choice here...)
Anyway: QA is easy. It's the coding that's the hard part. And it looks like the coding is solid. I've set up a variety of fairly complex condition combinations, and a variety of multi-part actions, both involving the userpoints and not, and I haven't found a new way to break it. Not that I won't keep trying...
This is a really valuable addition to Drupal. Thanks for the work. Now I've got about 50 rules to go set up.
@himagarwal
I agree with above, you've got a new issue here, and the Rules project is the people who should see it. Good idea, just put it in front of the right set of eyes.
You'd best steel yourself for the future: Drupal is becoming a lot more powerful, but the price is that it's going to be less easy to use than it used to be (not that it was all that easy to begin with...). More flexibility, but less out-of-the-box stuff. I used to be able to hack some of my own patches...but the move to a more OO approach to coding is starting to leave designers/part-time hackers like me in the dust. I think the gain is worth the price.
Comment #20
Bilmar commentedI'm having a problem with the rules integration. I currently have it set so when an event takes place a point is deducted from the user.
Right now, no matter which user takes the action - the point is deducted from admin =(
Is anyone experiencing this same bug?
Comment #21
jcmarco commentedHave you tested patch #15?
Comment #22
Bilmar commentedI tried to implement the patch in #15 but userpoints stopped working properly..
I believe it is my lack of knowledge in patching.
Will continue to try to get this to work properly
Comment #23
seabhac siulach commentedCan the patch in #15 above be added to the module?
The previous patch is not working, resulting in badges, etc. being awarded to the user awarding userpoints and not the person receiving the userpoints. In addition, the 'add role' action in rules is not working using this new userpoint condition, probably for the same reasons.
Thanks to all who have worked on this very useful addition to userpoints, by the way!
Comment #24
BenK commentedHey everyone,
Patch #15 (by jcmarco) works beautifully for me. I have a totally different configuration than what is described in this thread, but I was still getting points awarded to the admin (user #1) instead of the appropriate user. Once I applied patch #15, everything worked properly.
So can Patch #15 be officially committed to the module ASAP?
Thanks,
Ben
Comment #25
kbahey commentedI committed the patch in #15 to the 6.x-1.x-dev.
It will be available in the tarball in about 9 hours from now.
Please test the new tarball with the fix and report any problems in a new issue.
Comment #26
BenK commentedThanks, kbahey, for the quick response!