This tutorial will give you an example how to use the Rules Scheduler module.
Preparations
Additionally to Tutorial 2: download and install CCK and Date and setup a content type with a date field, that will serve as publishing date (set the Label to "Publishing Date"). See the documentation of those modules if you are not quite sure how to use them.
Creating a rule set as scheduling action
We can re-use the rule set from Tutorial 2, so refer to that example if you haven't created it yet.
Creating a triggered rule
- Go to "admin/rules/trigger" and add a new rule.
- The process will be very similar to the example in Tutorial 2.
- The rule label should be something like "Schedule publishing by date field" and the event must be "After saving new content".
- Add a condition "Content has type" to verify that we only act on our previously added content type.
- Now add an action, select "Schedule Publish content" and click "Next".
- Fill out the "Identifier" field with something like "node [node:nid]".
- Here comes the tricky part: fill out "Scheduled evaluation date" with something like "[node:field_publish_date-datetime]" where "field_publish_date" is the identifier of your date CCK field.
- You can lookup the available replacement tokens from the fieldset "Replacement patterns for saved content" above. Click "Save".
Testing
- Create new content from your previously defined content type with the date field.
- When you save it, the rule will be executed.
- Go to the scheduling page ("admin/rules/rule_sets/scheduling") and look at the list of scheduled tasks, your node should be listed with the scheduling date you entered during node creation.
Cloning the rule to also affect updated content
The rule from above only works for newly created content, but we want it on updated content, too. If the date value is updated, then also a previously scheduled task with the same user provided identifier (the node id in our case) should get updated to the specified date. We will add a condition to only affect publishing dates in the future (to avoid endless rescheduling loops). You need to enable the PHP filter module from Drupal core.
- Go to triggered rules page ("admin/rules/trigger") and click on "clone" near your rule from above.
- Change the event from "After saving new content" to "After updating existent content".
- Change the label of the rule by adding something like "on updating"
- "Save changes".
- Add a condition "Numeric comparison", set Number 1 to "[node:field_publish_date-timestamp]" (the token corresponding to your date field), the Operation to "Greater than" and Number 2 to "<?php echo time(); ?>". Click "Save".
- Now go back to your already existing content and edit the date field.
- Visit the scheduling page ("admin/rules/rule_sets/scheduling") and observe the updated scheduling date of your node.
Note: Rules Scheduler saves dates in GMT/UTC internally, but displays them in your timezone setting in the scheduling list. So be aware that the content of the date field is interpreted as UTC/GMT.
Deleting scheduled tasks
If you want to remove scheduled tasks, you either can do it manually on the scheduling page, but you can also use a Rules action to do it automatically. Let's say we want to cancel/delete scheduled tasks for a node, if the node gets deleted.
- Add a new triggered rule with the event "After deleting content"
- Add an action to to this rule "Delete scheduled rule sets" from the Rules Scheduler section
- Fill out the identifier field with "node [node:nid]" (Note: only scheduled tasks with exactly the same identifier match, so be careful in assigning them)
- Leave the Rule set box empty (we want delete tasks related to any rule set) and "Save"
- Do some testing: watch a scheduled task on the scheduling page, then delete the related node, then visit the page again. The task(s) have been deleted.
Another note: Deleting scheduled tasks for nodes that do not exist anymore is not mandatory, if a task is executed on a disappeared node, it gets simply canceled by the Rules system and does not break your site.
Comments
Handling timezones
If you want to avoid timezones surprises you might find it useful to use as the Scheduled evaluation date token something like [node:field_publish_date-value] rather than [node:field_publish_date-datetime]. The latter might be transformed by a timezone setting and rules will store it as if it were GMT/UTC time thus throwing off the scheduling by whatever difference there is between the timezone and GMT.
Timezone setting ans rules scheduler can be tricky
contrary to the above post, changing between date-value and date-timestamp does not seem to have any effect on when the rule is scheduled (Rules 6.x-1.3).
In my application I set the date input format for publishing to be 12/07/2010 - 8:00am -05:00
(i.e. dates stored as utc by compensating for the site's timezone)
I left the timezone handling for the date as site's time zone.
One tricky thing - If you are going to make a rule to both new content and updated content - the updated content trigger could fire when a new node is saved if the conditions are not set correctly.
Try adding the following condition for the updated content rule:
if "updated content's field 'field_your_cck_date_field_name' has changed
This guarantees that the rule only fires if an update actually changes the values of the date field in question.
Before adding this in I was having a problem where, on newly created nodes - rules scheduler was dropping the time portion of the scheduled date because both the new content saved and the content updated rules were firing .
OG node-types - scheduling is not working
Hi there,
this scheduling is not working with OG node-types. The node is loosing it's group during publishing!!!!
Did some one solve scheduling with OG node-types?
no one did this before?
no one did this before?
How to get the identifier?
How can I use this kind of expressions: [node:field_publish_date-datetime]
In the tutorial it says you can look that up under "Replacement patterns for saved content", but I cant find it. (Using the german translation of Drupal 6)
Where can I get documentation for that?
Or is this, what you use the Token module for?
Edit: It isnt displayed because of a bug: http://drupal.org/node/390482#comment-2819634
Under ‘Creating a triggered
Under ‘Creating a triggered rule’ ‘datetime’ is used but under ‘Cloning the rule to also affect updated content’ ‘timestamp’ is used.
Is this a mistake? Ive tried both variations for ‘Cloning the rule to also affect updated content’ but it doesn't work for me while the first part of the tutorial works fine.
Thanks
EDIT-
Just realise. Updating the date of new content does work, i was updating the date events that id made before these rules.
I used ‘timestamp’ like in the tutorial.
Trouble getting rules scheduler to call my custom action
I know the custom action works and I've called it through Rules manually and it works fine. But when I schedule it, it doesn't fire off even though the ruleset gets called.
Here is my previous post about it. http://drupal.org/node/833178
Anyone have any idea why this isn't working for me?
Tom
Newbie suggestion but have
Newbie suggestion but have you run the cron?
Very good tutorial, thanks
Very good tutorial, thanks for publishing it.
I would like to see an option for condition, so that while updating content the rule get fired only if a CCK date field changed. Because currently it seems that even if I update a node changing any other information than CCK date, anyway rule is getting fired.
And it is unnecessary.
Any hint for implementing this condition?
What about the to date?
[node:field_publish_date-datetime] uses the from date. What if we want to use the to date instead?
If you look in the token
If you look in the token replacements, it shows that for the to dates you just insert a "-to-"
between your field identifier and the format you want.
e.g. [node:field_publish_date-to-datetime]
^^- notice inserted "-to-"....^^^
-to-
Using -to-datetime rules are scheduling using from value. Is this a known bug?I am actually getting returns that are datetime -1 day
I solved this by passing
+1 day, [node:field_application_date-to-datetime] Schedules an event for the day in the field at 00:00:00
Subscribing
Subscribing
How to do similar in D7/Rules 2?
I really want to do something similar with Rules 2, just unpublish content based on a CCK field - but the docs for Rules 2 are minimal and I can't work out how to do it. The component types and configuration of scheduling is confusing. Has anyone done this sort of thing in Rules 2 who could provide a similar tutorial?
Would I be able to use
Would I be able to use schedule loops with this scenario as outlined by "Tutorial 4: Publish and unpublish content regularly on some week days (scheduling loops)?" My problem is getting nodes to publish at a specific time rather than 24 hours and explained "Tutorial 2: Publish content exactly 24 hours after it was created". Considering the method outlined above will let you publish based on date and time would it be able to repeat the following week?. Please advise.
schedule publishing and unpublishing
hi,
i tried to extend this tutorial with the scheduled unpublishing of a node, but it doesn't work. I simply followed the steps above twice, with some modifications in the second one which is for unpublishing.
The only differences in the setup for unpublishing are the identifiers of course and the scheduled evaluation date in the triggered rule which says: [node:field_publish_date-to-datetime] for the unpublishing procedure.
So both triggered rules are triggered by "After saving new content". By the condition of having a certain content-type.
Any ideas why this couldn't work?
Thanks in advance,
skobe
I tested that only after
I tested that only after activate cron the node is published; is so?
rules depending by cron?
Drupal 7 with Rules 2
Please someone provide a guide on how to do this in Drupal 7 with Rules 2!
In D7 I am not getting
In D7 I am not getting "Schedule Publish content" and "Scheduled evaluation date" actions....?
-
Chintan Umarani
Drupal Developer
www.umarani.com
Here is how to schedule publish in Drupal 7
Schedule content publish using date field in Drupal 7
Creating Scheduled content type
Creating Rule Component
Creating Rule
That should do it. You can test it by creating new content. You can also check scheduled component from: admin/config/workflow/rules/schedule
at the step "Add action. And
I worked out that I simply hadn't enabled the the Scheduler Rules modules. oops.
at the step "Add action. And choose from under Rules scheduler Schedule component evaluation" I don't have this action in my list, any idea why it's not showing up?