diff --git a/mod/assign/classes/task/cron_task.php b/mod/assign/classes/task/cron_task.php new file mode 100644 index 00000000000..f962197f6fc --- /dev/null +++ b/mod/assign/classes/task/cron_task.php @@ -0,0 +1,69 @@ +. + +namespace mod_assign\task; +defined('MOODLE_INTERNAL') || die(); + +/** + * A schedule task for assignment cron. + * + * @package mod_assign + * @copyright 2019 Simey Lameze + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class cron_task extends \core\task\scheduled_task { + /** + * Get a descriptive name for this task (shown to admins). + * + * @return string + */ + public function get_name() { + return get_string('crontask', 'mod_assign'); + } + + /** + * Run assignment cron. + */ + public function execute() { + global $CFG; + + require_once($CFG->dirroot . '/mod/assign/locallib.php'); + \assign::cron(); + + $plugins = \core_component::get_plugin_list('assignsubmission'); + + foreach ($plugins as $name => $plugin) { + $disabled = get_config('assignsubmission_' . $name, 'disabled'); + if (!$disabled) { + $class = 'assign_submission_' . $name; + require_once($CFG->dirroot . '/mod/assign/submission/' . $name . '/locallib.php'); + $class::cron(); + } + } + $plugins = \core_component::get_plugin_list('assignfeedback'); + + foreach ($plugins as $name => $plugin) { + $disabled = get_config('assignfeedback_' . $name, 'disabled'); + if (!$disabled) { + $class = 'assign_feedback_' . $name; + require_once($CFG->dirroot . '/mod/assign/feedback/' . $name . '/locallib.php'); + $class::cron(); + } + } + + return true; + } +} diff --git a/mod/assign/db/tasks.php b/mod/assign/db/tasks.php new file mode 100644 index 00000000000..d13e143899f --- /dev/null +++ b/mod/assign/db/tasks.php @@ -0,0 +1,34 @@ +. +/** + * Definition of assignment scheduled tasks. + * + * @package mod_assign + * @copyright 2019 Simey Lameze + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +defined('MOODLE_INTERNAL') || die(); +$tasks = array( + array( + 'classname' => '\mod_assign\task\cron_task', + 'blocking' => 0, + 'minute' => '*', + 'hour' => '*', + 'day' => '*', + 'month' => '*', + 'dayofweek' => '*' + ) +); diff --git a/mod/assign/lang/en/assign.php b/mod/assign/lang/en/assign.php index b61ddada062..3c5fed394d6 100644 --- a/mod/assign/lang/en/assign.php +++ b/mod/assign/lang/en/assign.php @@ -130,6 +130,7 @@ $string['couldnotconvertsubmission'] = 'Could not convert assignment submission $string['couldnotcreatecoursemodule'] = 'Could not create course module.'; $string['couldnotcreatenewassignmentinstance'] = 'Could not create new assignment instance.'; $string['couldnotfindassignmenttoupgrade'] = 'Could not find old assignment instance to upgrade.'; +$string['crontask'] = 'Background processing for assignment module'; $string['currentgrade'] = 'Current grade in gradebook'; $string['currentattempt'] = 'This is attempt {$a}.'; $string['currentattemptof'] = 'This is attempt {$a->attemptnumber} ( {$a->maxattempts} attempts allowed ).'; diff --git a/mod/assign/lib.php b/mod/assign/lib.php index 158f7b54822..6f0d59b2994 100644 --- a/mod/assign/lib.php +++ b/mod/assign/lib.php @@ -1257,39 +1257,6 @@ function assign_get_post_actions() { return array('upload', 'submit', 'submit for grading'); } -/** - * Call cron on the assign module. - */ -function assign_cron() { - global $CFG; - - require_once($CFG->dirroot . '/mod/assign/locallib.php'); - assign::cron(); - - $plugins = core_component::get_plugin_list('assignsubmission'); - - foreach ($plugins as $name => $plugin) { - $disabled = get_config('assignsubmission_' . $name, 'disabled'); - if (!$disabled) { - $class = 'assign_submission_' . $name; - require_once($CFG->dirroot . '/mod/assign/submission/' . $name . '/locallib.php'); - $class::cron(); - } - } - $plugins = core_component::get_plugin_list('assignfeedback'); - - foreach ($plugins as $name => $plugin) { - $disabled = get_config('assignfeedback_' . $name, 'disabled'); - if (!$disabled) { - $class = 'assign_feedback_' . $name; - require_once($CFG->dirroot . '/mod/assign/feedback/' . $name . '/locallib.php'); - $class::cron(); - } - } - - return true; -} - /** * Returns all other capabilities used by this module. * @return array Array of capability strings diff --git a/mod/assign/version.php b/mod/assign/version.php index 9dc333ff16f..68b0b47449e 100644 --- a/mod/assign/version.php +++ b/mod/assign/version.php @@ -25,6 +25,5 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'mod_assign'; // Full name of the plugin (used for diagnostics). -$plugin->version = 2018122000; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2018122001; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2018112800; // Requires this Moodle version. -$plugin->cron = 60;