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

This commit is contained in:
Jake Dallimore 2023-01-17 11:28:53 +08:00
commit 17659466cc
4 changed files with 36 additions and 1 deletions

View File

@ -477,7 +477,8 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) {
$temp->add(new admin_setting_heading('automatedsettings', new lang_string('automatedsettings','backup'), new lang_string('recyclebin_desc', 'backup')));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_users', new lang_string('generalusers', 'backup'), new lang_string('configgeneralusers', 'backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_role_assignments', new lang_string('generalroleassignments','backup'), new lang_string('configgeneralroleassignments','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_activities', new lang_string('generalactivities','backup'), new lang_string('configgeneralactivities','backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_activities', new lang_string('generalactivities', 'backup'),
new lang_string('backupautoactivitiesdescription', 'backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_blocks', new lang_string('generalblocks','backup'), new lang_string('configgeneralblocks','backup'), 1));
$temp->add(new admin_setting_configcheckbox(
'backup/backup_auto_files',

View File

@ -133,6 +133,16 @@ class course_bin extends base_bin {
\backup::MODE_AUTOMATED,
$user->id
);
// When "backup_auto_activities" setting is disabled, activities can't be restored from recycle bin.
$plan = $controller->get_plan();
$activitiessettings = $plan->get_setting('activities');
$settingsvalue = $activitiessettings->get_value();
if (empty($settingsvalue)) {
$controller->destroy();
return;
}
$controller->execute_plan();
// We don't need the forced setting anymore, hence unsetting it.

View File

@ -242,6 +242,29 @@ class course_bin_test extends \advanced_testcase {
$this->assertEquals(true, $attemptobj->is_finished());
}
/**
* Test that the activity is NOT stored in bin when
* in Automated backup setup settings "backup_auto_activities" is disabled.
*
* @dataProvider recycle_bin_settings_provider
* @covers ::store_item
*/
public function test_coursemodule_restore_with_activity_setting_disabled() {
// Set the configuration to not include activities in the automated backup.
set_config('backup_auto_activities', false, 'backup');
// Delete the course module.
course_delete_module($this->quiz->cmid);
// Now, run the course module deletion adhoc task.
\phpunit_util::run_all_adhoc_tasks();
// Check there is no items in the recycle bin.
$recyclebin = new \tool_recyclebin\course_bin($this->course->id);
$this->assertEquals(0, count($recyclebin->get_items()));
}
/**
* Tests that user data is not restored when module is restored.
*

View File

@ -70,6 +70,7 @@ $string['automatedsettings'] = 'Automated backup settings';
$string['automatedstorage'] = 'Automated backup storage';
$string['automatedstoragehelp'] = 'Choose the location where you want backups to be stored when they are automatically created.';
$string['backupactivity'] = 'Backup activity: {$a}';
$string['backupautoactivitiesdescription'] = 'Sets the default for including activities in a backup. For the recycle bin to work, this setting must be enabled.';
$string['backupcourse'] = 'Backup course: {$a}';
$string['backupcoursedetails'] = 'Course details';
$string['backupcoursesection'] = 'Section: {$a}';