Commit 887daf93 authored by Tim Hunt's avatar Tim Hunt
Browse files

MDL-67947 questions: questions_in_use should ask all components

Previously it was only checking mods.
parent 4e903321
......@@ -287,7 +287,7 @@ $string['questiondoesnotexist'] = 'This question does not exist';
$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.';
......@@ -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)) {
// 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;
This files describes API changes for code that uses the question API.
=== 3.9 ==
For years, the ..._questions_in_use callback has been the right way for plugins to
tell the core question system if questions are required. Previously this callback
only worked in mods. Now it works in all plugins.
At the same time, if you are still relying on the legacy ..._question_list_instances
callback for this, you will now get a debugging warning telling you to upgrade.
=== 3.8 ===
If you have customised the display of the question bank (using $CFG->questionbankcolumns)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment