mirror of
https://github.com/pluginsGLPI/example.git
synced 2025-05-04 18:08:42 +02:00
Crontask in class
git-svn-id: https://forge.glpi-project.org/svn/example/trunk@106 349b9182-4a13-0410-896f-e5e9767dd1b3
This commit is contained in:
parent
f5c43454a7
commit
d33517ba39
41
hook.php
41
hook.php
@ -643,8 +643,8 @@ function plugin_headings_example($type,$ID,$withtemplate=0){
|
|||||||
* <0 : to be run again (not finished)
|
* <0 : to be run again (not finished)
|
||||||
* 0 : nothing to do
|
* 0 : nothing to do
|
||||||
*/
|
*/
|
||||||
function plugin_example_cron_sample_run($task) {
|
function plugin_example_cron_sample1_run($task) {
|
||||||
$task->log("Example log message");
|
$task->log("Example log message from hook");
|
||||||
$task->setVolume(mt_rand(0,$task->fields['param']));
|
$task->setVolume(mt_rand(0,$task->fields['param']));
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -661,9 +661,9 @@ function plugin_example_cron_info($name) {
|
|||||||
global $LANG;
|
global $LANG;
|
||||||
|
|
||||||
switch ($name) {
|
switch ($name) {
|
||||||
case 'sample':
|
case 'sample1':
|
||||||
return array (
|
return array (
|
||||||
'description' => $LANG['plugin_example']['test'], // Mandatory
|
'description' => $LANG['plugin_example']['test'] . " (hook)", // Mandatory
|
||||||
'parameter' => $LANG['plugin_example']['test']); // Optional
|
'parameter' => $LANG['plugin_example']['test']); // Optional
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -745,29 +745,36 @@ function plugin_example_install(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// To be called for each task the plugin manage
|
// To be called for each task the plugin manage
|
||||||
CronTask::Register('example', 'sample', DAY_TIMESTAMP, array('param'=>50));
|
// 1 task in hook.php
|
||||||
|
CronTask::Register('example', 'sample1', HOUR_TIMESTAMP*2, array('param'=>50));
|
||||||
|
// 1 task in class
|
||||||
|
CronTask::Register('example', 'sample2', DAY_TIMESTAMP, array('itemtype'=>'PluginExampleExample'));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uninstall process for plugin : need to return true if succeeded
|
// Uninstall process for plugin : need to return true if succeeded
|
||||||
function plugin_example_uninstall(){
|
function plugin_example_uninstall(){
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
if (TableExists("glpi_plugin_example")){
|
// Old version tables
|
||||||
$query="DROP TABLE `glpi_plugin_example`;";
|
if (TableExists("glpi_dropdown_plugin_example")){
|
||||||
$DB->query($query) or die("error deleting glpi_plugin_example");
|
$query="DROP TABLE `glpi_dropdown_plugin_example`;";
|
||||||
}
|
$DB->query($query) or die("error deleting glpi_dropdown_plugin_example");
|
||||||
if (TableExists("glpi_dropdown_plugin_example")){
|
}
|
||||||
|
if (TableExists("glpi_plugin_example")){
|
||||||
$query="DROP TABLE `glpi_dropdown_plugin_example`;";
|
$query="DROP TABLE `glpi_plugin_example`;";
|
||||||
$DB->query($query) or die("error deleting glpi_dropdown_plugin_example");
|
$DB->query($query) or die("error deleting glpi_plugin_example");
|
||||||
}
|
}
|
||||||
|
// Current version tables
|
||||||
|
if (TableExists("glpi_plugin_example_example")){
|
||||||
|
$query="DROP TABLE `glpi_plugin_example_example`;";
|
||||||
|
$DB->query($query) or die("error deleting glpi_plugin_example_example");
|
||||||
|
}
|
||||||
if (TableExists("glpi_plugin_example_dropdown")){
|
if (TableExists("glpi_plugin_example_dropdown")){
|
||||||
|
|
||||||
$query="DROP TABLE `glpi_plugin_example_dropdown`;";
|
$query="DROP TABLE `glpi_plugin_example_dropdown`;";
|
||||||
$DB->query($query) or die("error deleting glpi_plugin_example_dropdown");
|
$DB->query($query) or die("error deleting glpi_plugin_example_dropdown");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function plugin_example_AssignToTicket($types)
|
function plugin_example_AssignToTicket($types)
|
||||||
|
@ -76,6 +76,44 @@ class PluginExampleExample extends CommonDBTM {
|
|||||||
|
|
||||||
return $tab;
|
return $tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Give localized information about 1 task
|
||||||
|
*
|
||||||
|
* @param $name of the task
|
||||||
|
*
|
||||||
|
* @return array of strings
|
||||||
|
*/
|
||||||
|
static function cron_info($name) {
|
||||||
|
global $LANG;
|
||||||
|
|
||||||
|
switch ($name) {
|
||||||
|
case 'sample2':
|
||||||
|
return array (
|
||||||
|
'description' => $LANG['plugin_example']['test']." (class)",
|
||||||
|
'parameter' => $LANG['plugin_example']['test']);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
static function cron_sample2_run($task) {
|
||||||
|
$task->log("Example log message from class");
|
||||||
|
$task->setVolume(mt_rand(0,10));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user