Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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 atadmin/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
- Go to
admin/rules/forms
to configuringForm events
. - Check
Enable event activation messages on forms
feature. Click onSave settings
button. - Go to
node/add
. - Click on the appropriate content type link. Rules will run cron when a page from this content type is saved or updated.
- Close by the top of the next page search for the big message box. Click on
Activate events for ********_node_form
link. - On the next page click on
Activate
button. - Go to
admin/rules/trigger/add
. - To create a new rule fill the
Label
field. The label could be anything. - Under
Event
selectRules Forms > **** node form is submitted
option. - Leave other options to their default setting.
- Click on
Save changes
button. - On the next screen click on
Add an action
link. - Under
Select an action to add:
selectPHP > Execute custom PHP code
option. - Click on
Next
button. - Type in the following PHP code into
PHP Code
field.
module_invoke_all('cron');
- Click on
Save
button. - That's it you have successful created a rule that will run cron when a content type is saved or updated.
- To test simply create an new node at
node/add
Where ***********
is the name of your content type.
Source PHP code: rickauer http://drupal.org/user/69553
Comments
Thank you
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?
I do not see where to put the
I do not see where to put the php code indicated in step 13. The rest of the steps worked.
Make sure that you have
Make sure that you have enabled the "php filter" module in admin/build/modules. In Drupal 6 it is disabled by default.
You can also use Elysia Cron
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.