wiki:Drupal HowTo Write Cron Tasks for CiviCRM

Version 4 (modified by Richard Bramley, 10 years ago) ( diff )

--

Drupal 'cron' and CiviCRM tasks

Certain things in CiviCRM need to happen on an automated basis. The most straightforward way of acheiving this is via drupal's fake cron process, which is well documented on the drupal site. Our drupal cron configuration is set to run hourly, and is triggered when the timer exceeds that limit AND a page somewhere on the drupal site is accessed.

To create a Drupal cron task, implement a cron hook function in a Drupal module. This should be called {MODULE_NAME}_cron(). To ensure that CiviCRM is correctly initialised, the method should first run the function

civicrm_initialize();

GENVASC 'mark as available' activity

The code is located in the genvasc_labels module and uses the CiviCRM API. The process is as follows:

  1. Select all the cases for the

Note regarding Cron System

By default, the activities and entries created by automated jobs in this way are assigned to whichever user triggered the cron job, in a similar way to the user who accesses an API call in a module being assigned to the results of that API call.

However, for an automated process this isn't what we want, because cron jobs will be assigned to whichever user happens to be logged in at the time the job is triggered. Instead, the LCBRU module creates a CiviCRM contact called 'Cron System' (LCBRU Staff sub-type), and all the functions and activities performed by cron tasks should be explicitly assigned to that specific contact ID. This will require the cron job to look up the Cron System in order to obtain the correct contact ID.

Note: See TracWiki for help on using the wiki.