Role with Rules
eranglr - October 27, 2008 - 15:20
Hi there,
I'm trying to figure out how to add a registered user a role after X days (there is a module called "role delay" but it isn't featured nor have any filter and power as rule/trigger).
I thought of using date module, any one has a SIMPLE yet SMART idea?
Thanks!

you might be able to do this
you might be able to do this with the http://drupal.org/project/rules module.
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
I know that
Look at the title :)
I know how to use rules, question is how to suspend role add-on to user (for example - give a new role after 4 days from registration, comment writing, etc..)
---------------------------------------
http://www.designhit.co.il - אתר הסטודנטים לעיצוב של המכון הטכנולוגי חולון
Since you make no mention of
Since you make no mention of the rules module, i took the 'rules' in the title to be the generic english word 'rules'.
In any case, the more I think about this the more I think it would probably be more efficient as a little php script run nightly with cron. If you do it with the rules module, even after the user's role has been promoted, it will continue to do the check at each user login or cron run (depending on the trigger you select) which seems like a waste.
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
The trigger I've selected is
Upon user registration,
Question is, if I can do this with rules and if so, HOW?:
when new user register, after X days/hours, he will get a custom Email? It is importent that AFTER that user will get this email, he won't get it again :)..
Is that possible using Rules? I've tried doing so using rule-sets, and apply +50 seconds under schedule option, even after running cron the e-mail wasn't sent..
Can you please guide me (and the rest of us who's reading this) how to apply a schedule role-apply/email sending.
---------------------------------------
http://www.designhit.co.il - אתר הסטודנטים לעיצוב של המכון הטכנולוגי חולון
It's not something you want
It's not something you want to do at registration-- it's something that needs to happen x days past user creation date.
So, the first thing you have to decide is which event you will use to check for the 'x days' interval. You can setup rules to check at each cron run. Depending on how often you run cron and how many users you have, it could be a large unnecessary overhead for cron to check every user creation date on your site at every cron run.
imo, it's better to check when the user logs in. So you'll need to check the current date against user created + x days.
Then, you need to make a condition for 'if the user does not already have the 'premium' role' (this is a default option if you choose the user login event).
If that condition evaluates to true (does not have the premium role), then add a second condition to check today's date against x days + $account->created (the date_api module has some functions that should be useful here, otherwise see the php date functions). You might be able to do this with the compare numeric values option, if not, you'll have to use the php code option.
Then, for the action, select 'add user role' (also available as an option if you select the user login event) and the premium role you'd like the user to receive.
It's actually not too difficult-- the only tricky part will be to get the date math right. The only thing I don't like about this approach, is that even after the user has been granted the premium role, it will still continue to check the first condition each time the user logs in.
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
Thank you,
I've tried doing it, guess the best way will be to just write/hack other module, so the "If" statement won't be checked each time over,
Thank you.
---------------------------------------
http://www.designhit.co.il - אתר הסטודנטים לעיצוב של המכון הטכנולוגי חולון
i just had another thought (
i just had another thought ( i can't believe i didn't think of it sooner)--- you should be able to add php to the action to disable the rule itself after the role has been changed.
rule===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
Can you (please) describe the steps to accomplish
This task? this will help me (and others) A LOT!
I understand the logical, BUT, what I can't figure out is - how setup each and every step.
So, it might help if you could please help me figure our exactly how to do so.
thank you
---------------------------------------
http://www.designhit.co.il - אתר הסטודנטים לעיצוב של המכון הטכנולוגי חולון