diff --git a/local/o365/classes/feature/coursesync/utils.php b/local/o365/classes/feature/coursesync/utils.php index 031ca11c2..1478ae10e 100644 --- a/local/o365/classes/feature/coursesync/utils.php +++ b/local/o365/classes/feature/coursesync/utils.php @@ -69,7 +69,11 @@ public static function get_enabled_courses(bool $returnallids = false) { return true; } } else if ($coursesyncsetting === 'oncustom') { - $coursesenabled = get_config('local_o365', 'coursesynccustom'); + // Get the list of enabled courses from database rather than get_config() to avoid cache issues. + $coursesenabled = $DB->get_field('config_plugins', 'value', ['plugin' => 'local_o365', 'name' => 'coursesynccustom']); + if (!$coursesenabled) { + $coursesenabled = ''; + } $originalcoursesenabled = $coursesenabled; $coursesenabled = @json_decode($coursesenabled, true); if (!empty($coursesenabled) && is_array($coursesenabled)) { @@ -81,10 +85,10 @@ public static function get_enabled_courses(bool $returnallids = false) { } } if ($changed) { - if ($originalcoursesenabled != json_encode($coursesenabled)) { + if ($originalcoursesenabled !== json_encode($coursesenabled)) { add_to_config_log('coursesynccustom', $originalcoursesenabled, json_encode($coursesenabled), 'local_o365'); + set_config('coursesynccustom', json_encode($coursesenabled), 'local_o365'); } - set_config('coursesynccustom', json_encode($coursesenabled), 'local_o365'); } return array_keys($coursesenabled); } @@ -225,7 +229,14 @@ public static function delete_microsoft_365_group(int $courseid) { * @param bool $enabled Whether to enable or disable. */ public static function set_course_sync_enabled(int $courseid, bool $enabled = true) { - $customcoursesyncsetting = get_config('local_o365', 'coursesynccustom'); + global $DB; + + // Get the list of enabled courses from database rather than get_config() to avoid cache issues. + $customcoursesyncsetting = $DB->get_field('config_plugins', 'value', + ['plugin' => 'local_o365', 'name' => 'coursesynccustom']); + if ($customcoursesyncsetting === false) { + $customcoursesyncsetting = ''; + } $originalcustomcoursesyncsetting = $customcoursesyncsetting; $customcoursesyncsetting = @json_decode($customcoursesyncsetting, true); if (empty($customcoursesyncsetting) || !is_array($customcoursesyncsetting)) { @@ -246,8 +257,8 @@ public static function set_course_sync_enabled(int $courseid, bool $enabled = tr if ($originalcustomcoursesyncsetting != json_encode($customcoursesyncsetting)) { add_to_config_log('coursesynccustom', $originalcustomcoursesyncsetting, json_encode($customcoursesyncsetting), 'local_o365'); + set_config('coursesynccustom', json_encode($customcoursesyncsetting), 'local_o365'); } - set_config('coursesynccustom', json_encode($customcoursesyncsetting), 'local_o365'); } /**