diff --git a/hook.php b/hook.php index d303ac2..cb7a6e0 100644 --- a/hook.php +++ b/hook.php @@ -651,15 +651,35 @@ function plugin_headings_example($type,$ID,$withtemplate=0){ } } +/** + * Execute 1 task manage by the plugin + * + * @param $task Object of CronTask class for log / stat + * + * @return interger + * >0 : done + * <0 : to be run again (not finished) + * 0 : nothing to do + */ +function plugin_example_cron_sample_run($task) { + $task->log("Example log message"); + $task->setVolume(mt_rand(0,$task->fields['param'])); -// Cron function : name= cron_plugin_PLUGINNAME -function cron_plugin_example(){ - logInFile('example',"cron called\n"); + return 1; +} - // >0 : done - // <0 : to be run again (not finished) - // 0 : nothing to do - return 1; +/** + * Give localized information about 1 task + * + * @param $name of the task + * + * @return array of strings + */ +function plugin_example_cron_sample_info($name) { + + return array ( + 'description' => "Example cron task", // Mandatory + 'parameter' => "Example parameter"); // Optional } @@ -735,6 +755,9 @@ function plugin_example_install(){ $DB->query($query) or die("error populate glpi_plugin_example_dropdown". $DB->error()); } + + // To be called for each task the plugin manage + CronTask::Register('example', 'sample', DAY_TIMESTAMP, array('param'=>50)); return true; } diff --git a/setup.php b/setup.php index 5eaa394..1dd00a8 100755 --- a/setup.php +++ b/setup.php @@ -98,9 +98,6 @@ function plugin_init_example() { $PLUGIN_HOOKS['item_transfer']['example'] = 'plugin_item_transfer_example'; - // Cron action - $PLUGIN_HOOKS['cron']['example'] = DAY_TIMESTAMP; - //redirect appel http://localhost/glpi/index.php?redirect=plugin_example_2 (ID 2 du form) $PLUGIN_HOOKS['redirect_page']['example']="example.form.php";