Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 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: 656 lines (22 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).

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

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

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

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.

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

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.

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

get_next_scheduled_time(int $now = 0)   X-Ref
Calculate when this task should next be run based on the schedule.

param: int $now Current time, for testing (leave 0 to use default time)
return: int $nextruntime.

get_next_scheduled_time_inner(int $now, array $validminutes, array $validhours,array $validdays, array $validdaysofweek, array $validmonths, int $originalyear = 0)   X-Ref
Recursively calculate the next valid time for this task.

param: int $now Start time
param: array $validminutes Valid minutes
param: array $validhours Valid hours
param: array $validdays Valid days
param: array $validdaysofweek Valid days of week
param: array $validmonths Valid months
param: int $originalyear Zero for first call, original year for recursive calls
return: int Next run time

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.

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