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

Award badges task fails when badge requires multiple deleted activities

XMLWordPrintable

    • MOODLE_401_STABLE, MOODLE_402_STABLE
    • MOODLE_402_STABLE, MOODLE_403_STABLE
    • MDL-79091-MOODLE_403_STABLE
    • Hide

      Disable the badge associated with a deleted module. On the course page, go to the Badges menu => Manage badges => Edit the badge (cog icon) then deactivate the badge

      To get the badge you can use the following SQL, replacing YOUR_CMID to the proper value:

      SELECT b.id AS badgeid, b.name AS badge_name, b.courseid AS courseid, c.shortname AS course_shortname
      FROM mdl_badge b
      JOIN mdl_badge_criteria bc ON bc.badgeid = b.id
      JOIN mdl_badge_criteria_param bcp ON bcp.critid = bc.id
      JOIN mdl_course c ON c.id = b.courseid
      WHERE bcp.name = CONCAT("module_", "YOUR_CMID");

       

      Show
      Disable the badge associated with a deleted module. On the course page, go to the Badges menu => Manage badges => Edit the badge (cog icon) then deactivate the badge To get the badge you can use the following SQL, replacing YOUR_CMID to the proper value: SELECT b.id AS badgeid, b.name AS badge_name, b.courseid AS courseid, c.shortname AS course_shortname FROM mdl_badge b JOIN mdl_badge_criteria bc ON bc.badgeid = b.id JOIN mdl_badge_criteria_param bcp ON bcp.critid = bc.id JOIN mdl_course c ON c.id = b.courseid WHERE bcp.name = CONCAT( "module_" , "YOUR_CMID" );  
    • Hide

      Setup

      1. Fresh Moodle site. IMPORTANT: Steps assume you are running locally, without a cronjob running.
      2. Go to Site administration > Server > System paths and set "pathtophp" with the proper value for your environment.

       

      Testing instructions

      1. Login as admin
      2. Create a new course: "Badge Test"
        1. Go to "Site Administration > Courses > Add a new course"
        2. Fill in Course full name as "Badge Test"
        3. Fill out Course short name as "badge"
        4. Change start date to be in the past
        5. Press Save and Display
      3. Enrol yourself in the new course
      4. Create 2 quiz assessments on "Badge Test" course, "Quiz 1" and "Quiz 2". No questions need to be added to them.
      5. Create some test badges
        1. In the course go to "More > Badges"
        2. Press Add a new Badge
          1. Enter a new badge name "Valid Badge"
          2. Fill in any description
          3. Upload/Select any image
        3. Press Create badge
        4. Change the dropdown to Course completion
        5. Enter 50 in grade
        6. Press save
        7. Press Enable Access
        8. Press Continue
        9. Press back
        10. Press Add a new badge
          1. Enter name as "Invalid badge"
          2. Enter any description
          3. Upload any image
        11. Press Create badge
        12. In the dropdown select activity completion
        13. Tick both quizzes
        14. Expand "This criterion is complete when" and select all
        15. Press Save
        16. Press Enable access
        17. Press Continue
      6. Delete the 2 quizzes from the course (Quiz 1 and Quiz 2).
      7. Completely remove the quizzes from the site:
        1. Go to "Site Administration > Server > Ad hoc tasks"
        2. Press the "Run all" link from the row "course_delete_modules"
        3. Press "Run adhoc tasks now" button
      8. Create the adhoc tasks:
        1. Go to "Site administration > Server > Scheduled Tasks"
        2. Press "Run now" on the row with the task "Add award badges adhoc tasks"
        3. Press "Run now" on the confirmation
      9. Run the adhoc tasks:
        1. Go to "Site Administration > Server > Ad hoc tasks"
        2. Press "Run all" next to "badges_adhoc_task"
        3. Press Confirm
      10. Confirm tasks have all been processed without error
        1. Confirm for the line Badge #: Valid Badge: badge was issued to 0 users.
        2. Confirm for the line Badge #: Invalid Badge: has invalid course modules, it has been made inactive https://moodle.localhost/badges/edit.php?id=#&action=badge
        3. If both the above lines are in the log shown, without any errors then both badges were processed
      11. Go to the Course > More > Badges > Manage badges" and confirm the "Invalid badge" has been automatically disabled.
      Show
      Setup Fresh Moodle site. IMPORTANT: Steps assume you are running locally, without a cronjob running. Go to Site administration > Server > System paths and set "pathtophp" with the proper value for your environment.   Testing instructions Login as admin Create a new course: "Badge Test" Go to "Site Administration > Courses > Add a new course" Fill in Course full name as "Badge Test" Fill out Course short name as "badge" Change start date to be in the past Press Save and Display Enrol yourself in the new course Create 2 quiz assessments on "Badge Test" course, "Quiz 1" and "Quiz 2". No questions need to be added to them. Create some test badges In the course go to "More > Badges" Press Add a new Badge Enter a new badge name "Valid Badge" Fill in any description Upload/Select any image Press Create badge Change the dropdown to Course completion Enter 50 in grade Press save Press Enable Access Press Continue Press back Press Add a new badge Enter name as "Invalid badge" Enter any description Upload any image Press Create badge In the dropdown select activity completion Tick both quizzes Expand "This criterion is complete when" and select all Press Save Press Enable access Press Continue Delete the 2 quizzes from the course (Quiz 1 and Quiz 2). Completely remove the quizzes from the site: Go to "Site Administration > Server > Ad hoc tasks" Press the "Run all" link from the row "course_delete_modules" Press "Run adhoc tasks now" button Create the adhoc tasks: Go to "Site administration > Server > Scheduled Tasks" Press "Run now" on the row with the task "Add award badges adhoc tasks" Press "Run now" on the confirmation Run the adhoc tasks: Go to "Site Administration > Server > Ad hoc tasks" Press "Run all" next to "badges_adhoc_task" Press Confirm Confirm tasks have all been processed without error Confirm for the line Badge #: Valid Badge: badge was issued to 0 users. Confirm for the line Badge #: Invalid Badge: has invalid course modules, it has been made inactive https://moodle.localhost/badges/edit.php?id=#&action=badge If both the above lines are in the log shown, without any errors then both badges were processed Go to the Course > More > Badges > Manage badges" and confirm the "Invalid badge" has been automatically disabled.

      When you create a badge that requires two activities to be completed in order to earn it and then delete these two activities, the task "Award badges" (core\task\badges_cron_task) fails with:

      Execute scheduled task: Award badges (core\task\badges_cron_task)
      ... started 17:15:58. Current memory use 3.4 MB.
      Started reviewing available badges.
      Processing badge "Badge mit fehlenden Voraussetzungen"...
      ... used 18 dbqueries
      ... used 0.13122606277466 seconds
      Scheduled task failed: Award badges (core\task\badges_cron_task),Invalid course module ID: 5585
      Backtrace:
      * line 2242 of /lib/modinfolib.php: call to course_modinfo->get_cm()
      * line 1049 of /lib/completionlib.php: call to cm_info::create()
      * line 204 of /badges/criteria/award_criteria_activity.php: call to completion_info->get_data()
      * line 536 of /badges/classes/badge.php: call to award_criteria_activity->review()
      * line 82 of /lib/classes/task/badges_cron_task.php: call to core_badges\badge->review_all_criteria()
      * line 263 of /lib/cronlib.php: call to core\task\badges_cron_task->execute()
      * line 167 of /admin/cli/scheduled_task.php: call to cron_run_inner_scheduled_task()
      

      Since the task just fails and doesn't continue with the other badges, you can have one badge with invalid criteria preventing all other badges from being awarded. Letting the task fail is good in that it brings the problem of invalid criteria to the attention of admins. But in my opinion it shouldn't prevent other badges with correctly setup criteria from being awarded.

            jay-oswald Jay Oswald
            tschroeder Tim Schroeder
            Brendan Heywood Brendan Heywood
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            17 Vote for this issue
            Watchers:
            20 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 hours, 42 minutes
                4h 42m

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