Skip to content

Commit

Permalink
MDL-62167 core_badges: Prevent SQL error with Oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
FMCorz authored and stronk7 committed May 1, 2018
1 parent 2cff7ff commit 0318b52
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions badges/classes/privacy/provider.php
Expand Up @@ -205,23 +205,23 @@ public static function export_user_data(approved_contextlist $contextlist) {
$params = [];

if (!empty($contexts[CONTEXT_SYSTEM])) {
$sqls[] = "type = :typesite";
$sqls[] = "b.type = :typesite";
$params['typesite'] = BADGE_TYPE_SITE;
}

if (!empty($contexts[CONTEXT_COURSE])) {
list($insql, $inparams) = $DB->get_in_or_equal($contexts[CONTEXT_COURSE], SQL_PARAMS_NAMED);
$sqls[] = "(type = :typecourse AND courseid $insql)";
$sqls[] = "(b.type = :typecourse AND b.courseid $insql)";
$params = array_merge($params, ['typecourse' => BADGE_TYPE_COURSE], $inparams);
}

$sqlwhere = '(' . implode(' OR ', $sqls) . ')';
$sql = "
SELECT *, COALESCE(courseid, 0) AS normalisedcourseid
FROM {badge}
WHERE (usermodified = :userid1 OR usercreated = :userid2)
SELECT b.*, COALESCE(b.courseid, 0) AS normalisedcourseid
FROM {badge} b
WHERE (b.usermodified = :userid1 OR b.usercreated = :userid2)
AND $sqlwhere
ORDER BY courseid, id";
ORDER BY b.courseid, b.id";
$params = array_merge($params, ['userid1' => $userid, 'userid2' => $userid]);
$recordset = $DB->get_recordset_sql($sql, $params);
static::recordset_loop_and_export($recordset, 'normalisedcourseid', [], function($carry, $record) use ($userid) {
Expand Down

0 comments on commit 0318b52

Please sign in to comment.