Moodle
  1. Moodle
  2. MDL-32308

fatal error when viewing user profile when not logged in under some circumstances

    Details

    • Rank:
      39106

      Description

      Problem arises because of the following

      $USER->id is 0, set on line 292 of lib/sessionlib.php (check_user_initialised)

      executes last statement of this if statement on line 262 of user/profile.php
      if ($currentuser
      or $user->maildisplay == 1
      or has_capability('moodle/course:useremail', $context)
      or ($user->maildisplay == 2 and enrol_sharing_course($user, $USER))) {

      which ends up testing !empty($user2->id) on line 268 of lib/enrollib.php (enrol_get_shared_courses)
      where $user2 === $USER

      The empty function (http://php.net/manual/en/function.empty.php) returns true when the variable is 0. This is not the wanted behaviour.

      A fix would be to change this to use isset instead of !empty

      A stack trace is below, a patch is attached

      Coding error detected, it must be fixed by a programmer: PHP catchable fatal error

      More information about this error

      Debug info: Object of class stdClass could not be converted to string
      Stack trace:
      line 359 of /lib/setuplib.php: coding_exception thrown
      line ? of unknownfile: call to default_error_handler()
      line 636 of /lib/dml/pgsql_native_moodle_database.php: call to pg_query_params()
      line 1587 of /lib/dml/moodle_database.php: call to pgsql_native_moodle_database->get_recordset_sql()
      line 297 of /lib/enrollib.php: call to moodle_database->record_exists_sql()
      line 237 of /lib/enrollib.php: call to enrol_get_shared_courses()
      line 267 of /user/profile.php: call to enrol_sharing_course()

        Activity

        Hide
        Petr Škoda added a comment -

        Thanks for the report, I will send it to the next integration.

        Show
        Petr Škoda added a comment - Thanks for the report, I will send it to the next integration.
        Hide
        Petr Škoda added a comment -

        Thanks a lot for the report and the patch!

        Show
        Petr Škoda added a comment - Thanks a lot for the report and the patch!
        Hide
        Sam Hemelryk added a comment -

        Thanks Petr - this has been integrated now

        Show
        Sam Hemelryk added a comment - Thanks Petr - this has been integrated now
        Hide
        Adrian Greeve added a comment -

        Tested in 2.1, 2.2 and master. No problems found. Test passed.
        Thanks.

        Show
        Adrian Greeve added a comment - Tested in 2.1, 2.2 and master. No problems found. Test passed. Thanks.
        Hide
        Dan Poltawski added a comment -

        Jolly good show!

        Your changes have made it into the Moodle release - its time to celebrate! I suggest a hot cup of English tea (with milk, no sugar) or a hoppy English ale.

        Tally-ho!

        Show
        Dan Poltawski added a comment - Jolly good show! Your changes have made it into the Moodle release - its time to celebrate! I suggest a hot cup of English tea (with milk, no sugar) or a hoppy English ale. Tally-ho!
        Hide
        Aaricia Thorgalson added a comment -

        Hello,
        I don't know if it is the same bug or not, but I have upgraded to Moodle 2.2.4 and when we want to see the participant's profile in a course, for instance:

        https://learning.health.org.kw/user/view.php?id=37&course=42

        We get the following error:
        Coding error detected, it must be fixed by a programmer: PHP catchable fatal error

        I have checked that we in the enrollib.php file we have the patch described:
        $user1 = !empty($user1->id) ? $user1->id : $user1;

        • $user2 = !empty($user2->id) ? $user2->id : $user2;
          + $user1 = isset($user1->id) ? $user1->id : $user1;
          + $user2 = isset($user2->id) ? $user2->id : $user2;

        if (empty($user1) or empty($user2)) {
        return false;

        If you try to access the user's profile through the url:

        https://learning.health.org.kw/user/view.php?id=37, it is working

        Do you think that it is the same bug or a different one?

        The only difference is when you add &course=course_id in the url

        Show
        Aaricia Thorgalson added a comment - Hello, I don't know if it is the same bug or not, but I have upgraded to Moodle 2.2.4 and when we want to see the participant's profile in a course, for instance: https://learning.health.org.kw/user/view.php?id=37&course=42 We get the following error: Coding error detected, it must be fixed by a programmer: PHP catchable fatal error I have checked that we in the enrollib.php file we have the patch described: $user1 = !empty($user1->id) ? $user1->id : $user1; $user2 = !empty($user2->id) ? $user2->id : $user2; + $user1 = isset($user1->id) ? $user1->id : $user1; + $user2 = isset($user2->id) ? $user2->id : $user2; if (empty($user1) or empty($user2)) { return false; If you try to access the user's profile through the url: https://learning.health.org.kw/user/view.php?id=37 , it is working Do you think that it is the same bug or a different one? The only difference is when you add &course=course_id in the url
        Hide
        Petr Škoda added a comment -

        Hello Aaricia, please create a new issue and describe there the exact steps to reproduce your problems, thank you.

        Show
        Petr Škoda added a comment - Hello Aaricia, please create a new issue and describe there the exact steps to reproduce your problems, thank you.
        Hide
        Aaricia Thorgalson added a comment -

        Hello Petr,

        I researched into this and I discovered that it is a complete different bug, as it is caused by the ILP 2.0 block of the ULCC in London.

        Basically,when you have that block in the course, it causes an exception of line 96:
        Debug info: Argument 2 passed to has_capability() must be an instance of context, boolean given, called in ...\blocks\ilp\block_ilp.php on line 96
        and defined

        so I will post it in the ILP forum. Nothing to do with the core files of Moodle.

        Thank you

        Show
        Aaricia Thorgalson added a comment - Hello Petr, I researched into this and I discovered that it is a complete different bug, as it is caused by the ILP 2.0 block of the ULCC in London. Basically,when you have that block in the course, it causes an exception of line 96: Debug info: Argument 2 passed to has_capability() must be an instance of context, boolean given, called in ...\blocks\ilp\block_ilp.php on line 96 and defined so I will post it in the ILP forum. Nothing to do with the core files of Moodle. Thank you

          People

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

            Dates

            • Created:
              Updated:
              Resolved: