From 7b3f43db95272d8eb949f35bcd61632c701bc8b1 Mon Sep 17 00:00:00 2001 From: Sujith Haridasan Date: Wed, 6 Jan 2021 15:21:10 +0530 Subject: [PATCH] MDL-57020 scales: Allow deletion of unused scales in forum Allow deletion of unused scales used in a forum for the course. Signed-off-by: Sujith Haridasan --- lib/grade/tests/grade_scale_test.php | 4 ++++ mod/forum/lib.php | 2 +- mod/glossary/lib.php | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/grade/tests/grade_scale_test.php b/lib/grade/tests/grade_scale_test.php index 722f7680f04..e1040f08139 100644 --- a/lib/grade/tests/grade_scale_test.php +++ b/lib/grade/tests/grade_scale_test.php @@ -167,5 +167,9 @@ class core_grade_scale_testcase extends grade_base_testcase { $this->assertNotEmpty($grade_item->id); $this->assertEquals(1, $grade_item->grademin); $this->assertEquals(1, $grade_item->grademax); + + $status = $scale->is_used(); + + $this->assertTrue($status); } } diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 79cc80fc5fb..e9089555fd1 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -954,7 +954,7 @@ function forum_scale_used_anywhere(int $scaleid): bool { return false; } - return $DB->record_exists('forum', ['scale' => $scaleid * -1]); + return $DB->record_exists_select('forum', "scale = ? and assessed > 0", [$scaleid * -1]); } // SQL FUNCTIONS /////////////////////////////////////////////////////////// diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index afae7fe5159..ab662bb3a0f 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -877,7 +877,7 @@ function glossary_scale_used() { function glossary_scale_used_anywhere($scaleid) { global $DB; - if ($scaleid and $DB->record_exists('glossary', array('scale'=>-$scaleid))) { + if ($scaleid and $DB->record_exists_select('glossary', "scale = ? and assessed > 0", [-$scaleid])) { return true; } else { return false;