This commit is contained in:
Sara Arjona 2021-11-08 15:33:46 +01:00
commit 2a22d5b077
2 changed files with 16 additions and 8 deletions

View File

@ -619,7 +619,8 @@ abstract class restore_dbops {
// Top-level category counter.
$topcats = 0;
// get categories in context (bank)
$categories = self::restore_get_question_categories($restoreid, $contextid);
$categories = self::restore_get_question_categories($restoreid, $contextid, $contextlevel);
// cache permissions if $targetcontext is found
if ($targetcontext = self::restore_find_best_target_context($categories, $courseid, $contextlevel)) {
$canmanagecategory = has_capability('moodle/question:managecategory', $targetcontext, $userid);
@ -765,8 +766,13 @@ abstract class restore_dbops {
/**
* Return one array of question_category records for
* a given restore operation and one restore context (question bank)
*
* @param string $restoreid Unique identifier of the restore operation being performed.
* @param int $contextid Context id we want question categories to be returned.
* @param int $contextlevel Context level we want to restrict the returned categories.
* @return array Question categories for the given context id and level.
*/
public static function restore_get_question_categories($restoreid, $contextid) {
public static function restore_get_question_categories($restoreid, $contextid, $contextlevel) {
global $DB;
$results = array();
@ -776,7 +782,14 @@ abstract class restore_dbops {
AND itemname = 'question_category'
AND parentitemid = ?", array($restoreid, $contextid));
foreach ($qcats as $qcat) {
$results[$qcat->itemid] = backup_controller_dbops::decode_backup_temp_info($qcat->info);
$result = backup_controller_dbops::decode_backup_temp_info($qcat->info);
// Filter out found categories that belong to another context level.
// (this can happen when a higher level category becomes remapped to
// a context id that, by coincidence, matches a context id of another
// category at lower level). See MDL-72950 for more info.
if ($result->contextlevel == $contextlevel) {
$results[$qcat->itemid] = $result;
}
}
$qcats->close();

View File

@ -47,11 +47,6 @@ class restore_attempt_test extends \advanced_testcase {
public function test_restore_question_attempts_missing_users(): void {
global $DB, $USER;
// TODO: Remove this once MDL-72950 is fixed.
if ($DB->get_dbfamily() == 'oracle') {
$this->markTestSkipped("Skipping for Oracle until MDL-72950 is fixed.");
}
$this->resetAfterTest();
$this->setAdminUser();