MDL-67947 questions: questions_in_use should ask all components

Previously it was only checking mods.
This commit is contained in:
Tim Hunt 2020-02-13 16:09:33 +00:00
parent 4e90332195
commit 887daf932c
3 changed files with 32 additions and 22 deletions

View file

@ -119,34 +119,35 @@ function question_save_qtype_order($neworder, $config = null) {
* @return boolean whether any of these questions are being used by any part of Moodle.
*/
function questions_in_use($questionids) {
global $CFG;
// Are they used by the core question system?
if (question_engine::questions_in_use($questionids)) {
return true;
}
foreach (core_component::get_plugin_list('mod') as $module => $path) {
$lib = $path . '/lib.php';
if (is_readable($lib)) {
include_once($lib);
// Check if any plugins are using these questions.
$callbacksbytype = get_plugins_with_function('questions_in_use');
foreach ($callbacksbytype as $callbacks) {
foreach ($callbacks as $function) {
if ($function($questionids)) {
return true;
}
}
}
$fn = $module . '_questions_in_use';
if (function_exists($fn)) {
if ($fn($questionids)) {
return true;
}
} else {
// Finally check legacy callback.
$legacycallbacks = get_plugin_list_with_function('mod', 'question_list_instances');
foreach ($legacycallbacks as $plugin => $function) {
debugging($plugin . ' implements deprecated method ' . $function .
'. ' . $plugin . '_questions_in_use should be implemented instead.', DEBUG_DEVELOPER);
// Fallback for legacy modules.
$fn = $module . '_question_list_instances';
if (function_exists($fn)) {
foreach ($questionids as $questionid) {
$instances = $fn($questionid);
if (!empty($instances)) {
return true;
}
}
}
if (isset($callbacksbytype['mod'][substr($plugin, 4)])) {
continue; // Already done.
}
foreach ($questionids as $questionid) {
if (!empty($function($questionid))) {
return true;
}
}
}