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:
Eugene Venter 2015-03-03 13:36:11 +13:00 committed by Eloy Lafuente (stronk7)
parent e201bf16a0
commit 96e339cc58
2 changed files with 10 additions and 7 deletions

View File

@ -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')) {

View File

@ -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;
}