Merge branch 'MDL-84695-main' of https://github.com/lucaboesch/moodle into main
This commit is contained in:
@@ -529,11 +529,13 @@ class question_bank_helper {
|
||||
$sql = "SELECT cm.id
|
||||
FROM {course_modules} cm
|
||||
JOIN {modules} m ON m.id = cm.module
|
||||
JOIN {{$defaultyactivityname}} q ON q.id = cm.instance AND cm.module = m.id
|
||||
JOIN {{$defaultyactivityname}} q ON q.id = cm.instance
|
||||
WHERE cm.course = :course
|
||||
AND q.type = :type";
|
||||
AND q.type = :type
|
||||
AND m.name = :modulename";
|
||||
|
||||
return $DB->get_fieldset_sql($sql, ['type' => $subtype, 'course' => $course->id]);
|
||||
return $DB->get_fieldset_sql($sql, ['type' => $subtype, 'course' => $course->id,
|
||||
'modulename' => $defaultyactivityname]);
|
||||
}
|
||||
|
||||
return [];
|
||||
|
||||
@@ -407,6 +407,10 @@ final class question_bank_helper_test extends \advanced_testcase {
|
||||
self::setAdminUser();
|
||||
|
||||
$course = self::getDataGenerator()->create_course();
|
||||
// Create module other than a qbank.
|
||||
$wiki = self::getDataGenerator()->create_module('wiki', [
|
||||
'course' => $course->id,
|
||||
]);
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
$qbanks = $modinfo->get_instances_of('qbank');
|
||||
$this->assertCount(0, $qbanks);
|
||||
@@ -416,6 +420,18 @@ final class question_bank_helper_test extends \advanced_testcase {
|
||||
$this->assertEquals(get_string('systembank', 'question'), $qbank->get_name());
|
||||
$modrecord = $DB->get_record('qbank', ['id' => $qbank->instance]);
|
||||
$this->assertEquals(question_bank_helper::TYPE_SYSTEM, $modrecord->type);
|
||||
// Swap the qbank instance record for one with the same ID as the wiki instance.
|
||||
$newqbank = clone($modrecord);
|
||||
$newqbank->id = $wiki->id;
|
||||
$DB->insert_record_raw('qbank', $newqbank, customsequence: true);
|
||||
$DB->delete_records('qbank', ['id' => $qbank->id]);
|
||||
$DB->set_field('course_modules', 'instance', $newqbank->id, ['instance' => $qbank->instance]);
|
||||
// Retry the above again.
|
||||
\course_modinfo::purge_course_caches([$course->id]);
|
||||
$qbank = question_bank_helper::get_default_open_instance_system_type($course);
|
||||
$this->assertEquals(get_string('systembank', 'question'), $qbank->get_name());
|
||||
$modrecord = $DB->get_record('qbank', ['id' => $qbank->instance]);
|
||||
$this->assertEquals(question_bank_helper::TYPE_SYSTEM, $modrecord->type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user