Hotaru Docs

 [həʊdɒks]

Plugin Cron Jobs

Cron is a plugin that was developed for Hotaru CMS. It mimics the cron function of unix by running jobs at regular intervals when your site is accessed.

Adding a new cron job from within your plugin

To add or update a cron job from within your plugin you can call cron as follows:

$timestamp = time();
$recurrence = "daily";
$hook = "SystemInfo:hotaru_feedback";
$cron_data = array('timestamp'=>$timestamp, 'recurrence'=>$recurrence, 'hook'=>$hook);
$h->pluginHook('cron_update_job', 'cron', $cron_data);

In this example: 1. a timestamp is set to mark the current time

2. the recurrence of the job is set to daily

3. the hook is the code function that will run at the $recurrence interval. There are 2 types of $hook that can be set

a) function_name_of_a_plugin (This is the most common way to set $hook)

b) hotaru_class:function_from_that_class )Note the use of the ':' to join the class name to the function from that class.

examples: $hook = "hotaru_feedback"; $hook = "SystemInfo:hotaru_feedback";

4. The $cron_data variable sets the 3 above criteria ready.

5. The $h->PluginHook('cron_update_job','cron',$cron_data); sets the cron job into the plugin hook. If you want to update a job use 'cron_update_job'. If you want to delete a job use 'cron_delete_job'

Deleting an existing cron job from within your plugin

$hook = "SystemInfo:hotaru_feedback";
$cron_data = array('hook'=>$hook);
$h->pluginHook('cron_delete_job', 'cron', $cron_data);

Note, if the cron job does not exist, no action will be taken.

Parameters

$recurrence: hourly, daily, weekly

cron_update_job - for new or update existing jobs cron_delete_job - for deleting jobs