Skip to content

Commit

Permalink
Merge branch 'MDL-68981-400' of https://github.com/HuongNV13/moodle i…
Browse files Browse the repository at this point in the history
…nto MOODLE_400_STABLE
  • Loading branch information
junpataleta authored and ilyatregubov committed Dec 1, 2022
2 parents 230c3ce + 832d237 commit 17e976a
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 22 deletions.
14 changes: 14 additions & 0 deletions admin/tool/recyclebin/classes/category_bin.php
Expand Up @@ -243,6 +243,16 @@ public function restore_item($item) {
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,
Expand Down Expand Up @@ -277,6 +287,10 @@ public function restore_item($item) {
// 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();

Expand Down
14 changes: 14 additions & 0 deletions admin/tool/recyclebin/classes/course_bin.php
Expand Up @@ -234,6 +234,16 @@ public function restore_item($item) {
$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,
Expand Down Expand Up @@ -264,6 +274,10 @@ public function restore_item($item) {
// 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();

Expand Down
44 changes: 22 additions & 22 deletions admin/tool/recyclebin/tests/behat/backup_user_data.feature
Expand Up @@ -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 all and finish" "button" in the "Confirmation" "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
Expand All @@ -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 |
5 changes: 5 additions & 0 deletions admin/tool/recyclebin/tests/category_bin_test.php
Expand Up @@ -190,6 +190,11 @@ public function recycle_bin_settings_provider() {
(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],
]],
];
}

Expand Down
5 changes: 5 additions & 0 deletions admin/tool/recyclebin/tests/course_bin_test.php
Expand Up @@ -187,6 +187,11 @@ public function recycle_bin_settings_provider() {
(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],
]],
];
}

Expand Down

0 comments on commit 17e976a

Please sign in to comment.