diff --git a/course/classes/category.php b/course/classes/category.php index 1a12b9b8c52..8a546a7ea62 100644 --- a/course/classes/category.php +++ b/course/classes/category.php @@ -629,10 +629,9 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr } // Delete theme usage cache if the theme has been changed. - if (isset($data->theme)) { - $oldcategory = $DB->get_record('course_categories', ['id' => $data->id]); - if ($data->theme != $oldcategory->theme) { - theme_delete_used_in_context_cache($data->theme, (string)$oldcategory->theme); + if (isset($newcategory->theme)) { + if ($newcategory->theme != $this->theme) { + theme_delete_used_in_context_cache($newcategory->theme, (string) $this->theme); } }