Skip to content

Commit

Permalink
Merge branch 'MDL-66221-401' of https://github.com/raortegar/moodle i…
Browse files Browse the repository at this point in the history
…nto MOODLE_401_STABLE
  • Loading branch information
snake committed Jan 17, 2023
2 parents 4b69c11 + c812f45 commit 1765946
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion admin/settings/courses.php
Expand Up @@ -477,7 +477,8 @@
$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',
Expand Down
10 changes: 10 additions & 0 deletions admin/tool/recyclebin/classes/course_bin.php
Expand Up @@ -133,6 +133,16 @@ public function store_item($cm) {
\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.
Expand Down
23 changes: 23 additions & 0 deletions admin/tool/recyclebin/tests/course_bin_test.php
Expand Up @@ -242,6 +242,29 @@ public function test_coursemodule_restore_with_userdata($settings) {
$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.
*
Expand Down
1 change: 1 addition & 0 deletions lang/en/backup.php
Expand Up @@ -70,6 +70,7 @@
$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}';
Expand Down

0 comments on commit 1765946

Please sign in to comment.