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

Mapping Feedback when Course is Deleted

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.7, 2.4.4, 2.5, 2.6
    • Fix Version/s: 2.3.8, 2.4.5, 2.5.1
    • Component/s: Feedback
    • Labels:
    • Testing Instructions:
      Hide
      1. Activate the feedback activity at the "Manage activities" page
      2. Create at least one course
      3. Create a feedback on the frontpage
      4. Go to "map feedback to courses" and map the created course to this feedback
      5. Due to the wrong usage of id in this issue you may have to do this mapping more than one times until you have an id in the table "feedback sitecourse map" that is not equal to any id in the course table.
      6. Before this fix there was shown an error
      Show
      Activate the feedback activity at the "Manage activities" page Create at least one course Create a feedback on the frontpage Go to "map feedback to courses" and map the created course to this feedback Due to the wrong usage of id in this issue you may have to do this mapping more than one times until you have an id in the table "feedback sitecourse map" that is not equal to any id in the course table. Before this fix there was shown an error
    • Affected Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE, MOODLE_26_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-39932_master

      Description

      When mapping feedback to a course, an error will be received if a course is deleted that happens to have the same id as that of the row in the feedback_sitecourse_map table.

      Steps to reproduce:
      1. Start with a fresh Moodle install.
      2. Create 2 courses (any format)
      3. Delete the first course (where courseid = 1)
      4. Create a Feedback Module
      5. Select "Map feedback to courses" then search and map to the 2nd course
      6. After 'mapping' has completed (i.e. the page refreshes), this error will appear:

      "Can not find data record in database table course."
       
      Debugging trace:
      	Debug info: SELECT id,category FROM {course} WHERE id = ?
      	[array (
      		0 => '1',
      	)]
      	Error code: invalidrecord
      	Stack trace:
      	    line 1372 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
      	    line 1348 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
      	    line 6576 of /lib/accesslib.php: call to moodle_database->get_record()
      	    line 133 of /mod/feedback/mapcourse.php: call to context_course::instance()
      

      If we look at the guilty line:

      133. $cmapcontext = context_course::instance($cmap->id);
      134. $cmapshortname = format_string($cmap->shortname, true, array('context' => $cmapcontext));
      135. $coursecontext = context_course::instance($cmap->courseid);
      136. $cmapfullname = format_string($cmap->fullname, true, array('context' => $coursecontext));
      

      A course context is being created using the 'id' primary key of the 'feedback_sitecourse_map' table. Naturally a course with this 'courseid' does not exist since we've deleted it. I'm not that well-versed in Moodle code but presumably a context shouldn't be created based on the mapping module but of the course itself. Which leads me to believe the above 4 lines should be re-written as:

      133. $coursecontext = context_course::instance($cmap->courseid);
      134. $cmapshortname = format_string($cmap->shortname, true, array('context' => $coursecontext));
      135. $cmapfullname = format_string($cmap->fullname, true, array('context' => $coursecontext));
      

      If this makes sense, I'll attach a git patch that solves the problem (tested and working on our dev system but not extensively).

        Gliffy Diagrams

          Attachments

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  8/Jul/13