use new crontask feature

git-svn-id: https://forge.glpi-project.org/svn/example/trunk@92 349b9182-4a13-0410-896f-e5e9767dd1b3
This commit is contained in:
remicollet 2009-09-03 16:42:42 +00:00
parent c3b74fddcc
commit 15b8a6cdf8
2 changed files with 30 additions and 10 deletions

View File

@ -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 return 1;
function cron_plugin_example(){ }
logInFile('example',"cron called\n");
// >0 : done /**
// <0 : to be run again (not finished) * Give localized information about 1 task
// 0 : nothing to do *
return 1; * @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()); $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; return true;
} }

View File

@ -98,9 +98,6 @@ function plugin_init_example() {
$PLUGIN_HOOKS['item_transfer']['example'] = 'plugin_item_transfer_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) //redirect appel http://localhost/glpi/index.php?redirect=plugin_example_2 (ID 2 du form)
$PLUGIN_HOOKS['redirect_page']['example']="example.form.php"; $PLUGIN_HOOKS['redirect_page']['example']="example.form.php";