diff --git a/classes/task/update_displayed_images_adhoc.php b/classes/task/update_displayed_images_adhoc.php new file mode 100644 index 00000000..ae0463b0 --- /dev/null +++ b/classes/task/update_displayed_images_adhoc.php @@ -0,0 +1,60 @@ +. + +/** + * Grid update displayed image adhoc task. + * + * @package format_grid + * @copyright 2024 G J Barnard. + * @author G J Barnard - + * {@link https://moodle.org/user/profile.php?id=442195} + * {@link https://gjbarnard.co.uk} + * @author Based on code originally written by Paul Krix and Julian Ridden. + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. + */ +namespace format_grid\task; + +/** + * Grid update displayed image adhoc task class. + * + * @package format_grid + * @copyright 2024 G J Barnard. + * @author G J Barnard - + * {@link https://moodle.org/user/profile.php?id=442195} + * {@link https://gjbarnard.co.uk} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. + */ +class update_displayed_images_adhoc extends \core\task\adhoc_task { + /** + * Run the task. + */ + public function execute() { + $trace = new \text_progress_trace(); + $courseid = $this->get_custom_data(); + self::do_update_displayed_images_task($trace, $courseid); + } + + /** + * Do the task. + * + * @param progress_trace $trace The trace object. + * @param $courseid Course id. + */ + protected static function do_update_displayed_images_task(\progress_trace $trace, $courseid) { + $trace->output('Executing Grid update displayed images adhoc task on course id ' . $courseid . '.'); + \format_grid\toolbox::update_displayed_images($courseid); + } +} diff --git a/classes/task/update_displayed_images_task.php b/classes/task/update_displayed_images_task.php new file mode 100644 index 00000000..4c0dbf68 --- /dev/null +++ b/classes/task/update_displayed_images_task.php @@ -0,0 +1,55 @@ +. + +/** + * Update displayed images task. + * + * @package format_grid + * @copyright 2024 G J Barnard. + * @author G J Barnard - + * {@link https://moodle.org/user/profile.php?id=442195} + * {@link https://gjbarnard.co.uk} + * @author Based on code originally written by Paul Krix and Julian Ridden. + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. + */ +namespace format_grid\task; + +/** + * Grid update displayed images task. + * + * @package format_grid + * @copyright 2024 G J Barnard. + * @author G J Barnard - + * {@link https://moodle.org/user/profile.php?id=442195} + * {@link https://gjbarnard.co.uk} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. + */ +class update_displayed_images_task { + /** + * Queue the tasks for each grid format course. + */ + public static function update_displayed_images() { + global $DB; + + $gridcourses = $DB->get_records('course', ['format' => 'grid'], '', 'id'); + + foreach ($gridcourses as $gridcourse) { + $task = new update_displayed_images_adhoc(); + $task->set_custom_data($gridcourse->id); + \core\task\manager::queue_adhoc_task($task); + } + } +} diff --git a/db/upgrade.php b/db/upgrade.php index 7a0f1bf3..0d7f5097 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -211,6 +211,19 @@ function xmldb_format_grid_upgrade($oldversion = 0) { upgrade_plugin_savepoint(true, 2023051001, 'format', 'grid'); } + if ($oldversion < 2023101503) { + // Has the upgrade already happened? Thus in versions for Moodle 4.1+ ? + $codebase = get_config('format_grid', 'codebase'); + if ((empty($codebase)) || ((!empty($codebase)) && ($codebase < 2024090700))) { + // No! + \format_grid\task\update_displayed_images_task::update_displayed_images(); + set_config('codebase', 2024090700, 'format_grid'); + } + + // Grid savepoint reached. + upgrade_plugin_savepoint(true, 2023101503, 'format', 'grid'); + } + // Automatic 'Purge all caches'.... purge_all_caches();