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

Badges - Delete a course with activity driven badges - fatal badge error

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.1.5, 3.2, 3.3
    • Fix Version/s: 3.2.5, 3.3.2
    • Component/s: Badges
    • Labels:
    • Testing Instructions:
      Hide
      1. Add activity completion to an activity on a Moodle course
      2. Create a new badge and set the criteria to require completion of that activity
      3. Enable the badge
      4. Have a student complete the activity and be awarded the badge
      5. Edit the course completion criteria and set such that 'Any' criteria satisfies it. Set the course to be complete if the activity created above is complete.
      6. Create a new badge and assign it's criteria to 'course completion'
      7. Run cron. The student should now have a badge for completing the course too. Confirm this.
      8. Delete the course
      9. Visit the student's profile
      10. Click on both the badge from the deleted course  - the one from the activity completion and the one from the course completion.

      Before this patch there will be an error message saying "record not found". After it there will be a form (see the screen shot badge_after_coursedelete.....) warning that the activity is no longer available.

      Show
      Add activity completion to an activity on a Moodle course Create a new badge and set the criteria to require completion of that activity Enable the badge Have a student complete the activity and be awarded the badge Edit the course completion criteria and set such that 'Any' criteria satisfies it. Set the course to be complete if the activity created above is complete. Create a new badge and assign it's criteria to 'course completion' Run cron. The student should now have a badge for completing the course too. Confirm this. Delete the course Visit the student's profile Click on both the badge from the deleted course  - the one from the activity completion and the one from the course completion. Before this patch there will be an error message saying "record not found". After it there will be a form (see the screen shot badge_after_coursedelete.....) warning that the activity is no longer available.
    • Difficulty:
      Easy
    • Affected Branches:
      MOODLE_31_STABLE, MOODLE_32_STABLE, MOODLE_33_STABLE
    • Fixed Branches:
      MOODLE_32_STABLE, MOODLE_33_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-59049-master
    • Sprint:
      3.4 Sprint 4

      Description

      If you have badges on a course which are driven by activity completion criteria, which are awarded to users, then later on the course is deleted, the badge remains on their profile, but when you click on it, you get a fatal error "Can not find data record in database".

      Steps:

      • Add activity completion to an activity on a Moodle course
      • Create a new badge and set the criteria to require completion of that activity
      • Enable the badge
      • Have a student complete the activity and be awarded the badge
      • Delete the course
      • Visit the student's profile
      • Click on the badge from the deleted course

       
      Can not find data record in database.

      More information about this error
      Debug info: SELECT c.id, c.enablecompletion, c.cacherev, c.startdate
      FROM {badge} b INNER JOIN {course} c ON b.courseid = c.id
      WHERE b.id = :badgeid
      [array (
      'badgeid' => '2562',
      )]
      Error code: invalidrecordunknown
       
      The problem lies in line 49 of /badges/criteria/award_criteria_activity.php:
       
       

      $this->course = $DB->get_record_sql('SELECT c.id, c.enablecompletion, c.cacherev, c.startdate
       FROM {badge} b INNER JOIN {course} c ON b.courseid = c.id
       WHERE b.id = :badgeid ', array('badgeid' => $this->badgeid), MUST_EXIST);  

      The "MUST_EXIST" flag causes the error, since the course no longer exists.
       
      For our Moodle i've removed that flag, but I don't know if you want to come up with a different way around it for the core badges code, if you really need the MUST_EXIST flag.
       
       
       

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                11/Sep/17