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

Convert awarding of badges to be event based

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Won't Do
    • Icon: Minor Minor
    • None
    • 2.9
    • Badges, Events API
    • MOODLE_29_STABLE
    • MDL-50342-master
    • Hide

      PHP unit tests should all continue to pass, including the new ones added by this patch.
      Manual testing would consist of creating new courses with a variety of criteria, enrolling one or more users in them, setting up badges and checking they continue to be issued by the system. A new sitewide setting in the badges section controls how many criteria are considered per request. If a badge has this number or fewer criteria, it should now be issued immediately when criteria are met (although course completion actually happens via a cron job so self-completion of a course won't immediately issue the badge).
      Mass issuing of badges will most easily be tested by setting a future course start date. An earlier event that could trigger a badge issue should now trigger the scheduling of an adhoc task to review the badge for all users when the course start date is reached.

      Show
      PHP unit tests should all continue to pass, including the new ones added by this patch. Manual testing would consist of creating new courses with a variety of criteria, enrolling one or more users in them, setting up badges and checking they continue to be issued by the system. A new sitewide setting in the badges section controls how many criteria are considered per request. If a badge has this number or fewer criteria, it should now be issued immediately when criteria are met (although course completion actually happens via a cron job so self-completion of a course won't immediately issue the badge). Mass issuing of badges will most easily be tested by setting a future course start date. An earlier event that could trigger a badge issue should now trigger the scheduling of an adhoc task to review the badge for all users when the course start date is reached.

      This patch switches Moodle's issuing of badges from being cron based to event based where possible and implements batching via an adhoc task when mass (re)checks of criteria are required. This avoids unnecessary and inefficient checking and rechecking of criteria that haven't yet been fulfilled when nothing has changed since the last cron run. A new admin setting controls the size of batches (default is 500). It should be noted that the batchsize is the number of criteria that are rechecked, not the number of badges that will be checked/issued. This means more complex badges won't still cause problems.

      New functions in lib/classes/task/manager allow us to update an existing adhoc task so that if a badge that is already undergoing a batch review has something changed that would start another review, we simply reset the current review to the beginning.

      The patch has grown a lot since it was first developed, due to feedback from Simey and Yulia. Despite its size, it has still been made as simple as possible. It checks the criteria for all unissued badges for a user when an event occurs that could result in criteria being fulfilled. Further optimisations could potentially provide the ability to just check the criteria (if any) related to the event.

      The patch maintains the previous behaviour of not issuing badges prior to a course start date. To achieve this, it schedules a badge for review after the course start date where appropriate, skipping all checking of other criteria until that time.

      Finally, additional tests are of course added to confirm the correct operation of the new code.

            Unassigned Unassigned
            nigelccatalyst Nigel Cunningham
            Simey Lameze Simey Lameze
            Votes:
            1 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.