Skip to content

Commit

Permalink
Fix PostgreSQL incompatibility issue and bug in DB queries in local_o…
Browse files Browse the repository at this point in the history
…365 tool pages
  • Loading branch information
weilai-irl committed Jul 3, 2024
1 parent 8f2b5fc commit f0ef843
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
3 changes: 1 addition & 2 deletions classes/feature/courserequest/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [];
Expand Down
20 changes: 10 additions & 10 deletions classes/feature/coursesync/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion classes/feature/coursesync/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) : [];
Expand Down
8 changes: 4 additions & 4 deletions classes/page/acp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Expand All @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit f0ef843

Please sign in to comment.