Skip to content

Commit f202773

Browse files
authored
Check required plugins are enabled (#32)
Some extra checks have been added to confirm the required plugins are enabled (H5P activity or H5P content bank type). Apart from that, documentation has been improved to add some reference to these requirements.
1 parent 83a0452 commit f202773

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ There are two ways to execute the activity migration:
1818

1919
Migrations tool will scan for non migrated hvp activities and will create as many H5P activities as needed.
2020

21-
By default, the CLI method will only migrate up to 100 hvp activities per execution and will keep the originals hvp in the courses. Use the option "--help" to know the CLI params to change this behavior to increase the migration limit or delete/hide the originals hvp.
21+
By default, the CLI method will only migrate up to 100 hvp activities per execution, will keep the originals hvp in the courses and will add a link to the content bank. Use the option "--help" to know the CLI params to change this behavior to increase the migration limit, delete/hide the originals hvp, decide whether to link/copy to the content bank or filter by content type.
2222

2323
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.
2424

@@ -27,7 +27,13 @@ The tool will only migrate each hvp once. In case you need to re-migrate an hvp,
2727
This tools requires both core H5P and the third party plugin (mod_hvp) installed in the system. The minimum requirements are:
2828

2929
* Moodle core 3.9: otherwise the H5P activity is not present
30-
* HVP activity 2020020500 or more: in previous versions this migraiton tool won't work
30+
* HVP activity 2020020500 or more: in previous versions this migration tool won't work
31+
* H5P core activity enabled
32+
33+
Apart from that, for adding contents to the content bank too (so it's not strictly required if contents won't be migrated to the content bank):
34+
35+
* H5P content type of the content bank enabled
36+
* Content bank repository enabled
3137

3238
## License ##
3339

classes/api.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,18 @@
3232
require_once($CFG->dirroot . '/tag/lib.php');
3333

3434
use stdClass;
35+
use repository;
3536
use stored_file;
3637
use context_user;
3738
use core_tag_tag;
3839
use context_course;
3940
use context_module;
4041
use completion_info;
4142
use moodle_exception;
43+
use core_plugin_manager;
4244
use core\output\notification;
4345
use mod_h5pactivity\local\attempt;
4446
use core_competency\api as competencyapi;
45-
use repository;
4647
use tool_migratehvp2h5p\event\hvp_migrated;
4748
/**
4849
* Class containing helper methods for processing mod_hvp migrations.
@@ -83,6 +84,8 @@ public static function migrate_hvp2h5p(int $hvpid, int $keeporiginal = self::KEE
8384
int $copy2cb = self::COPY2CBYESWITHLINK): array {
8485
global $DB;
8586

87+
self::check_requirements($copy2cb);
88+
8689
$messages = [];
8790
$transaction = $DB->start_delegated_transaction();
8891

@@ -153,6 +156,26 @@ public static function migrate_hvp2h5p(int $hvpid, int $keeporiginal = self::KEE
153156
return $messages;
154157
}
155158

159+
/**
160+
* Check minimum requirements for the migration tool are met, such as the H5P activity enabled.
161+
* An exception will be thrown if some of the requirements are not met.
162+
*
163+
* @param int $copy2cb Whether H5P files should be added to the content bank or not.
164+
* @return void
165+
* @throws moodle_exception if some requirement is not met.
166+
*/
167+
public static function check_requirements(int $copy2cb) {
168+
$plugins = core_plugin_manager::instance()->get_enabled_plugins('mod');
169+
if (!array_key_exists('h5pactivity', $plugins)) {
170+
throw new moodle_exception('error_modh5pactivity_disabled', 'tool_migratehvp2h5p');
171+
}
172+
173+
$contentbanktypes = core_plugin_manager::instance()->get_enabled_plugins('contenttype');
174+
if ($copy2cb != self::COPY2CBNO && !array_key_exists('h5p', $contentbanktypes)) {
175+
throw new moodle_exception('error_contenttypeh5p_disabled', 'tool_migratehvp2h5p');
176+
}
177+
}
178+
156179
/**
157180
* Return the SQL to select the hvp activies pending to migrate.
158181
*

index.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@
6666
$notices[] = [$errormsg, notification::NOTIFY_ERROR];
6767
}
6868
}
69+
} else {
70+
try {
71+
api::check_requirements($copy2cb);
72+
} catch (moodle_exception $e) {
73+
$notices[] = [$e->getMessage(), notification::NOTIFY_ERROR];
74+
}
6975
}
7076

7177
$PAGE->set_context($context);

lang/en/tool_migratehvp2h5p.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,18 @@
3232
$string['copy2cb_yeswithlink'] = 'Yes, and a link to these files should be used in the activity';
3333
$string['copy2cb_yeswithoutlink'] = 'Yes, but a copy will be used in the activity (changes in the content bank won\'t be reflected in the activity)';
3434
$string['copy2cb_no'] = 'No, they should be only created in the activity.';
35+
$string['error_contenttypeh5p_disabled'] = "H5P contentbank type is disabled. It must be enabled to migrate activities from mod_hvp
36+
and add them to the content bank too. You can enable this contentytype from 'Site administration | Plugins | Content bank | Manage
37+
content types' or run again the migration tool and select 'No, they should be only created in the activity.' (or 'copy2cb=0' if
38+
you're running CLI) to avoid creating files in content bank.";
39+
$string['error_modh5pactivity_disabled'] = 'H5P activity is disabled. It must be enabled to migrate activities from mod_hvp';
3540
$string['event_hvp_migrated'] = 'mod_hvp migrated to mod_h5pactivity';
3641
$string['graded'] = 'Graded users';
3742
$string['hvpactivities'] = 'Pending mod_hvp activities';
3843
$string['id'] = 'Id';
3944
$string['migrate'] = 'Migrate';
4045
$string['migrate_success'] = 'Hvp activity with id {$a} migrated successfully';
41-
$string['migrate_fail'] = 'Error migration hvp activity with id {$a}';
46+
$string['migrate_fail'] = 'Error migrating hvp activity with id {$a}';
4247
$string['migrate_gradesoverridden'] = 'Original mod_hvp activity "{$a->name}", with id {$a->id}, migrated successfully. However,
4348
it has some grading information overridden, such as feedback, which hasn\'t been migrated because the original activity is
4449
configured with an invalid maximum grade (it has to be higher than 0 in order to be migrated to the gradebook).';

0 commit comments

Comments
 (0)