mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-49356 restore: handle course completion if still not defined
Before this patch course completion only was restored if, appart from other conditions... we were restoring to new course, never to existing one. This relaxes a bit that condition in order to be able to restore to an existing course not having any course completion setting defined, so no conflict will happen ever.
This commit is contained in:
parent
e201bf16a0
commit
96e339cc58
@ -61,11 +61,8 @@ class restore_final_task extends restore_task {
|
||||
$this->add_step(new restore_grade_history_structure_step('grade_history', 'grade_history.xml'));
|
||||
}
|
||||
|
||||
// Course completion, executed conditionally if restoring to new course
|
||||
if ($this->get_target() !== backup::TARGET_CURRENT_ADDING &&
|
||||
$this->get_target() !== backup::TARGET_EXISTING_ADDING) {
|
||||
$this->add_step(new restore_course_completion_structure_step('course_completion', 'completion.xml'));
|
||||
}
|
||||
// Course completion.
|
||||
$this->add_step(new restore_course_completion_structure_step('course_completion', 'completion.xml'));
|
||||
|
||||
// Conditionally restore course badges.
|
||||
if ($this->get_setting_value('badges')) {
|
||||
|
@ -2453,11 +2453,12 @@ class restore_course_completion_structure_step extends restore_structure_step {
|
||||
* 2. The backup includes course completion information
|
||||
* 3. All modules are restorable
|
||||
* 4. All modules are marked for restore.
|
||||
* 5. No completion criteria already exist for the course.
|
||||
*
|
||||
* @return bool True is safe to execute, false otherwise
|
||||
*/
|
||||
protected function execute_condition() {
|
||||
global $CFG;
|
||||
global $CFG, $DB;
|
||||
|
||||
// First check course completion is enabled on this site
|
||||
if (empty($CFG->enablecompletion)) {
|
||||
@ -2483,11 +2484,16 @@ class restore_course_completion_structure_step extends restore_structure_step {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Finally check all modules within the backup are being restored.
|
||||
// Check all modules within the backup are being restored.
|
||||
if ($this->task->is_excluding_activities()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that no completion criteria is already set for the course.
|
||||
if ($DB->record_exists('course_completion_criteria', array('course' => $this->get_courseid()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user