Skip to content

Commit

Permalink
MDL-67947 questions: questions_in_use should ask all components
Browse files Browse the repository at this point in the history
Previously it was only checking mods.
  • Loading branch information
timhunt committed Feb 19, 2020
1 parent 59f9476 commit 2a91205
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lang/en/question.php
Expand Up @@ -283,7 +283,7 @@
$string['questionname'] = 'Question name';
$string['questionno'] = 'Question {$a}';
$string['questionsaveerror'] = 'Errors occur during saving question - ({$a})';
$string['questionsinuse'] = '(* Questions marked by an asterisk are already in use in some quizzes. These questions will not be deleted from these quizzes but only from the category list.)';
$string['questionsinuse'] = '(* Questions marked with an asterisk are used somewhere, for example in a quiz. Therefore, if you proceed, these questions will not really be deleted, they will just be hidden.)';
$string['questionsmovedto'] = 'Questions still in use moved to "{$a}" in the parent course category.';
$string['questionsrescuedfrom'] = 'Questions saved from context {$a}.';
$string['questionsrescuedfrominfo'] = 'These questions (some of which may be hidden) were saved when context {$a} was deleted because they are still used by some quizzes or other activities.';
Expand Down
40 changes: 19 additions & 21 deletions lib/questionlib.php
Expand Up @@ -119,34 +119,32 @@ 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) {
if (isset($callbacksbytype['mod'][substr($plugin, 4)])) {
continue; // Already done.
}

// 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;
}
}
}
foreach ($questionids as $questionid) {
if (!empty($function($questionid))) {
return true;
}
}
}
Expand Down

0 comments on commit 2a91205

Please sign in to comment.