MDL-53974 backup: Add option to backup course competencies

This commit is contained in:
Jun Pataleta 2016-04-29 18:32:06 +08:00 committed by Andrew Nicols
parent 11ee4f71a4
commit 45b9207d7e
7 changed files with 91 additions and 4 deletions

View File

@ -163,5 +163,10 @@ class backup_root_task extends backup_task {
$groups = new backup_groups_setting('groups', base_setting::IS_BOOLEAN, true); $groups = new backup_groups_setting('groups', base_setting::IS_BOOLEAN, true);
$groups->set_ui(new backup_setting_ui_checkbox($groups, get_string('rootsettinggroups', 'backup'))); $groups->set_ui(new backup_setting_ui_checkbox($groups, get_string('rootsettinggroups', 'backup')));
$this->add_setting($groups); $this->add_setting($groups);
// Define competencies inclusion setting if competencies are enabled.
$competencies = new backup_competencies_setting();
$competencies->set_ui(new backup_setting_ui_checkbox($competencies, get_string('rootsettingcompetencies', 'backup')));
$this->add_setting($competencies);
} }
} }

View File

@ -130,6 +130,27 @@ class backup_calendarevents_setting extends backup_anonymize_setting {}
*/ */
class backup_userscompletion_setting extends backup_anonymize_setting {} class backup_userscompletion_setting extends backup_anonymize_setting {}
/**
* root setting to control if backup will include competencies or not.
*/
class backup_competencies_setting extends backup_generic_setting {
/**
* backup_competencies_setting constructor.
*/
public function __construct() {
$defaultvalue = false;
$visibility = base_setting::HIDDEN;
$status = base_setting::LOCKED_BY_CONFIG;
if (\core_competency\api::is_enabled()) {
$defaultvalue = true;
$visibility = base_setting::VISIBLE;
$status = base_setting::NOT_LOCKED;
}
parent::__construct('competencies', base_setting::IS_BOOLEAN, $defaultvalue, $visibility, $status);
}
}
// Section backup settings // Section backup settings
/** /**

View File

@ -1585,6 +1585,21 @@ class backup_course_competencies_structure_step extends backup_structure_step {
return $wrapper; return $wrapper;
} }
/**
* Execute conditions.
*
* @return bool
*/
protected function execute_condition() {
// Do not execute if competencies are not included.
if (!$this->get_setting_value('competencies')) {
return false;
}
return true;
}
} }
/** /**
@ -1612,6 +1627,21 @@ class backup_activity_competencies_structure_step extends backup_structure_step
return $wrapper; return $wrapper;
} }
/**
* Execute conditions.
*
* @return bool
*/
protected function execute_condition() {
// Do not execute if competencies are not included.
if (!$this->get_setting_value('competencies')) {
return false;
}
return true;
}
} }
/** /**

View File

@ -266,5 +266,11 @@ class restore_root_task extends restore_task {
$groups->set_ui(new backup_setting_ui_checkbox($groups, get_string('rootsettinggroups', 'backup'))); $groups->set_ui(new backup_setting_ui_checkbox($groups, get_string('rootsettinggroups', 'backup')));
$groups->get_ui()->set_changeable($changeable); $groups->get_ui()->set_changeable($changeable);
$this->add_setting($groups); $this->add_setting($groups);
// Competencies restore setting. Show when competencies is enabled and the setting is available.
$hascompetencies = !empty($rootsettings['competencies']);
$competencies = new restore_competencies_setting($hascompetencies);
$competencies->set_ui(new backup_setting_ui_checkbox($competencies, get_string('rootsettingcompetencies', 'backup')));
$this->add_setting($competencies);
} }
} }

View File

@ -78,6 +78,30 @@ class restore_comments_setting extends restore_role_assignments_setting {}
*/ */
class restore_badges_setting extends restore_generic_setting {} class restore_badges_setting extends restore_generic_setting {}
/**
* root setting to control if competencies will also be restored.
*/
class restore_competencies_setting extends restore_generic_setting {
/**
* restore_competencies_setting constructor.
* @param bool $hascompetencies Flag whether to set the restore setting as checked and unlocked.
*/
public function __construct($hascompetencies) {
$defaultvalue = false;
$visibility = base_setting::HIDDEN;
$status = base_setting::LOCKED_BY_CONFIG;
if (\core_competency\api::is_enabled()) {
$visibility = base_setting::VISIBLE;
if ($hascompetencies) {
$defaultvalue = true;
$status = base_setting::NOT_LOCKED;
}
}
parent::__construct('competencies', base_setting::IS_BOOLEAN, $defaultvalue, $visibility, $status);
}
}
/** /**
* root setting to control if restore will create * root setting to control if restore will create
* events or no, depends of @restore_users_setting * events or no, depends of @restore_users_setting

View File

@ -3213,8 +3213,8 @@ class restore_course_competencies_structure_step extends restore_structure_step
*/ */
protected function execute_condition() { protected function execute_condition() {
// Do not restore when competencies are disabled. // Do not execute if competencies are not included.
if (!\core_competency\api::is_enabled()) { if (!$this->get_setting_value('competencies')) {
return false; return false;
} }
@ -3288,8 +3288,8 @@ class restore_activity_competencies_structure_step extends restore_structure_ste
*/ */
protected function execute_condition() { protected function execute_condition() {
// Do not restore when competencies are disabled. // Do not execute if competencies are not included.
if (!\core_competency\api::is_enabled()) { if (!$this->get_setting_value('competencies')) {
return false; return false;
} }

View File

@ -237,6 +237,7 @@ $string['rootsettingroleassignments'] = 'Include user role assignments';
$string['rootsettingactivities'] = 'Include activities and resources'; $string['rootsettingactivities'] = 'Include activities and resources';
$string['rootsettingbadges'] = 'Include badges'; $string['rootsettingbadges'] = 'Include badges';
$string['rootsettingblocks'] = 'Include blocks'; $string['rootsettingblocks'] = 'Include blocks';
$string['rootsettingcompetencies'] = 'Include competencies';
$string['rootsettingfilters'] = 'Include filters'; $string['rootsettingfilters'] = 'Include filters';
$string['rootsettingcomments'] = 'Include comments'; $string['rootsettingcomments'] = 'Include comments';
$string['rootsettingcalendarevents'] = 'Include calendar events'; $string['rootsettingcalendarevents'] = 'Include calendar events';