Skip to content

Commit

Permalink
MDL-53451 tool_lpmigrate: Fixing broken logic found in tests
Browse files Browse the repository at this point in the history
Thanks to MSSQL, the only one with failures.
  • Loading branch information
Frederic Massart committed Apr 20, 2016
1 parent 4fd183d commit d789158
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
5 changes: 5 additions & 0 deletions admin/tool/lpmigrate/classes/framework_processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,11 @@ protected function process_courses() {
// Finally, we remove the course competencies, but only for the 100% successful ones.
foreach ($competenciestoremovefromcourse as $competencyid => $unused) {

// Skip competencies with issues.
if (isset($competencieswithissues[$competencyid])) {
continue;
}

try {
// Process the course competency.
api::remove_competency_from_course($courseid, $competencyid);
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/lpmigrate/tests/processor_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public function test_destination_competency_exists() {
$this->assertEquals(2, $processor->get_courses_found_count());
$this->assertEquals(5, $processor->get_expected_course_competency_migrations());
$this->assertEquals(3, $processor->get_course_competency_migrations());
$this->assertEquals(3, $processor->get_course_competency_removals());
$this->assertEquals(2, $processor->get_course_competency_removals());

$this->assertEquals(3, $processor->get_cms_found_count());
$this->assertEquals(5, $processor->get_expected_module_competency_migrations());
Expand Down
5 changes: 2 additions & 3 deletions competency/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1606,12 +1606,11 @@ public static function remove_competency_from_course($courseid, $competencyid) {
$record->courseid = $courseid;
$record->competencyid = $competencyid;

$competency = new competency($competencyid);
$coursecompetency = new course_competency();
$exists = $coursecompetency->get_record(array('courseid' => $courseid, 'competencyid' => $competencyid));
$exists = course_competency::get_record(array('courseid' => $courseid, 'competencyid' => $competencyid));
if ($exists) {
// Delete all course_module_competencies for this competency in this course.
$cmcs = course_module_competency::list_course_module_competencies($competencyid, $courseid);
$cmcs = course_module_competency::get_records_by_competencyid_in_course($competencyid, $courseid);
foreach ($cmcs as $cmc) {
$cmc->delete();
}
Expand Down
29 changes: 29 additions & 0 deletions competency/classes/course_module_competency.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,33 @@ public static function list_course_module_competencies($cmid) {
return $instances;
}

/**
* List the relationship objects for a competency in a course.
*
* @param int $competencyid The competency ID.
* @param int $courseid The course ID.
* @return course_module_competency[]
*/
public static function get_records_by_competencyid_in_course($competencyid, $courseid) {
global $DB;

$sql = 'SELECT cmc.*
FROM {' . self::TABLE . '} cmc
JOIN {course_modules} cm
ON cm.course = ?
AND cmc.cmid = cm.id
WHERE cmc.competencyid = ?
ORDER BY cmc.sortorder ASC';
$params = array($courseid, $competencyid);

$results = $DB->get_recordset_sql($sql, $params);
$instances = array();
foreach ($results as $result) {
$instances[$result->id] = new course_module_competency(0, $result);
}
$results->close();

return $instances;
}

}

0 comments on commit d789158

Please sign in to comment.