mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +02:00
MDL-70230 admin: add setting sched. task status
When defining settings that are used by scheduled tasks, it is also useful, or even needed, to know the status of that scheduled task to have the whole big picture of that part of the system. Based on the admin_setting_description, this new setting reports its name, its status, a link to the configuration. When adding a new setting of this type, the user can add an extra description field to complete the whole meaning.
This commit is contained in:
parent
411150a424
commit
9c4510a358
7 changed files with 171 additions and 8 deletions
|
@ -429,6 +429,33 @@ abstract class scheduled_task extends task_base {
|
|||
return $nexttime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Informs whether this task can be run.
|
||||
* @return bool true when this task can be run. false otherwise.
|
||||
*/
|
||||
public function can_run(): bool {
|
||||
return $this->is_component_enabled() || $this->get_run_if_component_disabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function is_enabled(): bool {
|
||||
return $this->can_run() && !$this->get_disabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static function get_html_id(string $classname): string {
|
||||
return str_replace('\\', '-', ltrim($classname, '\\'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a descriptive name for this task (shown to admins).
|
||||
*
|
||||
|
|
|
@ -208,4 +208,13 @@ abstract class task_base {
|
|||
public function get_pid() {
|
||||
return $this->pid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Informs whether the task's component is enabled.
|
||||
* @return bool true when enabled. false otherwise.
|
||||
*/
|
||||
public function is_component_enabled(): bool {
|
||||
$plugininfo = \core_plugin_manager::instance()->get_plugin_info($this->get_component());
|
||||
return $plugininfo && $plugininfo->is_enabled();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue