Drupal Association members fund grants that make connections all over the world.
This tutorial will give you an example how to use the Rules Scheduler module.
We want to have our content published on Mondays and unpublished on the rest of the week. The content should be published between Monday 00:00 and 24:00. When the content is created, we would like to have it automatically published/unpublished, depending on the current day (publish immediately on Monday, keep it unpublished on other week days). We will create two rule sets that do the (un)publishing and schedule each other. Furthermore we will create two rules as triggers that react on content creation events, one for Mondays and one for the other days.
Please note that scheduled rule sets calling each other can cause infinite loop series. This is useful in many cases, but may also cause trouble and confusion if you do not intend to have a never-ending loop.
Same as in Tutorial 2 plus activation of the PHP filter module (core module) to make use of PHP input evaluators.
Creating rule sets as scheduling actions
- We can re-use the rule set from Tutorial 2, so refer to that example above if you haven't created it yet.
- Additionally we need a rule set with an "Unpublish content" action, create it the same way as the first one and replace "publish" with "unpublish".
- we need to extend both rule sets now by adding an action for re-scheduling each other
- Go to the rule sets page ("admin/rules/rule_sets") and click on the first rule set to edit it ("Publish content")
- Click on the rule ("Publish action") to edit
- Click on "Add an action" and select "Schedule Unpublish content" (the name of your unpublishing rule set)
- Set the identifier to "node [node:nid]"
- Set the execution date to "next Tuesday" and hit "Save"
- Now you have to do quite the same for the "Unpublish content" rule set, where the action is "Schedule Publish content" and the execution date "next Monday"
Creating triggered rules
Now we need two triggered rules to do the initial scheduling when content is created, depending on what day the content has been created.
- The process is very similar to the one in Tutorial 2
- Label the first rule "Monday publishing" and the second "Rest week unpublishing"
- The event is in both cases "After saving new content"
- Add a condition to check the creation date, choose "Numeric comparison", label it "Current day must be Monday" and fill the number 1 field with "<?php echo gmdate('w') ?>" and the number 2 field with "1" (for the "Monday publishing" rule). (Explanation: gmdate('w') returns the current day of the week by numbers from 0-6, 0 = Sunday, 1 = Monday, ... , 6 = Saturday)
- Similar condition for the "Rest week unpublishing rule": label it "Current day must not be Monday" and set number 1 and 2 to the same as before, but check the "negate" box this time.
- Now add an action to "Monday publishing": Select the rule set "Publish content" that will do the publishing and scheduling to unpublish the node.
- Same thing for "Rest week unpublishing": Select the rule set "Unpublish content"to do the opposite.
- You may also add a condition to only affect content of a certain content type (as in Tutorial 3).
Same as with the other tutorials - create some content and have a look at the scheduling page ("admin/rules/rule_sets/scheduling").