Friday, November 18, 2011

How to Publish content exactly 24 hours after it was created?


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 notpublished. 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.

No comments:

Post a Comment