From 8145b6647280596055a05c49dbd985dc6a586897 Mon Sep 17 00:00:00 2001 From: AL Rachels Date: Thu, 4 Jul 2024 13:49:23 -0500 Subject: [PATCH] implemented cron_task --- classes/task/cron_task.php | 59 ++++++++++++++++++++++++++++++++++++++ upgrade.txt | 2 ++ version.php | 6 ++-- view.php | 2 +- 4 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 classes/task/cron_task.php diff --git a/classes/task/cron_task.php b/classes/task/cron_task.php new file mode 100644 index 0000000..7a5a9cf --- /dev/null +++ b/classes/task/cron_task.php @@ -0,0 +1,59 @@ +. + +namespace mod_hotquestion\task; +defined('MOODLE_INTERNAL') || die(); // phpcs:ignore +use context_module; +use stdClass; + +/** + * A schedule task for hotquestion cron. + * + * @package mod_hotquestion + * @copyright 2024 AL Rachels + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class cron_task extends \core\task\scheduled_task { + + // Use the logging trait to get some nice, juicy, logging. + // Uncomment as needed, use \core\task\logging_trait;. + + /** + * Get a descriptive name for this task (shown to admins). + * + * @return string + */ + public function get_name() { + return get_string('crontask', 'mod_hotquestion'); + } + + /** + * Run hotquestion cron. + */ + public function execute() { + global $CFG; + + require_once($CFG->dirroot . '/mod/hotquestion/locallib.php'); + \hotquestion::cron(); + + // 20240704 Added to update completion state after a user adds heat or teacher adds to a students priority/grade. + $ci = new completion_info($course); + if ($cm->completion == COMPLETION_TRACKING_AUTOMATIC) { + $ci->update_state($cm, COMPLETION_UNKNOWN, null); + } + return true; + } +} diff --git a/upgrade.txt b/upgrade.txt index 81040d6..5b966b0 100644 --- a/upgrade.txt +++ b/upgrade.txt @@ -14,6 +14,8 @@ This files describes changes in the Hot Question code. === 4.2.1 === 20240701 pending +20220716 HotQuestion_892 - HotQuestion does not have a cron_task.php file. Added the + file with code for completion update_state. 20240625 HotQuestion_1255bt - Hot Question Activity Completion possible bug #97. Made a lot of changes to the completion code. See ticket for details. diff --git a/version.php b/version.php index 2ed4b1e..93fd032 100644 --- a/version.php +++ b/version.php @@ -28,10 +28,10 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024062900; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2024070400; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2021051700; // Requires Moodle 3.11 version. -$plugin->cron = 0; // Period for cron to check this module (secs). +$plugin->cron = 60; // Period for cron to check this module (secs). $plugin->component = 'mod_hotquestion'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = "4.2.1 (Build: 2024062900)"; // User-friendly version number. +$plugin->release = "4.2.1 (Build: 2024070400)"; // User-friendly version number. $plugin->supported = [311, 404]; diff --git a/view.php b/view.php index bfca1cc..1ca2597 100644 --- a/view.php +++ b/view.php @@ -98,7 +98,7 @@ $completion = new completion_info($course); $completion->set_module_viewed($cm); -// 20240701 Added to update completion state after a user post or adds heat. +// 20240701 Added to update completion state after a user posts a question. Does not work for adds heat. $ci = new completion_info($course); if ($cm->completion == COMPLETION_TRACKING_AUTOMATIC) { $ci->update_state($cm, COMPLETION_UNKNOWN, null);