MDL-63002 core: fixed incorrect calls to non-existent delete_record()
authorMark Nelson <markn@moodle.com>
Mon, 30 Jul 2018 12:47:57 +0000 (20:47 +0800)
committerMark Nelson <markn@moodle.com>
Mon, 30 Jul 2018 12:59:42 +0000 (20:59 +0800)
lib/gradelib.php
lib/tests/gradelib_test.php
mod/lesson/locallib.php

index cb31417..9e37c42 100644 (file)
@@ -1401,7 +1401,7 @@ function remove_grade_letters($context, $showfeedback) {
 
     $records = $DB->get_records('grade_letters', array('contextid' => $context->id));
     foreach ($records as $record) {
-        $DB->delete_record('grade_letters', array('id' => $record->id));
+        $DB->delete_records('grade_letters', array('id' => $record->id));
         // Trigger the letter grade deleted event.
         $event = \core\event\grade_letter_deleted::create(array(
             'objectid' => $record->id,
@@ -1473,7 +1473,7 @@ function grade_course_category_delete($categoryid, $newparentid, $showfeedback)
     $context = context_coursecat::instance($categoryid);
     $records = $DB->get_records('grade_letters', array('contextid' => $context->id));
     foreach ($records as $record) {
-        $DB->delete_record('grade_letters', array('id' => $record->id));
+        $DB->delete_records('grade_letters', array('id' => $record->id));
         // Trigger the letter grade deleted event.
         $event = \core\event\grade_letter_deleted::create(array(
             'objectid' => $record->id,
index f178315..fcc42ad 100644 (file)
@@ -56,4 +56,52 @@ class core_gradelib_testcase extends advanced_testcase {
 
         $this->assertTrue(grade_update_mod_grades($modinstance));
     }
+
+    /**
+     * Tests the function remove_grade_letters().
+     */
+    public function test_remove_grade_letters() {
+        global $DB;
+
+        $this->resetAfterTest();
+
+        $course = $this->getDataGenerator()->create_course();
+
+        $context = context_course::instance($course->id);
+
+        // Add a grade letter to the course.
+        $letter = new stdClass();
+        $letter->letter = 'M';
+        $letter->lowerboundary = '100';
+        $letter->contextid = $context->id;
+        $DB->insert_record('grade_letters', $letter);
+
+        remove_grade_letters($context, false);
+
+        // Confirm grade letter was deleted.
+        $this->assertEquals(0, $DB->count_records('grade_letters'));
+    }
+
+    /**
+     * Tests the function grade_course_category_delete().
+     */
+    public function test_grade_course_category_delete() {
+        global $DB;
+
+        $this->resetAfterTest();
+
+        $category = coursecat::create(array('name' => 'Cat1'));
+
+        // Add a grade letter to the category.
+        $letter = new stdClass();
+        $letter->letter = 'M';
+        $letter->lowerboundary = '100';
+        $letter->contextid = context_coursecat::instance($category->id)->id;
+        $DB->insert_record('grade_letters', $letter);
+
+        grade_course_category_delete($category->id, '', false);
+
+        // Confirm grade letter was deleted.
+        $this->assertEquals(0, $DB->count_records('grade_letters'));
+    }
 }
index 767b580..0d8d407 100644 (file)
@@ -4360,7 +4360,7 @@ abstract class lesson_page extends lesson_base {
             if (count($answers) > 1) {
                 $answer = array_shift($answers);
                 foreach ($answers as $a) {
-                    $DB->delete_record('lesson_answers', array('id' => $a->id));
+                    $DB->delete_records('lesson_answers', array('id' => $a->id));
                 }
             } else if (count($answers) == 1) {
                 $answer = array_shift($answers);