From 79265d30e6929b887742137d6a74ad656674b69e Mon Sep 17 00:00:00 2001 From: Lai Wei Date: Wed, 3 Jul 2024 09:59:27 +0100 Subject: [PATCH] Fix PostgreSQL incompatibility issue and bug in DB queries in local_o365 tool pages --- .../classes/feature/courserequest/main.php | 3 +-- .../o365/classes/feature/coursesync/main.php | 20 +++++++++---------- .../o365/classes/feature/coursesync/utils.php | 2 +- local/o365/classes/page/acp.php | 8 ++++---- local/o365/version.php | 4 ++-- local/office365/version.php | 6 +++--- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/local/o365/classes/feature/courserequest/main.php b/local/o365/classes/feature/courserequest/main.php index df350f1cf..d37968506 100644 --- a/local/o365/classes/feature/courserequest/main.php +++ b/local/o365/classes/feature/courserequest/main.php @@ -36,7 +36,6 @@ use local_o365\utils; use moodle_exception; use stdClass; - class main { const COURSE_REQUEST_STATUS_PENDING = 0; const COURSE_REQUEST_STATUS_APPROVED = 1; @@ -133,7 +132,7 @@ public function get_unmatched_teams_by_user_oid(string $userobjectid) { // Get SDS courses. $sdsmatchedgroupoids = $DB->get_fieldset_select('local_o365_objects', 'objectid', - 'type = "sdssection" AND subtype = "course"'); + "type = 'sdssection' AND subtype = 'course'"); $matchedgroupoids = array_unique(array_merge($matchedgroupoids, $sdsmatchedgroupoids)); $unmatchedteams = []; diff --git a/local/o365/classes/feature/coursesync/main.php b/local/o365/classes/feature/coursesync/main.php index 9410b34bc..4596a732f 100644 --- a/local/o365/classes/feature/coursesync/main.php +++ b/local/o365/classes/feature/coursesync/main.php @@ -605,10 +605,10 @@ private function process_courses_without_groups() { } } - $sql = 'SELECT crs.* + $sql = "SELECT crs.* FROM {course} crs - LEFT JOIN {local_o365_objects} obj ON obj.type = "group" AND obj.subtype = "course" AND obj.moodleid = crs.id - WHERE obj.id IS NULL AND crs.id != ? AND crs.visible != 0'; + LEFT JOIN {local_o365_objects} obj ON obj.type = 'group' AND obj.subtype = 'course' AND obj.moodleid = crs.id + WHERE obj.id IS NULL AND crs.id != ? AND crs.visible != 0"; // The "crs.visible != 0" is used to filter out courses in the process of copy or restore, which may contain incorrect or // incomplete contents. $params = [SITEID]; @@ -696,22 +696,22 @@ private function process_courses_without_teams() { $this->mtrace('Processing courses without teams...'); - $sql = 'SELECT crs.*, obj_group.objectid AS groupobjectid + $sql = "SELECT crs.*, obj_group.objectid AS groupobjectid FROM {course} crs LEFT JOIN {local_o365_objects} obj_group - ON obj_group.type = "group" AND obj_group.subtype = "course" AND obj_group.moodleid = crs.id + ON obj_group.type = 'group' AND obj_group.subtype = 'course' AND obj_group.moodleid = crs.id LEFT JOIN {local_o365_objects} obj_team1 - ON obj_team1.type = "group" AND obj_team1.subtype = "courseteam" AND obj_team1.moodleid = crs.id + ON obj_team1.type = 'group' AND obj_team1.subtype = 'courseteam' AND obj_team1.moodleid = crs.id LEFT JOIN {local_o365_objects} obj_team2 - ON obj_team2.type = "group" AND obj_team2.subtype = "teamfromgroup" AND obj_team2.moodleid = crs.id + ON obj_team2.type = 'group' AND obj_team2.subtype = 'teamfromgroup' AND obj_team2.moodleid = crs.id LEFT JOIN {local_o365_objects} obj_sds - ON obj_sds.type = "sdssection" AND obj_sds.subtype = "course" AND obj_sds.moodleid = crs.id + ON obj_sds.type = 'sdssection' AND obj_sds.subtype = 'course' AND obj_sds.moodleid = crs.id WHERE obj_group.id IS NOT NULL AND obj_team1.id IS NULL AND obj_team2.id IS NULL AND obj_sds.id IS NULL - AND crs.id != ?'; - $params = [SITEID]; + AND crs.id != " . SITEID; + $params = []; if (!empty($this->coursesinsql)) { $sql .= ' AND crs.id ' . $this->coursesinsql; $params = array_merge($params, $this->coursesparams); diff --git a/local/o365/classes/feature/coursesync/utils.php b/local/o365/classes/feature/coursesync/utils.php index 47695509e..6887286e1 100644 --- a/local/o365/classes/feature/coursesync/utils.php +++ b/local/o365/classes/feature/coursesync/utils.php @@ -199,7 +199,7 @@ public static function delete_microsoft_365_group(int $courseid) { // Delete course and team connection records. $DB->delete_records_select('local_o365_objects', - 'type = "group" AND subtype IN ("courseteam", "teamfromgroup") AND moodleid = ?', [$courseid]); + "type = 'group' AND subtype IN ('courseteam', 'teamfromgroup') AND moodleid = ?", [$courseid]); if ($result === true) { $metadata = (!empty($objectrec->metadata)) ? @json_decode($objectrec->metadata, true) : []; diff --git a/local/o365/classes/page/acp.php b/local/o365/classes/page/acp.php index 8ea0d57fb..2c866a5b3 100644 --- a/local/o365/classes/page/acp.php +++ b/local/o365/classes/page/acp.php @@ -1132,7 +1132,7 @@ public function mode_teamconnections_connect() { } $DB->delete_records_select('local_o365_objects', - 'type => "group" AND subtype IN ("courseteam", "teamfromgroup") AND moodleid = ?', [$courseid]); + "type = 'group' AND subtype IN ('courseteam', 'teamfromgroup') AND moodleid = ?", [$courseid]); $teamrecord = new stdClass(); $teamrecord->type = 'group'; @@ -1262,7 +1262,7 @@ public function mode_teamconnections_update() { } $DB->delete_records_select('local_o365_objects', - 'type => "group" AND subtype IN ("courseteam", "teamfromgroup") AND moodleid = ?', [$courseid]); + "type = 'group' AND subtype IN ('courseteam', 'teamfromgroup') AND moodleid = ?", [$courseid]); $teamrecord = new stdClass(); $teamrecord->type = 'group'; @@ -1343,7 +1343,7 @@ public function mode_maintenance_recreatedeletedgroups() { if (!$course = $DB->get_record('course', ['id' => $groupobject->moodleid])) { // Moodle course doesn't exist. Delete the invalid record. $DB->delete_records_select('local_o365_objects', - 'type => "group" AND subtype IN ("course", "courseteam", "teamfromgroup") AND moodleid = ?', + "type = 'group' AND subtype IN ('course', 'courseteam', 'teamfromgroup') AND moodleid = ?", [$groupobject->moodleid]); continue; } @@ -1360,7 +1360,7 @@ public function mode_maintenance_recreatedeletedgroups() { $status = ''; if (!in_array($groupobject->objectid, $groupids)) { $DB->delete_records_select('local_o365_objects', - 'type => "group" AND subtype IN ("course", "courseteam", "teamfromgroup") AND moodleid = ?', + "type = 'group' AND subtype IN ('course', 'courseteam', 'teamfromgroup') AND moodleid = ?", [$groupobject->moodleid]); if (!in_array($course->id, $coursesenabled)) { $status = get_string('acp_maintenance_recreatedeletedgroups_status_sync_disabled', 'local_o365'); diff --git a/local/o365/version.php b/local/o365/version.php index 3847018e1..c39d23fe4 100644 --- a/local/o365/version.php +++ b/local/o365/version.php @@ -26,9 +26,9 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2022112835; +$plugin->version = 2022112836; $plugin->requires = 2022112800; -$plugin->release = '4.1.7'; +$plugin->release = '4.1.8'; $plugin->component = 'local_o365'; $plugin->maturity = MATURITY_STABLE; $plugin->dependencies = [ diff --git a/local/office365/version.php b/local/office365/version.php index 7b9e2cb57..0a145a55d 100644 --- a/local/office365/version.php +++ b/local/office365/version.php @@ -25,15 +25,15 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2022112835; +$plugin->version = 2022112836; $plugin->requires = 2022112800; -$plugin->release = '4.1.7'; +$plugin->release = '4.1.8'; $plugin->component = 'local_office365'; $plugin->maturity = MATURITY_STABLE; $plugin->dependencies = [ 'auth_oidc' => 2022112835, 'block_microsoft' => 2022112835, - 'local_o365' => 2022112835, + 'local_o365' => 2022112836, 'repository_office365' => 2022112825, 'theme_boost_o365teams' => 2022112825, ];