Moodle
  1. Moodle
  2. MDL-39932

Mapping Feedback when Course is Deleted

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major 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 2.4 Branch:
    • Pull 2.5 Branch:
    • Pull Master Branch:
      MDL-39932_master
    • Rank:
      50684

      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).

        Activity

        Hide
        David N. Johnson added a comment -

        Patch to fix issue.

        Show
        David N. Johnson added a comment - Patch to fix issue.
        Hide
        Helen Foster added a comment -

        David, thanks a lot for your detailed report with patch. Hopefully it can be reviewed soon.

        Show
        Helen Foster added a comment - David, thanks a lot for your detailed report with patch. Hopefully it can be reviewed soon.
        Hide
        Andreas Grabs added a comment -

        Hi David, thank you for your contribution!
        By the way I have just fixed the strict message and the missing baseurl for flexible_table.
        Best regards
        Andreas

        Show
        Andreas Grabs added a comment - Hi David, thank you for your contribution! By the way I have just fixed the strict message and the missing baseurl for flexible_table. Best regards Andreas
        Hide
        David N. Johnson added a comment -

        Nice one, I figured this would sit on the tracker for a couple months before anyone looked at it. Great response time.

        Show
        David N. Johnson added a comment - Nice one, I figured this would sit on the tracker for a couple months before anyone looked at it. Great response time.
        Hide
        Eloy Lafuente (stronk7) added a comment -

        Integrated (23, 24, 25 & master), thanks!

        Show
        Eloy Lafuente (stronk7) added a comment - Integrated (23, 24, 25 & master), thanks!
        Hide
        Petr Škoda added a comment -

        works fine here, thanks

        Show
        Petr Škoda added a comment - works fine here, thanks
        Hide
        Dan Poltawski added a comment -
        Feature: Thanks to our superb contributors
          In order to make Moodle better
          As an integrator
          I need to thank all our contributors
        
          Scenario: Dan thanks you all
            Given I log in as "dan"
            And I see "lots of fixed issues"
            When I follow "Close integrated issues"
            Then I should see "Lots of thanks to all our contributors"
        

        Your changes are upstream

        Show
        Dan Poltawski added a comment - Feature: Thanks to our superb contributors In order to make Moodle better As an integrator I need to thank all our contributors Scenario: Dan thanks you all Given I log in as "dan" And I see "lots of fixed issues" When I follow "Close integrated issues" Then I should see "Lots of thanks to all our contributors" Your changes are upstream

          People

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

            Dates

            • Created:
              Updated:
              Resolved: