PHP Class CronTask, glpi

It has all necessary methods to set time schedule of the task. By default schedule is equal to original cron's: '* * * * *' that means to run specified console command every minute. Original cron syntax is supported for methods hour(), minute(), day(), month(), dayOfWeek(), cron(). By calling unique() method you can set flag for task to be unique. It means that if task already running and it's time to run it again - new instance will not be executed (warning message would be added to logs). You can combine any methods to set desired schedule. For example, if you want to run command 'import' with action 'products' and params '--updateAll=1' every day at 18:00, you need to create next task instance: $task = new CronTask('import', 'products', array('updateAll' => 1)); $task->name('Import products (daily@18:00)')->daily()->hour(18); How to add and run task see CronService class description.
Author: Vadym Stepanov ([email protected])
Afficher le fichier Open project: glpi-project/glpi Class Usage Examples

Méthodes publiques

Свойство Type Description
$dohistory From CommonDBTM
$rightname

Méthodes publiques

Méthode Description
Register ( $itemtype, $name, $frequency, $options = [] ) : boolean Register new task for plugin (called by plugin during install)
Unregister ( $plugin ) : boolean Unregister tasks for a plugin (call by glpi after uninstall)
addVolume ( $volume ) Increase the currently proccessed volume of a running task
callCron ( ) : nothing Call cron if time since last launch elapsed
callCronForce ( ) : boolean Call cron without time check
canDelete ( )
cleanDBonPurge ( )
cronCheckUpdate ( $task ) Cron job to check if a new version is available
cronCircularlogs ( $task ) Circular logs
cronGraph ( $task ) Garbage collector for cleaning graph files
cronInfo ( $name ) : array get Cron description parameter for this class
cronLogs ( $task ) Clean log cron function
cronOptimize ( $task ) Clean log cron function
cronSession ( $task ) Garbage collector for expired file session
cronTemp ( $task ) Garbage collector for cleaning tmp files
cronWatcher ( $task ) Check zombie crontask
defineTabs ( $options = [] )
dropdownFrequency ( $name, $value ) Dropdown for frequency (interval between 2 actions)
dropdownState ( $name, $value, $display = true ) : nothing Dropdown of state
end ( $retcode ) : boolean Start a task, timer, stat, log, .
getDescription ( $id ) : string Translate task description
getForbiddenActionsForMenu ( )
getForbiddenStandardMassiveAction ( )
getFromDBbyName ( $itemtype, $name ) : true Read a Crontask by its name
getModeName ( $mode ) : string Translate Mode to string
getNeedToRun ( $mode, $name = '' ) : false read the first task which need to be run by cron
getParameterDescription ( ) : string Translate task parameter description
getSearchOptions ( )
getSpecificMassiveActions ( $checkitem = NULL )
getSpecificValueToDisplay ( $field, $values, array $options = [] )
getSpecificValueToSelect ( $field, $name = '', $values = '', array $options = [] )
getStateName ( $state ) : string Translate state to string
getTypeName ( $nb )
getUsedItemtypes ( ) : array Get all itemtypes used
isDisabled ( ) : integer Give a task state
launch ( $mode, $max = 1, $name = '' ) : the Launch the need cron tasks
log ( $content ) Add a log message for a running task
processMassiveActionsForOneItemtype ( MassiveAction $ma, CommonDBTM $item, array $ids )
resetDate ( ) reset the next launch date => for a launch as soon as possible
resetState ( ) reset the current state
setVolume ( $volume ) Set the currently proccessed volume of a running task
showForm ( $ID, $options = [] ) : Nothing Print the contact form
showHistory ( ) : nothing Display list of a runned tasks
showHistoryDetail ( $logid ) : nothing Display detail of a runned task
showStatistics ( ) : nothing Display statistics of a task
signal ( $signo ) Signal handler callback
start ( ) : boolean Start a task, timer, stat, log, .

Private Methods

Méthode Description
get_lock ( ) : boolean Get a global database lock for cron
release_lock ( ) Release the global database lock

Method Details

Register() public static méthode

Register new task for plugin (called by plugin during install)
public static Register ( $itemtype, $name, $frequency, $options = [] ) : boolean
$itemtype itemtype of the plugin object
$name of the task
$frequency of execution
$options array of optional options (state, mode, allowmode, hourmin, hourmax, logs_lifetime, param, comment)
Résultat boolean for success

Unregister() public static méthode

Unregister tasks for a plugin (call by glpi after uninstall)
public static Unregister ( $plugin ) : boolean
$plugin : name of the plugin
Résultat boolean for success

addVolume() public méthode

Increase the currently proccessed volume of a running task
public addVolume ( $volume )
$volume

callCron() static public méthode

Call cron if time since last launch elapsed
static public callCron ( ) : nothing
Résultat nothing

callCronForce() static public méthode

Call cron without time check
static public callCronForce ( ) : boolean
Résultat boolean : true if launched

canDelete() static public méthode

static public canDelete ( )

cleanDBonPurge() public méthode

public cleanDBonPurge ( )

cronCheckUpdate() static public méthode

Cron job to check if a new version is available
static public cronCheckUpdate ( $task )
$task for log

cronCircularlogs() static public méthode

Circular logs
static public cronCircularlogs ( $task )
$task for log

cronGraph() static public méthode

