Moodle
  1. Moodle
  2. MDL-40436

Error in Courses block when the user is enrolled in courses from other servers by MNet

    Details

    • Testing Instructions:
      Hide
      1. Set up MNet enrolment
      2. Check out the greatest course ID of your local site
      3. Create enough courses on your remote site to get a greater course ID
      4. On the local site enrol a student in the remote course which has an ID that does not exist on the local site.
      5. Add the Courses block on the front page of the local site.
      6. Login as the student on the local site.
      7. Make sure you can see the block and its content without errors
      Show
      Set up MNet enrolment http://docs.moodle.org/24/en/MNet#Peer_to_Peer_Network Check out the greatest course ID of your local site Create enough courses on your remote site to get a greater course ID On the local site enrol a student in the remote course which has an ID that does not exist on the local site. Add the Courses block on the front page of the local site. Login as the student on the local site. Make sure you can see the block and its content without errors
    • Affected Branches:
      MOODLE_24_STABLE
    • Fixed Branches:
      MOODLE_24_STABLE, MOODLE_25_STABLE, MOODLE_26_STABLE
    • Pull from Repository:
    • Pull 2.6 Branch:
    • Pull Master Branch:
      MDL-40436-master
    • Story Points (Obsolete):
      5
    • Sprint:
      FRONTEND Sprint 7

      Description

      If user is enrolled in courses from other host (host 2) by mnet, and block "Courses" is activated in actual host (host 1), error shown : 'Can not find data record in database table course'.

      Steps to reproduce:

      1. Enrol user (user A) in course from other host (host 2) by mnet
      2. Activate block "Courses" in Home of host 1
      3. Access with user A in host 1

      Error shown : 'Can not find data record in database table course'.

      This is because in file:

      blocks/course_list/block_course_list.php, in function get_remote_courses()

      $coursecontext = context_course::instance($course->id);
      

      That's defined in the file :

      lib/accesslib.php

      ...
      if (!$record = $DB->get_record('context', array('contextlevel'=>CONTEXT_COURSE, 'instanceid'=>$instanceid))) {
                    if ($course = $DB->get_record('course', array('id'=>$instanceid), 'id,category', $strictness)) {
      ...
      

      but $course->id not in table 'course' because it is an MNet course.

      I think solution is commented:

      blocks/course_list/block_course_list.php, get_remote_courses()

      $coursecontext = context_course::instance($course->id);
      

        Gliffy Diagrams

          Activity

          Hide
          Michael de Raadt added a comment -

          Thanks for reporting that and suggesting a solution.

          Show
          Michael de Raadt added a comment - Thanks for reporting that and suggesting a solution.
          Hide
          Frédéric Massart added a comment -

          It took me a while to get this issue sorted, I had so much problems compiling PHP on Mac to get the extension XMLRPC working...

          Anyway, I decided to remove the usage of the context entirely, rather than using the system one, because the other places where we would be using format_string() with a remote course do not provide a context at all, and so we fallback on the $PAGE one.

          Pushing for peer review.

          Show
          Frédéric Massart added a comment - It took me a while to get this issue sorted, I had so much problems compiling PHP on Mac to get the extension XMLRPC working... Anyway, I decided to remove the usage of the context entirely, rather than using the system one, because the other places where we would be using format_string() with a remote course do not provide a context at all, and so we fallback on the $PAGE one. Pushing for peer review.
          Hide
          Damyon Wiese added a comment -

          [Y] Syntax
          [Y] Whitespace
          [Y] Output
          [-] Language
          [-] Databases
          [Y] Testing (instructions and automated tests)
          [-] Security
          [-] Documentation
          [Y] Git
          [-] Third party code
          [Y] Sanity check

          The patch makes sense to me - and I can't think of anything better to do with the context for a remote course.

          I thought about whether we should unit test this - but testing mnet courses would be quite difficult just for this small bug.

          Sending for integration.

          Show
          Damyon Wiese added a comment - [Y] Syntax [Y] Whitespace [Y] Output [-] Language [-] Databases [Y] Testing (instructions and automated tests) [-] Security [-] Documentation [Y] Git [-] Third party code [Y] Sanity check The patch makes sense to me - and I can't think of anything better to do with the context for a remote course. I thought about whether we should unit test this - but testing mnet courses would be quite difficult just for this small bug. Sending for integration.
          Hide
          Sam Hemelryk added a comment -

          Thanks Fred - looks like the correct solution and has been integrated now.

          Show
          Sam Hemelryk added a comment - Thanks Fred - looks like the correct solution and has been integrated now.
          Hide
          Mark Nelson added a comment -

          Hi Fred, works as expected. I was able to replicate this (as I wanted to make sure I followed the mnet instructions correctly) and with your patch I was no longer given an error, cheers.

          Show
          Mark Nelson added a comment - Hi Fred, works as expected. I was able to replicate this (as I wanted to make sure I followed the mnet instructions correctly) and with your patch I was no longer given an error, cheers.
          Hide
          Damyon Wiese added a comment -

          Twas the week before Christmas,
          And all though HQ
          Devs were scrambling to finish peer review.
          They sent all their issues,
          and rushed out the door -
          "To the beach!" someone heard them roar!

          This issue has been released upstream. Thanks!

          Show
          Damyon Wiese added a comment - Twas the week before Christmas, And all though HQ Devs were scrambling to finish peer review. They sent all their issues, and rushed out the door - "To the beach!" someone heard them roar! This issue has been released upstream. Thanks!

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Agile