diff --git a/backup/moodle2/restore_hvp_stepslib.php b/backup/moodle2/restore_hvp_stepslib.php index 263b3724..e751f1c9 100644 --- a/backup/moodle2/restore_hvp_stepslib.php +++ b/backup/moodle2/restore_hvp_stepslib.php @@ -202,6 +202,24 @@ protected function process_hvp_library($data) { $libraryid = self::get_library_id($data); if (!$libraryid) { + // If this library is not installed, ensure that the user has + // permission to install it before proceeding. + $params = ['machine_name' => $data->machine_name]; + if (!$DB->record_exists('hvp_libraries', $params)) { + $systemctx = \core\context\system::instance(); + $caninstall = has_capability('mod/hvp:updatelibraries', $systemctx); + + $librarycache = $DB->get_record('hvp_libraries_hub_cache', $params, 'id, is_recommended'); + if ($librarycache && $librarycache->is_recommended) { + $coursectx = \core\context\course::instance($this->get_courseid()); + $caninstall = $caninstall || has_capability('mod/hvp:installrecommendedh5plibraries', $coursectx); + } + + if (!$caninstall) { + throw new \core\exception\moodle_exception('restoreinstalldenied', 'hvp', '', $data->title); + } + } + // There is no updating of libraries. If an older patch version exists // on the site that one will be used instead of the new one in the backup. // This is due to the default behavior when files are restored in Moodle. diff --git a/lang/en/hvp.php b/lang/en/hvp.php index c6331c77..e104dac0 100644 --- a/lang/en/hvp.php +++ b/lang/en/hvp.php @@ -694,3 +694,6 @@ // Export libraries. $string['exportlibraries'] = 'Export libraries'; $string['exportlibrarieserror'] = 'An error occured while export the libraries.'; + +// Restore H5P library. +$string['restoreinstalldenied'] = 'You do not have permission to install missing content type \'{$a}\'. Please contact your site administrator.'; diff --git a/version.php b/version.php index c8a9b9c0..67d02f57 100644 --- a/version.php +++ b/version.php @@ -23,7 +23,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024120900; +$plugin->version = 2024120901; $plugin->requires = 2022112800; // 4.1.0 $plugin->cron = 0; $plugin->component = 'mod_hvp';