Closed (fixed)
Project:
Rules
Version:
6.x-1.x-dev
Component:
Documentation
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
3 Oct 2008 at 23:42 UTC
Updated:
20 Mar 2010 at 19:59 UTC
I can't find any information in documentation on how to setup scheduled events (like deleting nodes 30-days after they were published). I don't see any scheduling-related events at /admin/rules/trigger/add, could you point me in the right direction?
Comments
Comment #1
fagoyou have to create a rule set for that, then you can schedule the execution of the rule set.
hm, probably we need a howto here..
Comment #2
mattbk commented+1
Comment #3
philsward commentedI agree... I realize that documentation tends to go by the wayside when trying to maintain a module but I must say, the rules module is about like sitting someone in the pilot seat of a 747 and telling them to fly it without a manual (or training for that matter)... I doubt they would ever get off the ground, but they might at least figure out how to turn the windshield wipers on by tinkering with stuff long enough...
I've been trying for the last 3 hours to figure out how to schedule an expiration / unpublish a certain type of node. While I was able to get it to unpublish on a cron run, it was always immediately. This begs the question: What the hell is the difference between "Scheduled evaluation date:" and "Date:" I am "assuming" that "Scheduled evaluation date" is the date that the rule will be triggered and the "Date" is the date that the actual action takes place? If so, why not clarify it a bit more so I can quit staring at it and scratching my head... The other thing thats got me scratching my head, is the whole:
HUH??
I am not a php programmer and while I can figure a few minor and basic php code stuff out, a description like that to a non-programmer is completely Greek. When looking at the actual php manual (link from strtotime()) It's all written for people who know how to code and understand PHP! Now we've got some Greek and Latin adding to the confusion!
While I am not asking for a complete detailed handbook on this stuff, a link from the description to a few (or a lot) of common examples would be nice.
For example, what would a person enter to start from the node creation date, or maybe start x days after the last modified date. I know drupal has all sorts of hooks to this-that-and-the-other but I don't have a clue on how to properly use them for this type of stuff.
Sorry for the rant, I'm not trying to be a pain, just showing my frustration through a little humor and seriousness.
Comment #4
mattbk commentedYour quoted section is actually fairly easy to explain, if you are talking about x days after something. What the strtotime() function does is take what you enter and convert it into a datestamp the software understands. For example:
+1 day = one day after whatever your trigger is
+3 days = three days after
+1 month = one month after
+30 seconds = 30 seconds after
+5 minutes = 5 minutes after
etc.
I did figure out how to do some things, but I need to find time to write them up. I wrote a little bit down here: http://drupal.org/node/360740, but it is in no way complete and understandable.
Comment #5
philsward commentedYa, I tried doing +30 seconds last night but it kept unpublishing my nodes right after a cron run :( I turned on the logging and noticed that my scheduled ruleset seemed to be running before the conditions and actions which led up to the ruleset... I still have a long ways to go before I fully grasp rules, but I will be willing to help out on some of the documentation if I can ever get my head around it lol.
Thx for the post on the strtotime() info. I haven't found anywhere that specifies if the options have to specifically singular or if it accepts plural. I have noticed that a lot of "Programming" manuals and instructions give a very basic idea of how something works (gray) but hardly ever a black and white of what can and can't be done and how to do something the right way.
Comment #6
fagoPerhaps you could add a subpage to http://drupal.org/node/298481 which explains some possible values? Then if you can think of a better help text, tell us!
It might also help to have a look at the slides of my last presentation: http://more.zites.net/rules_at_the_drupalcamp_cologne There is also a video in english - just follow the links.
Comment #7
rdeboerHi,
It has been over 6 months since lefnire, dakotaroar and philsward requested a little documentation on the use of the scheduler.
I'm struggling with the same thing: created a rule-set with a "scheduled evaluation date & time" in the future, but the thing fires immediately when the event occurs.
At the moment I'm not sure whether it's a bug or an operational error on my behalf.
Has there been any progress on the 6.x-1.0 doco?
See also #466670: Not obvious how to use scheduler.
Rik
Comment #8
fagook, to get started some short steps to schedule a simple rule dealing with a node one day later.
1. Create a new rule set, add one argument of type node. This is the rule set, that will be scheduled for later execution.
2. Add a rule to this rule set, e.g. with an action sending you an e-mail or (un)publishing the node.
3. Add a triggered rule, e.g. evaluated on "content has been created". Add the action of the "Rules Scheduler": Schedule . For the date, enter "+1 day".
That's it. Hope it helps.
Comment #9
DanielJohnston commentedI'm going to jump in on this one as well. I've got a specific use case I'm working on, and not the darnedest idea how to achieve it using Rules Scheduler. Here's the thing I'm trying to do:
Create a new node with a CCK data field (with from and to dates)
The node is published at time of creation
When the to date in the CCK date field is reached, unpublish the node
This has obvious applications for displaying events, job adverts and the like. Using Rules seems more elegant than using Scheduler module, which doesn't support CCD Dates, so grateful for any support.
Comment #10
rdeboer@fago, #8
Yes, that got me going, thanks!
Perhaps worth mentioning for others reading this thread that if you don't have cron running as a scheduled job, you won't get an error message.
So to check whether it all works, for a quick test, initially don't use "+1 day", but maybe "+1 minute" and then visit .../admin/reports/status/run-cron to fire cron (once) manually, which will also invoke the Rules Scheduler, I believe.
To set up cron properly, see: http://drupal.org/getting-started/6/install/cron
Comment #11
wb54321 commentedWould love to see a tutorial that explains how to schedule unpublishing a page based on the CCK date field. Or a tutorial that triggers ANY action based on the CCK date field; I could extrapolate from there to accomplish what I need. Or a string of PHP that will replace the CCK Date field.
Plus I don't understand why Rules requires entering a fixed date when you choose the CCK date field at all. If you are going to create a rule to automatically trigger events without manual intervention, it seems that the whole point is to automate a manually repetitive task. Why would you want to assign a fixed date for something that will be done over and over?
Comment #12
uprojects commentedYes ! I say Yes ! :) to know how to schedule unpublishing a page based on the CCK date field or a date creation.
Comment #13
agileadamWe are actually trying to solve this.
Please see here (though it may not be of much assistance): http://groups.drupal.org/node/21377
Comment #14
aantonop commentedOk, I can't do a full tutorial, but I have got this working and understand the PHP, so I might be able to help...
Doing something by scheduling based on a CCK date field.
Let's say the CCK date field is called field_yourcckfieldname.
So, I want to schedule something. The schedule rule takes a timestamp
Here's a sample code you could use:
<? echo strtotime("-5 days", strtotime("[node:field_yourcckfieldname-datetime]")); ?>
This will schedule the rule to run five days before the time/date in the CCK field. Change the "-5 days" part to add or subtract time as you wish. You can use any reasonable text like "-5 seconds" or "-3 years" or "+5 months" or whatever.
If you want it to run on the exact date in the CCK, use this code instead:
<? echo strtotime("[node:field_yourcckfieldname-datetime]"); ?>
In both examples, replace the token [node:field_yourcckfieldname-datetime] with the one matching your CCK field name with the "-datetime" suffix. See the token replacement values in your rules interface and find the right one in the list.
Keep in mind that scheduled rules only run wheneven a cron-run happens. Under normal circumstances you run cron once an hour on a drupal site. So whatever you might be scheduling it will run during the first cron-run AFTER the scheduled time.
Let's say you're running cron at 45 minutes past the hour. So 1:45, 2:45, 3:45 etc. You schedule something for 5:00. Cron run happens at 4:45 - too early, won't run. Next cron run happens at 5:45, NOW it will run because it is past the scheduled time.
So no matter what you do, at best you get about an hour accuracy on scheduling
HTH
Comment #15
rdeboerThanks so much aantonop!
Rik
Comment #16
Krogenar commentedIs this correct? It's not very clear to me. I've been playing around with the tips from posts #8 and #14 got me started, but this basic question still isn't clear to me. Should I putting 'now' or
<? echo strtotime("now")); ?>into one of these fields to ensure that the rule is scheduled immediately?If someone could write up a very basic step-by-step tutorial on how to make the Rules module publish and/or unpublish a node, that would be a tremendous help. Right now I'm just experimenting and hoping I come upon a working solution.
Comment #17
fagoJust put "now" in there, though for "now" you won't need the scheduling system really... (except you just want to let it be handled by cron).
see #515714: Tutorial for Rules Scheduler Module.
Comment #18
aantonop commentedstrototime("now") is uneccessary. The equivalent in PHP is simply time() which defaults to "now" and doesn't do a string conversion.
so <? echo time(); ?> is the same as <? echo strtotime("now"); ?> only faster and more efficient.
Also, if you need to schedule for "now" then execute the rule instead of scheduling it. That will run it immediately instead of at the next cron run. Advantage is that you have less stuff queued up for the cron run. The more stuff you schedule for cron, the longer cron takes and that can cause problems beyond a certain point (cron has a timeout of 1 hour and is subject to PHP memory limits and run time limits)
Comment #19
fagoIt's there, yeah! :)
http://drupal.org/node/298476
Comment #20
rdeboerSuperb!
Comment #22
mchaplin commentedI found I had to have 6.x-1.x-dev if I wanted to use this kind of code:
<? echo strtotime("-5 days", strtotime("[node:field_yourcckfieldname-datetime]")); ?>
Version 6.x-1.1 accepted the above code, but showed a blank Scheduled date in Home › Rules › Rule sets ›
Comment #23
jday commentedRules 6.x-1.x-dev
CCK 6.x-2.x-dev
Drupal 6.16
using
<? echo strtotime("-5 days", strtotime("[node:field_date-datetime]")); ?>or
<?php echo [node:field_date-value] + 86400 * 1 ?>in the date evaluation field do not work, the date field is blank on the Rules Sets Scheduling list
UPDATE: using this value in the date evaluation field worked for me
[node:field_date-datetime] + 3 days