PHP Класс 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.
Автор: Vadym Stepanov ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$dohistory From CommonDBTM
$rightname

Открытые методы

Метод Описание
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, .

Приватные методы

Метод Описание
get_lock ( ) : boolean Get a global database lock for cron
release_lock ( ) Release the global database lock

Описание методов

Register() публичный статический Метод

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)
Результат boolean for success

Unregister() публичный статический Метод

Unregister tasks for a plugin (call by glpi after uninstall)
public static Unregister ( $plugin ) : boolean
$plugin : name of the plugin
Результат boolean for success

addVolume() публичный Метод

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

callCron() статический публичный Метод

Call cron if time since last launch elapsed
static public callCron ( ) : nothing
Результат nothing

callCronForce() статический публичный Метод

Call cron without time check
static public callCronForce ( ) : boolean
Результат boolean : true if launched

canDelete() статический публичный Метод

static public canDelete ( )

cleanDBonPurge() публичный Метод

public cleanDBonPurge ( )

cronCheckUpdate() статический публичный Метод

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

cronCircularlogs() статический публичный Метод

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

cronGraph() статический публичный Метод

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

cronInfo() статический публичный Метод

get Cron description parameter for this class
static public cronInfo ( $name ) : array
$name string name of the task
Результат array of string

cronLogs() статический публичный Метод

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

cronOptimize() статический публичный Метод

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

cronSession() статический публичный Метод

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

cronTemp() статический публичный Метод

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

cronWatcher() статический публичный Метод

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

defineTabs() публичный Метод

public defineTabs ( $options = [] )

dropdownFrequency() публичный Метод

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

dropdownState() статический публичный Метод

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)
Результат nothing (display)

end() публичный Метод

..
public end ( $retcode ) : boolean
$retcode : <0 : need to run again, 0:nothing to do, >0:ok
Результат boolean : true if ok (not start by another)

getDescription() публичный Метод

Translate task description
public getDescription ( $id ) : string
$id integer ID of the crontask
Результат string

getForbiddenActionsForMenu() статический публичный Метод

См. также: CommonGLPI::getForbiddenActionsForMenu()
static public getForbiddenActionsForMenu ( )

getForbiddenStandardMassiveAction() публичный Метод

getFromDBbyName() публичный Метод

Used by plugins to load its crontasks
public getFromDBbyName ( $itemtype, $name ) : true
$itemtype itemtype of the crontask
$name name of the task
Результат true if succeed else false

getModeName() публичный статический Метод

Translate Mode to string
public static getModeName ( $mode ) : string
$mode integer
Результат string

getNeedToRun() публичный Метод

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 '')
Результат false if no task to run

getParameterDescription() публичный Метод

Translate task parameter description
public getParameterDescription ( ) : string
Результат string

getSearchOptions() публичный Метод

public getSearchOptions ( )

getSpecificMassiveActions() публичный Метод

См. также: CommonDBTM::getSpecificMassiveActions()
public getSpecificMassiveActions ( $checkitem = NULL )

getSpecificValueToDisplay() статический публичный Метод

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

getSpecificValueToSelect() статический публичный Метод

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

getStateName() публичный статический Метод

Translate state to string
public static getStateName ( $state ) : string
$state integer
Результат string

getTypeName() статический публичный Метод

static public getTypeName ( $nb )

getUsedItemtypes() статический публичный Метод

Get all itemtypes used
static public getUsedItemtypes ( ) : array
Результат array of itemtypes

isDisabled() публичный Метод

Give a task state
public isDisabled ( ) : integer
Результат integer 0 : task is enabled if disable : 1: by config, 2: by system lock, 3: by plugin

launch() публичный статический Метод

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 '')
Результат the name of last task launched

log() публичный Метод

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

processMassiveActionsForOneItemtype() статический публичный Метод

См. также: CommonDBTM::processMassiveActionsForOneItemtype()
static public processMassiveActionsForOneItemtype ( MassiveAction $ma, CommonDBTM $item, array $ids )
$ma MassiveAction
$item CommonDBTM
$ids array

resetDate() публичный Метод

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

resetState() публичный Метод

reset the current state
public resetState ( )

setVolume() публичный Метод

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

showForm() публичный Метод

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
Результат Nothing (display)

showHistory() публичный Метод

Display list of a runned tasks
public showHistory ( ) : nothing
Результат nothing

showHistoryDetail() публичный Метод

Display detail of a runned task
public showHistoryDetail ( $logid ) : nothing
$logid : crontasklogs_id
Результат nothing

showStatistics() публичный Метод

Display statistics of a task
public showStatistics ( ) : nothing
Результат nothing

signal() публичный Метод

Signal handler callback
С версии: 9.1
public signal ( $signo )

start() публичный Метод

..
public start ( ) : boolean
Результат boolean : true if ok (not start by another)

Описание свойств

$dohistory публичное свойство

From CommonDBTM
public $dohistory

$rightname статическое публичное свойство

static public $rightname