Moodle
  1. Moodle
  2. MDL-40436

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

    Details

    • Story Points:
      5
    • Rank:
      53542
    • 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);
      

        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