Skip to content

Commit 54c4f6c

Browse files
committed
MDL-84416 backup: Add backup_import_badges setting
While MDL-43938 introduced badge importing, two tasks were left incomplete. 1) Creating the backup_import_badges setting for default import behaviour. 2) Preventing the inclusion of badges during activity duplication. This commit implements them.
1 parent 688478c commit 54c4f6c

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

admin/settings/courses.php

+6
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,12 @@
458458
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_activities', new lang_string('generalactivities','backup'), new lang_string('configgeneralactivities','backup'), array('value'=>1, 'locked'=>0)));
459459
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_blocks', new lang_string('generalblocks','backup'), new lang_string('configgeneralblocks','backup'), array('value'=>1, 'locked'=>0)));
460460
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_filters', new lang_string('generalfilters','backup'), new lang_string('configgeneralfilters','backup'), array('value'=>1, 'locked'=>0)));
461+
$temp->add(new admin_setting_configcheckbox_with_lock(
462+
'backup/backup_import_badges',
463+
new lang_string('generalbadges', 'backup'),
464+
new lang_string('configgeneralbadges', 'backup'),
465+
['value' => 0, 'locked' => 0],
466+
));
461467
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_calendarevents', new lang_string('generalcalendarevents','backup'), new lang_string('configgeneralcalendarevents','backup'), array('value'=>1, 'locked'=>0)));
462468
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_groups',
463469
new lang_string('generalgroups', 'backup'), new lang_string('configgeneralgroups', 'backup'),

backup/util/dbops/backup_controller_dbops.class.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ public static function apply_config_defaults(backup_controller $controller) {
584584
'backup_import_activities' => 'activities',
585585
'backup_import_blocks' => 'blocks',
586586
'backup_import_filters' => 'filters',
587+
'backup_import_badges' => 'badges',
587588
'backup_import_calendarevents' => 'calendarevents',
588589
'backup_import_permissions' => 'permissions',
589590
'backup_import_groups' => 'groups',
@@ -602,6 +603,8 @@ public static function apply_config_defaults(backup_controller $controller) {
602603
'filters',
603604
);
604605
self::force_enable_settings($controller, $settings);
606+
// Badges are not included by default when duplicating activities.
607+
self::force_settings($controller, ['badges'], false);
605608
}
606609
break;
607610
case backup::MODE_AUTOMATED:
@@ -641,9 +644,19 @@ public static function apply_config_defaults(backup_controller $controller) {
641644
* @param array $settings a map from admin config names to setting names (Config name => Setting name)
642645
*/
643646
private static function force_enable_settings(backup_controller $controller, array $settings) {
647+
self::force_settings($controller, $settings, true);
648+
}
649+
650+
/**
651+
* Set these settings to the given $value. No defaults from admin settings.
652+
*
653+
* @param backup_controller $controller The backup controller.
654+
* @param array $settings a map from admin config names to setting names (Config name => Setting name).
655+
* @param mixed $value the value to set the settings to.
656+
*/
657+
private static function force_settings(backup_controller $controller, array $settings, $value) {
644658
$plan = $controller->get_plan();
645659
foreach ($settings as $config => $settingname) {
646-
$value = true;
647660
if ($plan->setting_exists($settingname)) {
648661
$setting = $plan->get_setting($settingname);
649662
// We do not allow this setting to be locked for a duplicate function.

backup/util/ui/tests/behat/duplicate_activities.feature

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ Feature: Duplicate activities
2121
| data | Test database name | Test database description | C1 | database1 | 1 |
2222
And the following config values are set as admin:
2323
| backup_import_activities | 0 | backup |
24+
And the following "core_badges > Badges" exist:
25+
| name | course | description | image | status | type |
26+
| My course badge | C1 | Badge description | badges/tests/behat/badge.png | active | 2 |
27+
And the following "core_badges > Criterias" exist:
28+
| badge | role |
29+
| My course badge | editingteacher |
2430
And I log in as "teacher1"
2531
And I am on "Course 1" course homepage with editing mode on
2632
And I duplicate "Test database name" activity
@@ -38,3 +44,8 @@ Feature: Duplicate activities
3844
Then I should see "Original database name" in the "Section 1" "section"
3945
And I should see "Duplicated database name" in the "Section 1" "section"
4046
And "Original database name" "link" should appear before "Duplicated database name" "link"
47+
# Check that badges are not duplicated. If they are duplicated, they will appear as "Not available".
48+
And I navigate to "Badges" in current page administration
49+
And the following should not exist in the "reportbuilder-table" table:
50+
| Name | Badge status |
51+
| My course badge | Not available |

backup/util/ui/tests/behat/import_course.feature

+14-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Feature: Import course's contents into another course
6868
| Published course badge | editingteacher |
6969
| Unpublished course badge | editingteacher |
7070
When I import "Course 1" course into "Course 2" course using this options:
71-
| Settings | Include badges | 1 |
71+
| Initial | Include badges | 1 |
7272
And I navigate to "Badges" in current page administration
7373
Then I should see "Published course badge"
7474
And I should see "Unpublished course badge"
@@ -77,3 +77,16 @@ Feature: Import course's contents into another course
7777
And ".no-criteria-set" "css_element" should not exist in the "Published course badge" "table_row"
7878
And ".no-criteria-set" "css_element" should not exist in the "Unpublished course badge" "table_row"
7979
And ".no-criteria-set" "css_element" should exist in the "Unpublished without criteria course badge" "table_row"
80+
81+
Scenario: Import process should not include badges by default
82+
Given I log in as "teacher1"
83+
And the following "core_badges > Badges" exist:
84+
| name | course | description | image | status | type |
85+
| Published course badge | C1 | Badge description | badges/tests/behat/badge.png | active | 2 |
86+
And the following "core_badges > Criterias" exist:
87+
| badge | role |
88+
| Published course badge | editingteacher |
89+
When I import "Course 1" course into "Course 2" course using this options:
90+
| Initial | Include badges | 0 |
91+
And I navigate to "Badges" in current page administration
92+
Then I should not see "Published course badge"

0 commit comments

Comments
 (0)