Merge branch 'MDL-68981-master' of https://github.com/HuongNV13/moodle

This commit is contained in:
Jun Pataleta 2022-11-30 11:53:34 +08:00 committed by Ilya Tregubov
commit bc0c11a191
5 changed files with 60 additions and 22 deletions

View File

@ -243,6 +243,16 @@ class category_bin extends base_bin {
throw new \moodle_exception("Could not create course to restore into.");
}
// As far as recycle bin is using MODE_AUTOMATED, it observes the General restore settings.
// For recycle bin we want to ensure that backup files are always restore the users and groups information.
// In order to achieve that, we hack the setting here via $CFG->forced_plugin_settings,
// so it won't interfere other operations.
// See MDL-65218 and MDL-35773 for more information.
// This hack will be removed once recycle bin switches to use its own backup mode, with
// own preferences and 100% separate from MOODLE_AUTOMATED.
// TODO: Remove this as part of MDL-65228.
$CFG->forced_plugin_settings['restore'] = ['restore_general_users' => 1, 'restore_general_groups' => 1];
// Define the import.
$controller = new \restore_controller(
$tempdir,
@ -277,6 +287,10 @@ class category_bin extends base_bin {
// Run the import.
$controller->execute_plan();
// We don't need the forced setting anymore, hence unsetting it.
// TODO: Remove this as part of MDL-65228.
unset($CFG->forced_plugin_settings['restore']);
// Have finished with the controller, let's destroy it, freeing mem and resources.
$controller->destroy();

View File

@ -234,6 +234,16 @@ class course_bin extends base_bin {
$fb = get_file_packer('application/vnd.moodle.backup');
$fb->extract_to_pathname($file, $fulltempdir);
// As far as recycle bin is using MODE_AUTOMATED, it observes the General restore settings.
// For recycle bin we want to ensure that backup files are always restore the users and groups information.
// In order to achieve that, we hack the setting here via $CFG->forced_plugin_settings,
// so it won't interfere other operations.
// See MDL-65218 and MDL-35773 for more information.
// This hack will be removed once recycle bin switches to use its own backup mode, with
// own preferences and 100% separate from MOODLE_AUTOMATED.
// TODO: Remove this as part of MDL-65228.
$CFG->forced_plugin_settings['restore'] = ['restore_general_users' => 1, 'restore_general_groups' => 1];
// Define the import.
$controller = new \restore_controller(
$tempdir,
@ -264,6 +274,10 @@ class course_bin extends base_bin {
// Run the import.
$controller->execute_plan();
// We don't need the forced setting anymore, hence unsetting it.
// TODO: Remove this as part of MDL-65228.
unset($CFG->forced_plugin_settings['restore']);
// Have finished with the controller, let's destroy it, freeing mem and resources.
$controller->destroy();

View File

@ -22,35 +22,30 @@ Feature: Backup user data
And the following "activities" exist:
| activity | course | section | name | intro |
| quiz | C1 | 1 | Quiz 1 | Test quiz description |
And the following "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "questions" exist:
| questioncategory | qtype | name | questiontext |
| Test questions | truefalse | TF1 | First question |
| Test questions | truefalse | TF2 | Second question |
And quiz "Quiz 1" contains the following questions:
| question | page |
| TF1 | 1 |
| TF2 | 1 |
@javascript
Scenario: Delete and restore a quiz with user data
Given I am on the "Quiz 1" "quiz activity" page logged in as teacher1
And I add a "True/False" question to the "Quiz 1" quiz with:
| Question name | TF1 |
| Question text | First question |
| General feedback | Thank you, this is the general feedback |
| Correct answer | False |
| Feedback for the response 'True'. | So you think it is true |
| Feedback for the response 'False'. | So you think it is false |
And I add a "True/False" question to the "Quiz 1" quiz with:
| Question name | TF2 |
| Question text | Second question |
| General feedback | Thank you, this is the general feedback |
| Correct answer | False |
| Feedback for the response 'True'. | So you think it is true |
| Feedback for the response 'False'. | So you think it is false |
And I set the field "maxgrade" to "10.0"
And I press "savechanges"
And I log out
When I am on the "Quiz 1" "quiz activity" page logged in as student1
Scenario Outline: Delete and restore a quiz with user data
Given the following config values are set as admin:
| restore_general_users | <include_user> | restore |
And I am on the "Quiz 1" "quiz activity" page logged in as student1
And I press "Attempt quiz"
And I click on "True" "radio" in the "First question" "question"
And I click on "False" "radio" in the "Second question" "question"
And I press "Finish attempt"
And I press "Submit all and finish"
And I click on "Submit" "button" in the "Submit all your answers and finish?" "dialogue"
And I should see "5.00 out of 10.00"
And I should see "50.00 out of 100.00"
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
@ -63,5 +58,10 @@ Feature: Backup user data
And I log in as "student1"
And I am on "Course 1" course homepage
When I navigate to "User report" in the course gradebook
Then "Quiz 1" row "Grade" column of "user-grade" table should contain "5"
Then "Quiz 1" row "Grade" column of "user-grade" table should contain "50"
And "Quiz 1" row "Percentage" column of "user-grade" table should contain "50"
Examples:
| include_user | case_explanation |
| 1 | Checked |
| 1 | Unchecked |

View File

@ -190,6 +190,11 @@ class category_bin_test extends \advanced_testcase {
(object)['plugin' => 'backup', 'name' => 'backup_auto_storage', 'value' => 2],
(object)['plugin' => 'backup', 'name' => 'backup_auto_destination', 'value' => true],
]],
'restore/restore_general_users moodle' => [[
(object)['plugin' => 'restore', 'name' => 'restore_general_users', 'value' => 0],
(object)['plugin' => 'restore', 'name' => 'restore_general_groups', 'value' => 0],
]],
];
}

View File

@ -187,6 +187,11 @@ class course_bin_test extends \advanced_testcase {
(object)['plugin' => 'backup', 'name' => 'backup_auto_storage', 'value' => 2],
(object)['plugin' => 'backup', 'name' => 'backup_auto_destination', 'value' => true],
]],
'restore/restore_general_users moodle' => [[
(object)['plugin' => 'restore', 'name' => 'restore_general_users', 'value' => 0],
(object)['plugin' => 'restore', 'name' => 'restore_general_groups', 'value' => 0],
]],
];
}