From 3577bbe1012b0dbff43ab09026661973858949b2 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Thu, 21 Apr 2016 11:37:27 +0800 Subject: [PATCH] MDL-53451 tool_lpmigrate: Keep course competency on module failure When permissions are lacking and the course module competencies could not be migrated we must keep the course competency to preserve the original competency in the course module. --- admin/tool/lpmigrate/classes/framework_processor.php | 2 ++ admin/tool/lpmigrate/tests/processor_test.php | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/admin/tool/lpmigrate/classes/framework_processor.php b/admin/tool/lpmigrate/classes/framework_processor.php index 51005f02b0a..0dac5e7607f 100644 --- a/admin/tool/lpmigrate/classes/framework_processor.php +++ b/admin/tool/lpmigrate/classes/framework_processor.php @@ -543,6 +543,7 @@ class framework_processor { } catch (moodle_exception $e) { // There was a major problem with this competency in this module. + $competencieswithissues[$competencyid] = true; $message = get_string('errorwhilemigratingmodulecompetencywithexception', 'tool_lpmigrate', $e->getMessage()); $this->log_error($courseid, $competencyid, $cmid, $message); @@ -564,6 +565,7 @@ class framework_processor { $this->modulecompetencyremovals++; } } catch (moodle_exception $e) { + $competencieswithissues[$competencyid] = true; $this->log_warning($courseid, $competencyid, $cmid, get_string('warningcouldnotremovemodulecompetency', 'tool_lpmigrate')); } diff --git a/admin/tool/lpmigrate/tests/processor_test.php b/admin/tool/lpmigrate/tests/processor_test.php index 8d1cfafab11..792a902962b 100644 --- a/admin/tool/lpmigrate/tests/processor_test.php +++ b/admin/tool/lpmigrate/tests/processor_test.php @@ -456,7 +456,7 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase { $this->assertEquals(1, $processor->get_courses_found_count()); $this->assertEquals(2, $processor->get_expected_course_competency_migrations()); $this->assertEquals(2, $processor->get_course_competency_migrations()); - $this->assertEquals(2, $processor->get_course_competency_removals()); + $this->assertEquals(0, $processor->get_course_competency_removals()); $this->assertEquals(1, $processor->get_cms_found_count()); $this->assertEquals(2, $processor->get_expected_module_competency_migrations()); @@ -472,8 +472,13 @@ class tool_lpmigrate_framework_processor_testcase extends advanced_testcase { $this->assertRegexp('/Sorry, but you do not currently have permissions to do that/', $errors[0]['message']); $this->assertEquals($this->f1comps['A3']->get_id(), $errors[1]['competencyid']); - $this->assertCourseCompetencyMigrated($this->c2, $this->f1comps['A2'], $this->f2comps['A2']); - $this->assertCourseCompetencyMigrated($this->c2, $this->f1comps['A3'], $this->f2comps['A3']); + // The new competencies were added to the course, but the old ones were not removed because they are still in modules. + $this->assertCourseCompetencyExists($this->c2, $this->f1comps['A2']); + $this->assertCourseCompetencyExists($this->c2, $this->f1comps['A3']); + $this->assertCourseCompetencyExists($this->c2, $this->f2comps['A2']); + $this->assertCourseCompetencyExists($this->c2, $this->f2comps['A3']); + + // Module competencies were not migrated because permissions are lacking. $this->assertModuleCompetencyNotMigrated($this->cms[$this->c2->id]['F1'], $this->f1comps['A2'], $this->f2comps['A2']); $this->assertModuleCompetencyNotMigrated($this->cms[$this->c2->id]['F1'], $this->f1comps['A3'], $this->f2comps['A2']); }