Objective

In this tutorial we will use rules module to run cron when a content is saved or updated. This tutorial is for absolute beginners. If you consider yourself an advanced user find the README.txt file that comes with the module.

Requirements

  • Drupal 6.x
  • Rules module 6.x-1.2 or more recent.
  • Both Rules Forms support & Rules Administration UI Rules sub-modules must be activated at admin/build/modules.
  • We assume that your CCK content type is already created.

Optional

  • Token module if you want to use tokenized URL. Make sure that the Token sub-module Token actions is activated.

Steps

  1. Go to admin/rules/forms to configuring Form events.
  2. Check Enable event activation messages on forms feature. Click on Save settings button.
  3. Go to node/add.
  4. Click on the appropriate content type link. Rules will run cron when a page from this content type is saved or updated.
  5. Close by the top of the next page search for the big message box. Click on Activate events for ********_node_form link.
  6. Where *********** is the name of your content type.

  7. On the next page click on Activate button.
  8. Go to admin/rules/trigger/add.
  9. To create a new rule fill the Label field. The label could be anything.
  10. Under Event select Rules Forms > **** node form is submitted option.
  11. Leave other options to their default setting.
  12. Click on Save changes button.
  13. On the next screen click on Add an action link.
  14. Under Select an action to add: select PHP > Execute custom PHP code option.
  15. Click onNext button.
  16. Type in the following PHP code into PHP Code field.
    module_invoke_all('cron');
  17. Click on Save button.
  18. That's it you have successful created a rule that will run cron when a content type is saved or updated.
  19. To test simply create an new node at node/add

Source PHP code: rickauer http://drupal.org/user/69553

Comments

trazom’s picture

Great tutorial. Would you be so kind as to tell me what I would put into the PHP code field if I wanted, say, to update URL aliases (using pathauto and token) once new content was created?

carbonaccord’s picture

I do not see where to put the php code indicated in step 13. The rest of the steps worked.

philiplucas’s picture

Make sure that you have enabled the "php filter" module in admin/build/modules. In Drupal 6 it is disabled by default.

philiplucas’s picture

You can also use Elysia Cron module (http://drupal.org/project/elysia_cron) for managing specific cron jobs and have them run at what ever frequency you'd like. Having them run less than realtime may also take load off the server when people add and edit nodes at a high frequency.