Skip to content

Commit

Permalink
MDL-50894 lib/conditionlib: Occasional cron error
Browse files Browse the repository at this point in the history
Inhibit division by zero error warnings when rawgrademax and rawgrademin are
equal. The change does not affect existing functional behavior.
  • Loading branch information
Gedion Woldeselassie authored and Gedion Woldeselassie committed Jul 24, 2015
1 parent 7fa7357 commit 28b91e2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions availability/condition/grade/classes/condition.php
Expand Up @@ -228,7 +228,9 @@ protected static function get_cached_grade_score($gradeitemid, $courseid,
WHERE
gi.courseid = ?', array($userid, $courseid));
foreach ($rs as $record) {
if (is_null($record->finalgrade)) {
// This function produces division by zero error warnings when rawgrademax and rawgrademin
// are equal. Below change does not affect function behavior, just avoids the warning.
if (is_null($record->finalgrade) || $record->rawgrademax == $record->rawgrademin) {
// No grade = false.
$cachedgrades[$record->id] = false;
} else {
Expand All @@ -249,7 +251,9 @@ protected static function get_cached_grade_score($gradeitemid, $courseid,
// Just get current grade.
$record = $DB->get_record('grade_grades', array(
'userid' => $userid, 'itemid' => $gradeitemid));
if ($record && !is_null($record->finalgrade)) {
// This function produces division by zero error warnings when rawgrademax and rawgrademin
// are equal. Below change does not affect function behavior, just avoids the warning.
if ($record && !is_null($record->finalgrade) && $record->rawgrademax != $record->rawgrademin) {
$score = (($record->finalgrade - $record->rawgrademin) * 100) /
($record->rawgrademax - $record->rawgrademin);
} else {
Expand Down

0 comments on commit 28b91e2

Please sign in to comment.