CronTasks extends AppModel
Cron Task management
Table of Contents
Methods
| __construct() | Initialize Cron Tasks |
| add() | Adds a new cron task |
| addTaskRun() | Sets when a cron task should run for a given company |
| deleteTask() | Deletes a cron task |
| deleteTaskRun() | Deletes when a cron task should run for the given company. |
| edit() | Edits a cron task |
| editTaskRun() | Updates when a cron task should run for the given company |
| get() | Retrieves a cron task |
| getAll() | Retrieves a list of all cron tasks in the system |
| getAllTaskRun() | Retrieves a list of all cron tasks and their company-specific run settings for this company |
| getByKey() | Retrieves a cron task |
| getTaskRun() | Retrieves a cron task and its company-specific run settings |
| getTaskRunByKey() | Retrieves a cron task and its company-specific run settings |
| getTaskTypes() | Retrieves a list of the task types and their language |
| getAllTaskRuns() | Partially constructs a Record object for queries required by both CronTasks::getAllTaskRun() and CronTasks::deleteTaskRun() |
| getRules() | Retrieves the rules for adding/editing cron tasks |
| getTaskRunRules() | Retrieves the rules for adding/editing cron task runs |
| setLanguage() | Sets the real name and description values, including language defines, for the given task by reference |
| setTaskFields() | Updates the given task to set additional fields to the object, such as language and module/plugin information |
Methods
__construct()
Initialize Cron Tasks
public
__construct() : mixed
add()
Adds a new cron task
public
add(array<string|int, mixed> $vars) : mixed
Parameters
- $vars : array<string|int, mixed>
-
An array of key=>value fields including:
- key A unique key representing this cron task
- task_type The type of cron task this represents (system, module, or plugin)
- dir The directory this cron task belongs to (optional)
- name The name of this cron task
- description The description of this cron task (optional)
- is_lang 1 if name and description are language definitions in the language file, 0 otherwise (optional, default 0)
- type The type of cron task this is ("time" or "interval" based, optional, default "interval")
Return values
mixed —The cron task ID created, or void on error
addTaskRun()
Sets when a cron task should run for a given company
public
addTaskRun(int $task_id, array<string|int, mixed> $vars) : mixed
Parameters
- $task_id : int
-
The cron task ID associated with this runnable task
- $vars : array<string|int, mixed>
-
A list of key=>value fields to add, including:
- time The daily 24-hour time that this task should run (e.g. "14:25", optional, required if interval is not given)
- interval The interval, in minutes, that this cron task should run (optional, required if time is not given)
- enabled 1 if this cron task is enabled, 0 otherwise (optional, default 1)
Return values
mixed —The cron task run ID created, or void on error
deleteTask()
Deletes a cron task
public
deleteTask(int $task_id, string $task_type, string $dir) : mixed
Parameters
- $task_id : int
-
The ID of the cron task to delete
- $task_type : string
-
The task's task_type (i.e., 'plugin', or 'module')
- $dir : string
-
The directory this cron task belongs to
deleteTaskRun()
Deletes when a cron task should run for the given company.
public
deleteTaskRun(int $task_run_id) : mixed
NOTE: This will also delete the cron task itself iff the cron task is no longer used by any other company and this cron task is related to a plugin
Parameters
- $task_run_id : int
-
The cron task run ID
edit()
Edits a cron task
public
edit(int $task_id, array<string|int, mixed> $vars) : mixed
Parameters
- $task_id : int
-
The cron task ID to edit
- $vars : array<string|int, mixed>
-
A list of key=>value fields to update, including:
- name The name of this cron task
- description The description of this cron task (optional)
- is_lang 1 if name and description are language definitions in the language file, 0 otherwise (optional, default 0)
editTaskRun()
Updates when a cron task should run for the given company
public
editTaskRun(int $task_run_id, array<string|int, mixed> $vars) : mixed
Parameters
- $task_run_id : int
-
The cron task run ID
- $vars : array<string|int, mixed>
-
A list of key=>value fields to update, including:
- time The daily 24-hour time that this task should run (e.g. "14:25", optional, required if interval is not given)
- interval The interval, in minutes, that this cron task should run (optional, required if time is not given)
- enabled 1 if this cron task is enabled, 0 otherwise (optional, default 1)
get()
Retrieves a cron task
public
get(int $id) : mixed
Parameters
- $id : int
-
The cron task ID
Return values
mixed —An stdClass object representing the cron task, or false if it does not exist
getAll()
Retrieves a list of all cron tasks in the system
public
getAll() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of stdClass objects representing each cron task
getAllTaskRun()
Retrieves a list of all cron tasks and their company-specific run settings for this company
public
getAllTaskRun([bool $system = false ][, string $task_type = 'all' ][, string $dir = null ]) : array<string|int, mixed>
Parameters
- $system : bool = false
-
True to fetch only system cron tasks, false to fetch company cron tasks (default false)
- $task_type : string = 'all'
-
The type of task to fetch (i.e. 'system', 'plugin', 'module', or 'all' for any, default 'all')
- $dir : string = null
-
The directory this cron task belongs to iff $task_type is 'plugin' or 'module' (optional)
Return values
array<string|int, mixed> —A list of stdClass objects representing each cron task, or an empty array if none exist
getByKey()
Retrieves a cron task
public
getByKey(string $key[, string $plugin_dir = null ][, string $task_type = 'plugin' ]) : mixed
Parameters
- $key : string
-
The cron task key
- $plugin_dir : string = null
-
The plugin directory of the plugin this cron task belongs to OR if $task_type is given, the directory that this cron task belongs to, plugin or not
- $task_type : string = 'plugin'
-
The type of task to fetch (one of 'system', 'plugin', or 'module'), default 'plugin' for backward compatibility
Return values
mixed —An stdClass object representing the cron task, or false if it does not exist
getTaskRun()
Retrieves a cron task and its company-specific run settings
public
getTaskRun(int $task_run_id[, bool $system = false ]) : mixed
Parameters
- $task_run_id : int
-
The cron task run ID
- $system : bool = false
-
True to fetch only system cron tasks, false to fetch company cron tasks (default false)
Return values
mixed —An stdClass object representing the runnable cron task, or false if one does not exist
getTaskRunByKey()
Retrieves a cron task and its company-specific run settings
public
getTaskRunByKey(string $key[, string $plugin_dir = null ][, bool $system = false ][, string $task_type = 'plugin' ]) : mixed
Parameters
- $key : string
-
The cron task key
- $plugin_dir : string = null
-
The plugin directory of the plugin this cron task belongs to OR if $task_type is given, the directory that this cron task belongs to, plugin or not (default null)
- $system : bool = false
-
True to fetch only system cron tasks, false to fetch company cron tasks (default false)
- $task_type : string = 'plugin'
-
The type of task to fetch (one of 'system', 'plugin', or 'module'), (default 'plugin' for backward compatibility)
Return values
mixed —An stdClass object representing the runnable cron task, or false if one does not exist
getTaskTypes()
Retrieves a list of the task types and their language
public
getTaskTypes() : array<string|int, mixed>
Return values
array<string|int, mixed> —A key/value list of task types and their language
getAllTaskRuns()
Partially constructs a Record object for queries required by both CronTasks::getAllTaskRun() and CronTasks::deleteTaskRun()
private
getAllTaskRuns() : Record
Return values
Record —The partially constructed query Record object
getRules()
Retrieves the rules for adding/editing cron tasks
private
getRules(array<string|int, mixed> $vars[, bool $edit = false ]) : array<string|int, mixed>
Parameters
- $vars : array<string|int, mixed>
-
A list of input fields
- $edit : bool = false
-
True for edit rules, false for add rules (optional, default false)
Return values
array<string|int, mixed> —A list of rules
getTaskRunRules()
Retrieves the rules for adding/editing cron task runs
private
getTaskRunRules(array<string|int, mixed> $vars[, bool $edit = false ]) : array<string|int, mixed>
Parameters
- $vars : array<string|int, mixed>
-
A list of input fields
- $edit : bool = false
-
Trtue for edit rules, false for add rules (optional, default false)
Return values
array<string|int, mixed> —A list of rules
setLanguage()
Sets the real name and description values, including language defines, for the given task by reference
private
setLanguage(stdClass &$task) : mixed
Parameters
- $task : stdClass
-
A cron task object containing:
- name The name of the cron task
- description The description of the cron task
- is_lang 1 if the name and description are language definitions, or 0 otherwise
setTaskFields()
Updates the given task to set additional fields to the object, such as language and module/plugin information
private
setTaskFields(stdClass $task[, bool $set_plugin_fields = false ]) : stdClass
Parameters
- $task : stdClass
-
An stdClass object representing a single cron task
- $set_plugin_fields : bool = false
-
True to include plugin fields as a part of the task, or false otherwise (default false)
Return values
stdClass —The updated task object