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])
Exibir arquivo Open project: glpi-project/glpi Class Usage Examples

Public Properties

Property Type Description
$dohistory From CommonDBTM
$rightname

Public Methods

Method 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

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

Method Details

Register() public static method

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)
return boolean for success

Unregister() public static method

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

addVolume() public method

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

callCron() static public method

Call cron if time since last launch elapsed
static public callCron ( ) : nothing
return nothing

callCronForce() static public method

Call cron without time check
static public callCronForce ( ) : boolean
return boolean : true if launched

canDelete() static public method

static public canDelete ( )

cleanDBonPurge() public method

public cleanDBonPurge ( )

cronCheckUpdate() static public method

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

cronCircularlogs() static public method

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

cronGraph() static public method

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

cronInfo() static public method

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

cronLogs() static public method

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

cronOptimize() static public method

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

cronSession() static public method

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

cronTemp() static public method

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

cronWatcher() static public method

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

defineTabs() public method

public defineTabs ( $options = [] )

dropdownFrequency() public method

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

dropdownState() static public method

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)
return nothing (display)

end() public method

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

getDescription() public method

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

getForbiddenActionsForMenu() static public method

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

getForbiddenStandardMassiveAction() public method

getFromDBbyName() public method

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

getModeName() public static method

Translate Mode to string
public static getModeName ( $mode ) : string
$mode integer
return string

getNeedToRun() public method

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 '')
return false if no task to run

getParameterDescription() public method

Translate task parameter description
public getParameterDescription ( ) : string
return string

getSearchOptions() public method

public getSearchOptions ( )

getSpecificMassiveActions() public method

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

getSpecificValueToDisplay() static public method

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

getSpecificValueToSelect() static public method

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

getStateName() public static method

Translate state to string
public static getStateName ( $state ) : string
$state integer
return string

getTypeName() static public method

static public getTypeName ( $nb )

getUsedItemtypes() static public method

Get all itemtypes used
static public getUsedItemtypes ( ) : array
return array of itemtypes

isDisabled() public method

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

launch() public static method

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 '')
return the name of last task launched

log() public method

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

processMassiveActionsForOneItemtype() static public method

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

resetDate() public method

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

resetState() public method

reset the current state
public resetState ( )

setVolume() public method

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

showForm() public method

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
return Nothing (display)

showHistory() public method

Display list of a runned tasks
public showHistory ( ) : nothing
return nothing

showHistoryDetail() public method

Display detail of a runned task
public showHistoryDetail ( $logid ) : nothing
$logid : crontasklogs_id
return nothing

showStatistics() public method

Display statistics of a task
public showStatistics ( ) : nothing
return nothing

signal() public method

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

start() public method

..
public start ( ) : boolean
return 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