Garbage collector for cleaning graph files
static public cronGraph ( $task )
$task for log

cronInfo() static public méthode

get Cron description parameter for this class
static public cronInfo ( $name ) : array
$name string name of the task
Résultat array of string

cronLogs() static public méthode

Clean log cron function
static public cronLogs ( $task )
$task instance of CronTask

cronOptimize() static public méthode

Clean log cron function
static public cronOptimize ( $task )
$task for log

cronSession() static public méthode

Garbage collector for expired file session
static public cronSession ( $task )
$task for log

cronTemp() static public méthode

Garbage collector for cleaning tmp files
static public cronTemp ( $task )
$task for log

cronWatcher() static public méthode

Check zombie crontask
static public cronWatcher ( $task )
$task for log

defineTabs() public méthode

public defineTabs ( $options = [] )

dropdownFrequency() public méthode

Dropdown for frequency (interval between 2 actions)
public dropdownFrequency ( $name, $value )
$name select name
$value default value (default 0)

dropdownState() static public méthode

Dropdown of state
static public dropdownState ( $name, $value, $display = true ) : nothing
$name select name
$value default value (default 0)
$display display or get string (true by default)
Résultat nothing (display)

end() public méthode

..
public end ( $retcode ) : boolean
$retcode : <0 : need to run again, 0:nothing to do, >0:ok
Résultat boolean : true if ok (not start by another)

getDescription() public méthode

Translate task description
public getDescription ( $id ) : string
$id integer ID of the crontask
Résultat string

getForbiddenActionsForMenu() static public méthode

See also: CommonGLPI::getForbiddenActionsForMenu()
static public getForbiddenActionsForMenu ( )

getForbiddenStandardMassiveAction() public méthode

getFromDBbyName() public méthode

Used by plugins to load its crontasks
public getFromDBbyName ( $itemtype, $name ) : true
$itemtype itemtype of the crontask
$name name of the task
Résultat true if succeed else false

getModeName() public static méthode

Translate Mode to string
public static getModeName ( $mode ) : string
$mode integer
Résultat string

getNeedToRun() public méthode

read the first task which need to be run by cron
public getNeedToRun ( $mode, $name = '' ) : false
$mode >0 retrieve task configured for this mode <0 retrieve task allowed for this mode (force, no time check) (default 0)
$name one specify action (default '')
Résultat false if no task to run

getParameterDescription() public méthode

Translate task parameter description
public getParameterDescription ( ) : string
Résultat string

getSearchOptions() public méthode

public getSearchOptions ( )

getSpecificMassiveActions() public méthode

See also: CommonDBTM::getSpecificMassiveActions()
public getSpecificMassiveActions ( $checkitem = NULL )

getSpecificValueToDisplay() static public méthode

static public getSpecificValueToDisplay ( $field, $values, array $options = [] )
$options array

getSpecificValueToSelect() static public méthode

static public getSpecificValueToSelect ( $field, $name = '', $values = '', array $options = [] )
$field
$name (default '')
$values (default '')
$options array array

getStateName() public static méthode

Translate state to string
public static getStateName ( $state ) : string
$state integer
Résultat string

getTypeName() static public méthode

static public getTypeName ( $nb )

getUsedItemtypes() static public méthode

Get all itemtypes used
static public getUsedItemtypes ( ) : array
Résultat array of itemtypes

isDisabled() public méthode

Give a task state
public isDisabled ( ) : integer
Résultat integer 0 : task is enabled if disable : 1: by config, 2: by system lock, 3: by plugin

launch() public static méthode

Launch the need cron tasks
public static launch ( $mode, $max = 1, $name = '' ) : the
$mode (internal/external, <0 to force)
$max number of task to launch (default 1)
$name of task to run (default '')
Résultat the name of last task launched

log() public méthode

Add a log message for a running task
public log ( $content )
$content

processMassiveActionsForOneItemtype() static public méthode

See also: CommonDBTM::processMassiveActionsForOneItemtype()
static public processMassiveActionsForOneItemtype ( MassiveAction $ma, CommonDBTM $item, array $ids )
$ma MassiveAction
$item CommonDBTM
$ids array

resetDate() public méthode

reset the next launch date => for a launch as soon as possible
public resetDate ( )

resetState() public méthode

reset the current state
public resetState ( )

setVolume() public méthode

Set the currently proccessed volume of a running task
public setVolume ( $volume )
$volume

showForm() public méthode

Print the contact form
public showForm ( $ID, $options = [] ) : Nothing
$ID integer ID of the item
$options array - target filename : where to go when done. - withtemplate boolean : template or basic item
Résultat Nothing (display)

showHistory() public méthode

Display list of a runned tasks
public showHistory ( ) : nothing
Résultat nothing

showHistoryDetail() public méthode

Display detail of a runned task
public showHistoryDetail ( $logid ) : nothing
$logid : crontasklogs_id
Résultat nothing

showStatistics() public méthode

Display statistics of a task
public showStatistics ( ) : nothing
Résultat nothing

signal() public méthode

Signal handler callback
Since: 9.1
public signal ( $signo )

start() public méthode

..
public start ( ) : boolean
Résultat boolean : true if ok (not start by another)

Property Details

$dohistory public_oe property

From CommonDBTM
public $dohistory

$rightname static_oe public_oe property

static public $rightname