Skip to content

Commit

Permalink
Check required plugins are enabled (#32)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sarjona authored Feb 4, 2021
1 parent 83a0452 commit f202773
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ There are two ways to execute the activity migration:

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

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

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.

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

* Moodle core 3.9: otherwise the H5P activity is not present
* HVP activity 2020020500 or more: in previous versions this migraiton tool won't work
* HVP activity 2020020500 or more: in previous versions this migration tool won't work
* H5P core activity enabled

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):

* H5P content type of the content bank enabled
* Content bank repository enabled

## License ##

Expand Down
25 changes: 24 additions & 1 deletion classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@
require_once($CFG->dirroot . '/tag/lib.php');

use stdClass;
use repository;
use stored_file;
use context_user;
use core_tag_tag;
use context_course;
use context_module;
use completion_info;
use moodle_exception;
use core_plugin_manager;
use core\output\notification;
use mod_h5pactivity\local\attempt;
use core_competency\api as competencyapi;
use repository;
use tool_migratehvp2h5p\event\hvp_migrated;
/**
* Class containing helper methods for processing mod_hvp migrations.
Expand Down Expand Up @@ -83,6 +84,8 @@ public static function migrate_hvp2h5p(int $hvpid, int $keeporiginal = self::KEE
int $copy2cb = self::COPY2CBYESWITHLINK): array {
global $DB;

self::check_requirements($copy2cb);

$messages = [];
$transaction = $DB->start_delegated_transaction();

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

/**
* Check minimum requirements for the migration tool are met, such as the H5P activity enabled.
* An exception will be thrown if some of the requirements are not met.
*
* @param int $copy2cb Whether H5P files should be added to the content bank or not.
* @return void
* @throws moodle_exception if some requirement is not met.
*/
public static function check_requirements(int $copy2cb) {
$plugins = core_plugin_manager::instance()->get_enabled_plugins('mod');
if (!array_key_exists('h5pactivity', $plugins)) {
throw new moodle_exception('error_modh5pactivity_disabled', 'tool_migratehvp2h5p');
}

$contentbanktypes = core_plugin_manager::instance()->get_enabled_plugins('contenttype');
if ($copy2cb != self::COPY2CBNO && !array_key_exists('h5p', $contentbanktypes)) {
throw new moodle_exception('error_contenttypeh5p_disabled', 'tool_migratehvp2h5p');
}
}

/**
* Return the SQL to select the hvp activies pending to migrate.
*
Expand Down
6 changes: 6 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
$notices[] = [$errormsg, notification::NOTIFY_ERROR];
}
}
} else {
try {
api::check_requirements($copy2cb);
} catch (moodle_exception $e) {
$notices[] = [$e->getMessage(), notification::NOTIFY_ERROR];
}
}

$PAGE->set_context($context);
Expand Down
7 changes: 6 additions & 1 deletion lang/en/tool_migratehvp2h5p.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@
$string['copy2cb_yeswithlink'] = 'Yes, and a link to these files should be used in the activity';
$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)';
$string['copy2cb_no'] = 'No, they should be only created in the activity.';
$string['error_contenttypeh5p_disabled'] = "H5P contentbank type is disabled. It must be enabled to migrate activities from mod_hvp
and add them to the content bank too. You can enable this contentytype from 'Site administration | Plugins | Content bank | Manage
content types' or run again the migration tool and select 'No, they should be only created in the activity.' (or 'copy2cb=0' if
you're running CLI) to avoid creating files in content bank.";
$string['error_modh5pactivity_disabled'] = 'H5P activity is disabled. It must be enabled to migrate activities from mod_hvp';
$string['event_hvp_migrated'] = 'mod_hvp migrated to mod_h5pactivity';
$string['graded'] = 'Graded users';
$string['hvpactivities'] = 'Pending mod_hvp activities';
$string['id'] = 'Id';
$string['migrate'] = 'Migrate';
$string['migrate_success'] = 'Hvp activity with id {$a} migrated successfully';
$string['migrate_fail'] = 'Error migration hvp activity with id {$a}';
$string['migrate_fail'] = 'Error migrating hvp activity with id {$a}';
$string['migrate_gradesoverridden'] = 'Original mod_hvp activity "{$a->name}", with id {$a->id}, migrated successfully. However,
it has some grading information overridden, such as feedback, which hasn\'t been migrated because the original activity is
configured with an invalid maximum grade (it has to be higher than 0 in order to be migrated to the gradebook).';
Expand Down

0 comments on commit f202773

Please sign in to comment.