Skip to content

Commit

Permalink
Merge branch 'wip-107275-m404' into MOODLE_404_STABLE
Browse files Browse the repository at this point in the history
# Conflicts:
#	local/o365/classes/feature/coursesync/utils.php
  • Loading branch information
weilai-irl committed Oct 14, 2024
2 parents df40c63 + f22f641 commit 3a43eb1
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions classes/feature/coursesync/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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)) {
Expand All @@ -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');
}

/**
Expand Down

0 comments on commit 3a43eb1

Please sign in to comment.