Tutorial 2: Publish content exactly 24 hours after it was created

Last modified: November 22, 2009 - 19:11

This tutorial will give you an example how to use the Rules Scheduler module.

Preparations

  1. At first you have to download and install the Rules module, the Views module (for displaying scheduled tasks) and the Token module.
  2. Go to "admin/build/modules" on your site and activate "Rules", "Rules Administration UI", "Rules Scheduler", "Views" and "Token" modules.

Creating a rule set as scheduling action

Now we need to create a rule set, that will be scheduled later.

  1. Go to "admin/rules/rule_sets" and click on the tab "Add a new rule set".
  2. Fill out the label for example with "Publish content {rule set}" and the machine-readable name with "publish_content".
  3. In the "Arguments" fieldset fill out the first row: select "Content" as data type, enter "Content {argument}" as the label and "publish_content__content" as the machine-readable name.
  4. Now confirm your input by clicking the "Save" button.
  5. You are redirected now to the rule sets overview page and your freshly created rule set is listed.
  6. Click on it ("Publish content {rule set}" was the name) and add a new rule by clicking the "Add new rule" tab.
  7. Fill out the label of the new rule with "Publish action {rule}" and click on "Save changes".
  8. You are now on the edit page of this rule and we want to add an action by clicking on "Add an action".
  9. You get a select box where you need to select "Node|Publish content" (NOT "Rule Set|Publish content"!) and confirm it by clicking on "Next".
  10. We leave the details of the action unchanged on the received form, because the argument is already selected correctly (we had only "Content {argument}" specified as argument), except for changing the action label from "Publish content" to "Publish content {action}" to make it easier to track.
  11. Hit "Save".

Creating a triggered rule

Our simple rule set is now completed and is ready for scheduling.

  1. To trigger it, we need to invoke it on a certain event, so we go to the triggered rules page ("admin/rules/trigger") and click on "Add a new rule".
  2. Fill out the label with "Publishing rule {triggered rule}" and select "Node|After saving new content" from the event box.
  3. Hit "Save changes" to create the rule. On the resulting page click "Add an action", where we will schedule our rule set.
  4. Select "Rule Scheduler|Schedule Publish content {rule set}" from the select box and confirm the action by clicking "Next".
  5. Now we adjust the scheduling information: Append "{action}" to the label at the top. The arguments configuration is already setup correctly ("created content" is the item we want to hand over to our "Publish content {rule set}" rule set).
  6. The fieldset "Token replacement patterns" allows you to use substitutes for example in the "Identifier" field below.
  7. We want to identify the future scheduling task somehow, so we fill out the Identifier field with "node [node:nid]" to get the node ID of the created content. An identifier is always optional, but it is useful to delete/update a specific scheduled task later by another rule.
  8. We set "Scheduled evaluation date" to "+1 day", because we want the rule set to be executed one day after the creation event. Click on "Save" to submit the form.
  9. In order to trigger this action only for unpublished content, we need to add a condition. Click on "Add a condition", select "Node|Content is published", and click on "Next" to confirm the selection.
  10. Turn the "Negate" checkbox on because we want to trigger for content that is not published. Click on "Save" to submit the form.

Testing

At this point we are ready to do a little test.

  1. Create new content (e.g. on "node/add/story") and unset the "Published" option in the "Publishing options" fieldset.
  2. After saving, go to the rule set scheduling page ("admin/rules/rule_sets/scheduling").
  3. You can see now a task entry in the task list that contains a scheduling date in 24 hours and the identifier is set to the node ID of the new content.

*_*

beautifulmind - July 16, 2009 - 09:13

I am not a critic of this method but just wanna share my ideas with the community. The same feature can be achieved with workflow module.

Regards.

page not found for scheduling

toddwoof - July 16, 2009 - 13:01

When I navigate to admin/rules/rule_sets/scheduling as instructed, I get "page not found." Is there some new path, or something else that needs to be set up to see the task entries? Thanks!

Please download the dev

mediarays - July 17, 2009 - 20:26

Please download the dev version of the rules module

it didn't work

angel07 - July 20, 2009 - 03:52

After downloading the dev version of the rules module I tried typing admin/rules/rule_sets/scheduling at the address bar and it I still get "Page not found". What should I do?

Can see the tasks now

toddwoof - July 20, 2009 - 14:20

Thanks -- the dev. version dated 17 July 2009 fixed it for me. Note: The display of data isn't quite right, but I'll post that to the project issues queue.

can this be done?

achilles085 - August 20, 2009 - 07:05

can this module do what i want?

ex.
I have a node created, which is initially unpublished state. when this node turns into published state, can this module turns the state of the node into unpublished again after 2months(60 days). What I'd like to do is i have this Listings(content type) and after the 2months period, this listing(node) will turn into unpublished state.

Badly needed your advice!

thanks

--------------------------
personal | blogspot | wp

yes it can be done!

BassPlaya - October 4, 2009 - 16:58

@ achilles085:

see http://drupal.org/node/595692

How do we use "Views" to

a.bond - August 27, 2009 - 17:49

How do we use "Views" to display scheduled tasks?

Good tutorial!

BassPlaya - October 4, 2009 - 14:14

I tried this to "unpublish a content" after a certain time (I still have to see the result, will let you guys know if it did the trick) but at some point the user might want to change the content. This update of the content does not affect the scheduling time. Would there be a way to do this? And how about when the rule is actually unpublishing my content, could the rule be set again when the content is published again in the future?

 
 

Drupal is a registered trademark of Dries Buytaert.