|
32 | 32 | require_once($CFG->dirroot . '/tag/lib.php'); |
33 | 33 |
|
34 | 34 | use stdClass; |
| 35 | +use repository; |
35 | 36 | use stored_file; |
36 | 37 | use context_user; |
37 | 38 | use core_tag_tag; |
38 | 39 | use context_course; |
39 | 40 | use context_module; |
40 | 41 | use completion_info; |
41 | 42 | use moodle_exception; |
| 43 | +use core_plugin_manager; |
42 | 44 | use core\output\notification; |
43 | 45 | use mod_h5pactivity\local\attempt; |
44 | 46 | use core_competency\api as competencyapi; |
45 | | -use repository; |
46 | 47 | use tool_migratehvp2h5p\event\hvp_migrated; |
47 | 48 | /** |
48 | 49 | * Class containing helper methods for processing mod_hvp migrations. |
@@ -83,6 +84,8 @@ public static function migrate_hvp2h5p(int $hvpid, int $keeporiginal = self::KEE |
83 | 84 | int $copy2cb = self::COPY2CBYESWITHLINK): array { |
84 | 85 | global $DB; |
85 | 86 |
|
| 87 | + self::check_requirements($copy2cb); |
| 88 | + |
86 | 89 | $messages = []; |
87 | 90 | $transaction = $DB->start_delegated_transaction(); |
88 | 91 |
|
@@ -153,6 +156,26 @@ public static function migrate_hvp2h5p(int $hvpid, int $keeporiginal = self::KEE |
153 | 156 | return $messages; |
154 | 157 | } |
155 | 158 |
|
| 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 | + |
156 | 179 | /** |
157 | 180 | * Return the SQL to select the hvp activies pending to migrate. |
158 | 181 | * |
|
0 commit comments