Skip to content

Commit

Permalink
Merge branch 'MDL-51514_master' of git://github.com/markn86/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllao committed Oct 5, 2015
2 parents fe73503 + 84ab39c commit cc69a29
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions lib/grade/grade_category.php
Expand Up @@ -793,15 +793,28 @@ private function set_usedinaggregation($userid, $usedweights, $novalue, $dropped

// Reset aggregation to unknown and 0 for all grade items for this user and category.
$params = array('categoryid' => $this->id, 'userid' => $userid);
$itemssql = "SELECT id
FROM {grade_items}
WHERE categoryid = :categoryid";

$sql = "UPDATE {grade_grades}
SET aggregationstatus = 'unknown',
aggregationweight = 0
WHERE userid = :userid
AND itemid IN ($itemssql)";

switch ($DB->get_dbfamily()) {
case 'mysql':
// Optimize the query for MySQL by using a join rather than a sub-query.
$sql = "UPDATE {grade_grades} g
JOIN {grade_items} gi ON (g.itemid = gi.id)
SET g.aggregationstatus = 'unknown',
g.aggregationweight = 0
WHERE g.userid = :userid
AND gi.categoryid = :categoryid";
break;
default:
$itemssql = "SELECT id
FROM {grade_items}
WHERE categoryid = :categoryid";

$sql = "UPDATE {grade_grades}
SET aggregationstatus = 'unknown',
aggregationweight = 0
WHERE userid = :userid
AND itemid IN ($itemssql)";
}

$DB->execute($sql, $params);

Expand Down

0 comments on commit cc69a29

Please sign in to comment.