From 88db9f847c630fd293fb6545e112810157e74fe9 Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Mon, 20 Jan 2025 17:50:32 +0100 Subject: [PATCH] New release 0.1.7 Also: - Improve markdown - Fix coding style --- CHANGES.md | 40 +++++++++++++++----------- README.md | 9 +++--- classes/api.php | 22 +++++++------- classes/event/hvp_migrated.php | 5 ++-- classes/output/hvpactivities_table.php | 18 ++++++------ classes/output/listnotmigrated.php | 4 +-- tests/author_test.php | 2 +- 7 files changed, 53 insertions(+), 47 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 48c788c..79a9db6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,42 +1,48 @@ -# VERSIONS HISTORY # +# VERSIONS HISTORY + +## Changes in version 0.1.7 (20250120) - I'm still alive + +- Add Moodle 4.4 and 4.5 support +- Replace deprecated calls +- Improve markdown and fix coding style + +## Changes in version 0.1.6 (20240111) - RIP master -Changes in version 0.1.6 (20240111) - RIP master ---------------------------------------------------- - Move from master to main (#51) - Bump GHA environments -Changes in version 0.1.5 (20221129) - I'm now stable! ---------------------------------------------------- +## Changes in version 0.1.5 (20221129) - I'm now stable + - Include author, if possible, when migrating to content bank (#46) - Fix SQL limit with Oracle (#34) Thanks to Jonathan Harker from Catalyst and all the contributors who have created issues, fixes and improvements. -Changes in version 0.1.4 (20210204) - Let's make it better! ---------------------------------------------------- +## Changes in version 0.1.4 (20210204) - Let's make it better + - Copy completion information related to grades too (#27) - Check if contentbank repository is enabled or not (#30) - Check required plugins are enabled (#32) - Create manually CB file when it is null (#25) - Other fixes and improvements: - * Add GitHub action support (#22) + - Add GitHub action support (#22) Thanks to Jordan, Ramon Ovelar, Adrian Perez and all the contributors who have created issues, fixes and improvements. -Changes in version 0.1.3 (2020121100) - Hurray project week! ---------------------------------------------------- +## Changes in version 0.1.3 (2020121100) - Hurray project week + - Let admins copy files to content bank too (#11) - Migrate depending on a subset of content-types (#19) - Allow async module deletes (#14) - Other fixes and improvements: - * Set grade type to None when maxgrade is 0 (#7) - * Rawscore and maxscore can not be null (#8) + - Set grade type to None when maxgrade is 0 (#7) + - Rawscore and maxscore can not be null (#8) Thanks to Eric Merrill, GaRaOne and Alexander Bias and all the contributors who have created issues, fixes and improvements. -Changes in version 0.1.2 (2020062400) - Welcome Beta ---------------------------------------------------- +## Changes in version 0.1.2 (2020062400) - Welcome Beta + - Some migration errors fixes: - * Use "enable skipping" from the competency API to avoid migration failed error (#1) - * Set contextid properly in event trigger (#3) - * Replace wrong table name and hardcoded prefix + - Use "enable skipping" from the competency API to avoid migration failed error (#1) + - Set contextid properly in event trigger (#3) + - Replace wrong table name and hardcoded prefix diff --git a/README.md b/README.md index a3b37ff..6aed25f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ -# Migrate mod_hvp to mod_h5pactivity # +# Migrate mod_hvp to mod_h5pactivity [![Moodle Plugin CI](https://github.com/moodlehq/moodle-tool_migratehvp2h5p/actions/workflows/ci.yml/badge.svg)](https://github.com/moodlehq/moodle-tool_migratehvp2h5p/actions/workflows/ci.yml) - Moodle plugin allowing to migrate activities created with the mod_hvp plugin created by Joubel to the new mod_h5pactivity created by Moodle HQ since Moodle 3.9. Some limitations to consider before using this plugin: @@ -10,7 +9,7 @@ Some limitations to consider before using this plugin: * Currently it's still not possible to save the current status with the mod_h5pactivity. The mod_hvp supports it (although it's disabled by default) so, before migrating the activities, consider students might loose these unfinished attempts. * The new mod_h5pactivity hasn't any global settings to define the default behaviour so general settings defined in mod_hvp, such as the default display options or whether to use or not the hub, are not migrated. -# How to use this tool # +## How to use this tool There are two ways to execute the activity migration: @@ -23,7 +22,7 @@ By default, the CLI method will only migrate up to 100 hvp activities per execut The tool will only migrate each hvp once. In case you need to re-migrate an hvp, just remove or rename the migrated h5p activity, this way the tool won't detect the hvp as migrated. -# Tool dependencies # +## Tool dependencies This tools requires both core H5P and the third party plugin (mod_hvp) installed in the system. The minimum requirements are: @@ -36,7 +35,7 @@ Apart from that, for adding contents to the content bank too (so it's not strict * H5P content type of the content bank enabled * Content bank repository enabled -## License ## +### License This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software diff --git a/classes/api.php b/classes/api.php index afae01c..1b58149 100644 --- a/classes/api.php +++ b/classes/api.php @@ -53,22 +53,22 @@ */ class api { - /** @var value to indicate the original hvp activity must be deleted after migration */ + /** @var int Value to indicate the original hvp activity must be deleted after migration */ public const DELETEORIGINAL = 0; - /** @var value to indicate to keep the original hvp activity after migration */ + /** @var int Value to indicate to keep the original hvp activity after migration */ public const KEEPORIGINAL = 1; - /** @var value to indicate to hide the original hvp activity after migration */ + /** @var int Value to indicate to hide the original hvp activity after migration */ public const HIDEORIGINAL = 2; - /** @var value to indicate the original hvp activity must not be copied to content bank. */ + /** @var int Value to indicate the original hvp activity must not be copied to content bank. */ public const COPY2CBNO = 0; - /** @var value to indicate the original hvp activity must be copied to content bank and then linked to the new activity. */ + /** @var int Value to indicate the original hvp activity must be copied to content bank and then linked to the new activity. */ public const COPY2CBYESWITHLINK = 1; - /** @var value to indicate the original hvp activity must be copied to content bank too. */ + /** @var int Value to indicate the original hvp activity must be copied to content bank too. */ public const COPY2CBYESWITHOUTLINK = 2; /** @@ -353,7 +353,7 @@ private static function create_mod_h5pactivity(stdClass $hvp, stdClass $hvpgrade $h5pactivity->gradeitem = self::duplicate_grade_item($hvpgradeitem, $h5pactivity); // Update couse_module information. - $h5pcm = self::add_course_module_to_section($hvpcm, $h5pactivity->cm->id); + self::add_course_module_to_section($hvpcm, $h5pactivity->cm->id); self::copy_tags($hvpcm, $h5pactivity); self::copy_competencies($hvpcm, $h5pactivity); @@ -663,18 +663,18 @@ private static function duplicate_course_module(stdClass $cm, int $moduleid): st * * @param stdClass $hvpcm * @param int $h5pcmid - * @return stdClass The course module object for the h5pactivity. + * @return stdClass|null The course module object for the h5pactivity. */ - private static function add_course_module_to_section(stdClass $hvpcm, int $h5pcmid): stdClass { + private static function add_course_module_to_section(stdClass $hvpcm, int $h5pcmid): ?stdClass { global $DB; $h5pcm = get_coursemodule_from_id('', $h5pcmid, $hvpcm->course); if (!$h5pcm) { - return false; + return null; } $section = $DB->get_record('course_sections', ['id' => $h5pcm->section]); if (!$section) { - return false; + return null; } $h5pcm->section = course_add_cm_to_section($h5pcm->course, $h5pcm->id, $section->section, $hvpcm->id); diff --git a/classes/event/hvp_migrated.php b/classes/event/hvp_migrated.php index eb1825a..ceaf908 100644 --- a/classes/event/hvp_migrated.php +++ b/classes/event/hvp_migrated.php @@ -24,6 +24,7 @@ namespace tool_migratehvp2h5p\event; +use stdClass; use core\event\base; /** @@ -67,7 +68,7 @@ public static function get_name() { * Create event from record. * * @param stdClass $record - * @return acceptance_created + * @return hvp_migrated */ public static function create_from_record($record) { $event = static::create([ @@ -119,7 +120,7 @@ protected function validate_data() { /** * No mapping required for this event because this event is not backed up. * - * @return bool + * @return array */ public static function get_other_mapping() { $othermapped = [ diff --git a/classes/output/hvpactivities_table.php b/classes/output/hvpactivities_table.php index 033602a..866c33c 100644 --- a/classes/output/hvpactivities_table.php +++ b/classes/output/hvpactivities_table.php @@ -88,11 +88,11 @@ protected function define_table_columns() { $this->define_columns(array_keys($columnheaders)); $this->define_headers(array_values($columnheaders)); - $this->column_class('id', 'd-none d-sm-table-cell'); - $this->column_class('contenttype', 'd-none d-sm-table-cell'); - $this->column_class('graded', 'd-none d-md-table-cell'); - $this->column_class('attempted', 'd-none d-md-table-cell'); - $this->column_class('savedstate', 'd-none d-md-table-cell'); + $this->column_class(array_search('id', $columnheaders), 'd-none d-sm-table-cell'); + $this->column_class(array_search('contenttype', $columnheaders), 'd-none d-sm-table-cell'); + $this->column_class(array_search('graded', $columnheaders), 'd-none d-md-table-cell'); + $this->column_class(array_search('attempted', $columnheaders), 'd-none d-md-table-cell'); + $this->column_class(array_search('savedstate', $columnheaders), 'd-none d-md-table-cell'); } /** @@ -114,7 +114,7 @@ protected function define_table_configs() { * @param stdClass $data The row data. * @return string * @throws \moodle_exception - * @throws coding_exception + * @throws \coding_exception */ public function col_select(stdClass $data):string { global $OUTPUT; @@ -139,7 +139,7 @@ public function col_select(stdClass $data):string { * @param stdClass $data The row data. * @return string * @throws \moodle_exception - * @throws coding_exception + * @throws \coding_exception */ public function col_graded(stdClass $data): string { global $DB; @@ -158,7 +158,7 @@ public function col_graded(stdClass $data): string { * @param stdClass $data The row data. * @return string * @throws \moodle_exception - * @throws coding_exception + * @throws \coding_exception */ public function col_attempted(stdClass $data): string { global $DB; @@ -177,7 +177,7 @@ public function col_attempted(stdClass $data): string { * @param stdClass $data The row data. * @return string * @throws \moodle_exception - * @throws coding_exception + * @throws \coding_exception */ public function col_name(stdClass $data): string { $url = new moodle_url('/mod/hvp/view.php', ['id' => $data->instanceid]); diff --git a/classes/output/listnotmigrated.php b/classes/output/listnotmigrated.php index 821580a..0f0b703 100644 --- a/classes/output/listnotmigrated.php +++ b/classes/output/listnotmigrated.php @@ -40,13 +40,13 @@ */ class listnotmigrated implements renderable, templatable { - /** @var data_requests_table $table The data requests table. */ + /** @var \tool_migratehvp2h5p\output\hvpactivities_table $table The data requests table. */ protected $table; /** * Contructor. * - * @param hvpactivities_table $table The data requests table. + * @param \tool_migratehvp2h5p\output\hvpactivities_table $table The data requests table. */ public function __construct(\tool_migratehvp2h5p\output\hvpactivities_table $table) { $this->table = $table; diff --git a/tests/author_test.php b/tests/author_test.php index 7094cb4..1d1eb9a 100644 --- a/tests/author_test.php +++ b/tests/author_test.php @@ -51,7 +51,7 @@ private function fake_hvp(stdClass $course): stdClass { if (empty($this->modid)) { $mod = $DB->get_record('modules', [ 'name' => 'hvp' ], '*', IGNORE_MISSING); if (empty($mod)) { - $this->fail("The 'mod_hvp' plugin must be installed for these tests to succeed."); + throw new \moodle_exception("The 'mod_hvp' plugin must be installed for these tests to succeed."); } $this->modid = $mod->id; }