1
0
mirror of https://github.com/moodle/moodle.git synced 2025-04-24 09:55:33 +02:00

Merge branch 'MDL-76193-401' of https://github.com/JBThong/moodle into MOODLE_401_STABLE

This commit is contained in:
Sara Arjona 2022-12-07 17:26:22 +01:00
commit 151de4586d
3 changed files with 50 additions and 0 deletions

@ -5293,6 +5293,7 @@ class restore_move_module_questions_categories extends restore_execution_step {
AND parentitemid = ?", array($this->get_restoreid(), $contextid));
$top = question_get_top_category($newcontext->newitemid, true);
$oldtopid = 0;
$categoryids = [];
foreach ($modulecats as $modulecat) {
// Before 3.5, question categories could be created at top level.
// From 3.5 onwards, all question categories should be a child of a special category called the "top" category.
@ -5308,6 +5309,7 @@ class restore_move_module_questions_categories extends restore_execution_step {
$cat->parent = $top->id;
}
$DB->update_record('question_categories', $cat);
$categoryids[] = (int)$cat->id;
}
// And set new contextid (and maybe update newitemid) also in question_category mapping (will be
@ -5316,6 +5318,30 @@ class restore_move_module_questions_categories extends restore_execution_step {
$modulecat->newitemid, $newcontext->newitemid);
}
// Update the context id of any tags applied to any questions in these categories.
if ($categoryids) {
[$categorysql, $categoryidparams] = $DB->get_in_or_equal($categoryids, SQL_PARAMS_NAMED);
$sqlupdate = "UPDATE {tag_instance}
SET contextid = :newcontext
WHERE component = :component
AND itemtype = :itemtype
AND itemid IN (SELECT DISTINCT bi.newitemid as questionid
FROM {backup_ids_temp} bi
JOIN {question} q ON q.id = bi.newitemid
JOIN {question_versions} qv ON qv.questionid = q.id
JOIN {question_bank_entries} qbe ON qbe.id = qv.questionbankentryid
WHERE bi.backupid = :backupid AND bi.itemname = 'question_created'
AND qbe.questioncategoryid {$categorysql}) ";
$params = [
'newcontext' => $newcontext->newitemid,
'component' => 'core_question',
'itemtype' => 'question',
'backupid' => $this->get_restoreid(),
];
$params += $categoryidparams;
$DB->execute($sqlupdate, $params);
}
// Now set the parent id for the question categories that were in the top category in the course context
// and have been moved now.
if ($oldtopid) {

@ -0,0 +1,24 @@
@core @core_backup
Feature: Backup and restore of the question that was tagged
Background:
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
@javascript @_file_upload
Scenario: Restore the quiz containing the question that was tagged
Given I am on the "Course 1" "restore" page logged in as "admin"
And I press "Manage backup files"
And I upload "backup/moodle2/tests/fixtures/test_tags_backup.mbz" file to "Files" filemanager
And I press "Save changes"
And I restore "test_tags_backup.mbz" backup into a new course using this options:
| Schema | Course name | Course 2 |
| Schema | Course short name | C2 |
When I am on the "TF1" "core_question > edit" page logged in as admin
And I expand all fieldsets
Then I should see "Tag1-TF1"
And I should see "Tag2-TF1"
And I am on the "TF2" "core_question > edit" page logged in as admin
And I expand all fieldsets
And I should see "Tag1-TF2"

Binary file not shown.