Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

Scheduled task abstract class.

Copyright: 2013 Damyon Wiese
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 573 lines (17 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: scheduled_task  - X-Ref

Abstract class defining a scheduled task.

get_last_run_time()   X-Ref
Get the last run time for this scheduled task.

return: int

set_last_run_time($lastruntime)   X-Ref
Set the last run time for this scheduled task.

param: int $lastruntime

is_customised()   X-Ref
Has this task been changed from it's default config?

return: bool

set_customised($customised)   X-Ref
Has this task been changed from it's default config?

param: bool

is_overridden()   X-Ref
Has this task been changed from it's default config?

return: bool

set_overridden(bool $overridden)   X-Ref
Set the overridden value.

param: bool $overridden

set_minute($minute, $expandr = true)   X-Ref
Setter for $minute. Accepts a special 'R' value
which will be translated to a random minute.

param: string $minute
param: bool $expandr - if true (default) an 'R' value in a time is expanded to an appropriate int.

get_minute()   X-Ref
Getter for $minute.

return: string

set_hour($hour, $expandr = true)   X-Ref
Setter for $hour. Accepts a special 'R' value
which will be translated to a random hour.

param: string $hour
param: bool $expandr - if true (default) an 'R' value in a time is expanded to an appropriate int.

get_hour()   X-Ref
Getter for $hour.

return: string

set_month($month)   X-Ref
Setter for $month.

param: string $month

get_month()   X-Ref
Getter for $month.

return: string

set_day($day)   X-Ref
Setter for $day.

param: string $day

get_day()   X-Ref
Getter for $day.

return: string

set_day_of_week($dayofweek, $expandr = true)   X-Ref
Setter for $dayofweek.

param: string $dayofweek
param: bool $expandr - if true (default) an 'R' value in a time is expanded to an appropriate int.

get_day_of_week()   X-Ref
Getter for $dayofweek.

return: string

set_disabled($disabled)   X-Ref
Setter for $disabled.

param: bool $disabled

get_disabled()   X-Ref
Getter for $disabled.

return: bool

get_run_if_component_disabled()   X-Ref
Override this function if you want this scheduled task to run, even if the component is disabled.

return: bool

is_valid(string $field)   X-Ref
Informs whether the given field is valid.
Use the constants FIELD_* to identify the field.
Have to be called after the method set_{field}(string).

return: bool true if given field is valid. false otherwise.
param: string $field field identifier; expected values from constants FIELD_*.

get_valid(string $field)   X-Ref
Calculates the list of valid values according to the given field and stored expression.

return: array(int) list of matching values.
param: string $field field identifier. Must be one of those FIELD_*.

eval_cron_field($field, $min, $max)   X-Ref
Take a cron field definition and return an array of valid numbers with the range min-max.

return: array(int)
param: string $field - The field definition.
param: int $min - The minimum allowable value.
param: int $max - The maximum allowable value.

next_in_list($current, $list)   X-Ref
Assuming $list is an ordered list of items, this function returns the item
in the list that is greater than or equal to the current value (or 0). If
no value is greater than or equal, this will return the first valid item in the list.
If list is empty, this function will return 0.

return: int $next.
param: int $current The current value
param: int[] $list The list of valid items.

get_next_scheduled_time()   X-Ref
Calculate when this task should next be run based on the schedule.

return: int $nextruntime.

can_run()   X-Ref
Informs whether this task can be run.

return: bool true when this task can be run. false otherwise.

is_enabled()   X-Ref
Checks whether the component and the task disabled flag enables to run this task.
This do not checks whether the task manager allows running them or if the
site allows tasks to "run now".

return: bool true if task is enabled. false otherwise.

get_html_id(string $classname)   X-Ref
Produces a valid id string to use as id attribute based on the given FQCN class name.

return: string valid string to be used as id attribute.
param: string $classname FQCN of a task.