Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-50894

Cron Error: division by zero warning in lib/conditionlib.php

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      Steps to reproduce it using the Interface (with the patch not applied/reverted):

      1: Enable availability (admin/settings.php?section=optionalsubsystems)
      2: For a specific quiz/assignment, make the row grade min/max values equal to force a division by zero and have its finalgrade set.
      3: Set up conditional availability in (course/modedit.php) (example, have the assignment in step #2 be dependent on the completion of another assignment/quiz)
      4: Clear cache
      5. Login as an enrolled student to the course and visit the course page to induce the error.

      After the above 5 steps, if you check the log file, you should see the bellow message.

      PHP Warning: Division by zero in lib/conditionlib.php on line 1221

      Once the warning is reproducible consistently for new enrolled users...

      6: Apply the patch, enrol some new users and log in with them, visiting the course page.
      7: There shouldn't be more PHP Warnings at all.

      Show
      Steps to reproduce it using the Interface (with the patch not applied/reverted): 1: Enable availability (admin/settings.php?section=optionalsubsystems) 2: For a specific quiz/assignment, make the row grade min/max values equal to force a division by zero and have its finalgrade set. 3: Set up conditional availability in (course/modedit.php) (example, have the assignment in step #2 be dependent on the completion of another assignment/quiz) 4: Clear cache 5. Login as an enrolled student to the course and visit the course page to induce the error. After the above 5 steps, if you check the log file, you should see the bellow message. PHP Warning: Division by zero in lib/conditionlib.php on line 1221 Once the warning is reproducible consistently for new enrolled users... 6: Apply the patch, enrol some new users and log in with them, visiting the course page. 7: There shouldn't be more PHP Warnings at all.
    • Affected Branches:
      MOODLE_28_STABLE, MOODLE_29_STABLE, MOODLE_30_STABLE
    • Fixed Branches:
      MOODLE_28_STABLE, MOODLE_29_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-50894_master

      Description

      When you run a cron a

      $ php admin/cli/cron.php

      The below warning is displayed.

      PHP Warning: Division by zero in lib/conditionlib.php on line 1221

      This error comes from the below division in get_cached_grade_score when it runs across grades with zero rawgrademax value. There are grade items with grademax set to zero. This code should handle such grade items without throwing errors.

              foreach ($rs as $record) {
                          $cachedgrades[$record->id] =
                              is_null($record->finalgrade)
                                  // No grade = false
                                  ? false
                                  // Otherwise convert grade to percentage
                                  : (($record->finalgrade - $record->rawgrademin) * 100) /
                                      ($record->rawgrademax - $record->rawgrademin);
      

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  14/Sep/15