Skip to content

Commit 11a5adb

Browse files
committed
Fix MSSQL-incompatible SQL query
Use the parameter $limitnum of the get_records_sql method. This provides the means to limit the records to only the first one and is database-agnostic.
1 parent f784b76 commit 11a5adb

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Diff for: classes/review.php

+9-7
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,20 @@ public static function get_first_review_post($moodleoverflowid, $afterpostid = n
107107
$addwhere = ' AND p.id != :notpostid ';
108108
$params['notpostid'] = $afterpostid;
109109
}
110-
$record = $DB->get_record_sql(
110+
$records = $DB->get_records_sql(
111111
'SELECT p.id as postid, p.discussion as discussionid FROM {moodleoverflow_posts} p ' .
112112
'JOIN {moodleoverflow_discussions} d ON d.id = p.discussion ' .
113113
"WHERE p.reviewed = 0 AND d.moodleoverflow = :moodleoverflowid AND p.created < :reviewtime $addwhere " .
114-
"ORDER BY $orderby p.discussion, p.id " .
115-
'LIMIT 1',
116-
$params
114+
"ORDER BY $orderby p.discussion, p.id ",
115+
$params,
116+
0,
117+
1
117118
);
118-
if ($record) {
119+
$key = array_key_first($records);
120+
if ($key) {
119121
return (new \moodle_url('/mod/moodleoverflow/discussion.php', [
120-
'd' => $record->discussionid,
121-
], 'p' . $record->postid))->out(false);
122+
'd' => $records[$key]->discussionid,
123+
], 'p' . $records[$key]->postid))->out(false);
122124
} else {
123125
return null;
124126
}

0 commit comments

Comments
 (0)