Moodle
  1. Moodle
  2. MDL-29274

People block returns wrong context to user/index.php if block added to module

    Details

    • Rank:
      18815

      Description

      try adding the people block to a forum. then click on the participants link inside it..
      it throws a context error. This seems to be a regression, it was reported and fixed in MDL-13252.

        Issue Links

          Activity

          Hide
          Michael de Raadt added a comment -

          Increasing the priority on this as it has now been replicated.

          Show
          Michael de Raadt added a comment - Increasing the priority on this as it has now been replicated.
          Hide
          Dan Poltawski added a comment -

          Hi Raj,

          If you look at the docs for get_course_context() method it says:

          @deprecated since 2.2, use $context->get_course_context() instead
          

          So instead you can do:
          $this->page->context->get_course_context()

          Show
          Dan Poltawski added a comment - Hi Raj, If you look at the docs for get_course_context() method it says: @deprecated since 2.2, use $context->get_course_context() instead So instead you can do: $this->page->context->get_course_context()
          Hide
          Rajesh Taneja added a comment -

          Thanks for pointing that Dan,
          Branches updated and up for another review

          Show
          Rajesh Taneja added a comment - Thanks for pointing that Dan, Branches updated and up for another review
          Hide
          Dan Poltawski added a comment -

          Looks good!

          Show
          Dan Poltawski added a comment - Looks good!
          Hide
          Rajesh Taneja added a comment -

          Sorry Dan,
          I have updated the branch again. I encountered one regression while upgrading site.
          If this block is placed on front page and we try to upgrade, context passed is SYSTEM_CONTEXT and it fails.
          So I have updated the code which will take care of it.

          Once more for your review.

          Show
          Rajesh Taneja added a comment - Sorry Dan, I have updated the branch again. I encountered one regression while upgrading site. If this block is placed on front page and we try to upgrade, context passed is SYSTEM_CONTEXT and it fails. So I have updated the code which will take care of it. Once more for your review.
          Hide
          Dan Poltawski added a comment -

          Looks good

          Show
          Dan Poltawski added a comment - Looks good
          Hide
          Rajesh Taneja added a comment -

          Thanks Dan

          Show
          Rajesh Taneja added a comment - Thanks Dan
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Integrated, thanks! (20, 21 & master)

          Show
          Eloy Lafuente (stronk7) added a comment - Integrated, thanks! (20, 21 & master)
          Hide
          Jason Fowler added a comment -

          All good

          Show
          Jason Fowler added a comment - All good
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Well,

          I wish I said it every time
          you do the things you do.
          You always lend a helping hand,
          and I'm filled with gratitude.

          You are strong and generous
          for each and everyone one of us.
          I am eternally grateful,
          I cannot say thanks enough.

          Sorry for the (un)cool bit above, lol. Closing this as fixed. Ciao

          Show
          Eloy Lafuente (stronk7) added a comment - Well, I wish I said it every time you do the things you do. You always lend a helping hand, and I'm filled with gratitude. You are strong and generous for each and everyone one of us. I am eternally grateful, I cannot say thanks enough. Sorry for the (un)cool bit above, lol. Closing this as fixed. Ciao
          Hide
          Peter Ruthven-Stuart added a comment - - edited

          Hello,

          I am preparing to upgrade from 2.0.7+ to 2.2.1+ via 2.1.4., and am now practising on a clone of my moodle system.

          The upgrade from 2.0.7 to 2.1.4+ went OK. However, when trying to access a course containing a 'People' block I get the following error:

          Fatal error: Call to undefined method stdClass::get_course_context() in /Library/WebServer/Documents/moodle22/blocks/participants/block_participants.php on line 23

          Commenting out line 23 'fixes' the problem; the course page loads, but there is no 'participants' link in the people block. Note, this error does not appear in the 2.0.7 system which was updated this morning (4th March).

          Comparing the two files (block_participants.php) in the 2.0.7 and 2.1.4 installations I see there have been some small changes, and in the version 2.0.7 file there is a reference to MDL-13252, which bought me here.

          UPDATE: I continued on to upgrade to 2.2.1+, and the 'Fatal error' message reported above no longer appears.

          MySQL: 5.1.42
          PHP: 5.3.8

          Show
          Peter Ruthven-Stuart added a comment - - edited Hello, I am preparing to upgrade from 2.0.7+ to 2.2.1+ via 2.1.4., and am now practising on a clone of my moodle system. The upgrade from 2.0.7 to 2.1.4+ went OK. However, when trying to access a course containing a 'People' block I get the following error: Fatal error: Call to undefined method stdClass::get_course_context() in /Library/WebServer/Documents/moodle22/blocks/participants/block_participants.php on line 23 Commenting out line 23 'fixes' the problem; the course page loads, but there is no 'participants' link in the people block. Note, this error does not appear in the 2.0.7 system which was updated this morning (4th March). Comparing the two files (block_participants.php) in the 2.0.7 and 2.1.4 installations I see there have been some small changes, and in the version 2.0.7 file there is a reference to MDL-13252, which bought me here. UPDATE: I continued on to upgrade to 2.2.1+, and the 'Fatal error' message reported above no longer appears. MySQL: 5.1.42 PHP: 5.3.8
          Hide
          James O'Dell added a comment -

          This problem may be solved for 2.2. But NOT for 2.1. People Block uses the function 'get_course_context'
          Moodle 2.1 expects the object 'context', while Moodle 2.2 expects a 'boolean'

          ---- 2.1
          ---- /**
          ---- * Find course context
          ---- * @param object $context - course or lower context
          ---- * @return object context of the enclosing course, throws exception when related course context found
          ---- */
          ---- function get_course_context($context) {

          ---- 2.2
          ---- /**
          ---- * Is this context part of any course? If yes return course context.
          ---- *
          ---- * @param bool $strict true means throw exception if not found, false means return false if not found
          ---- * @return course_context context of the enclosing course, null if not found or exception
          ---- */
          ---- public function get_course_context($strict = true) {

          The 'fix', which shows up in both Moodle 2.1 repositories(git and cvs) uses '$this->page->context->get_course_context(false)' - a boolean.

          Currently if you update to moodle 2.1.4+ (Build: 20120301) you can expect any course which has the 'People'
          block to display an entirely blank page.

          If you go back the previous version where '$currentcontext = $this->page->context;' and it works again.

          Some one needs to fix the repositories for Moodle 2.1 ...

          Imho, poor regression testing for Moodle 2.1 core stable!

          Show
          James O'Dell added a comment - This problem may be solved for 2.2. But NOT for 2.1. People Block uses the function 'get_course_context' Moodle 2.1 expects the object 'context', while Moodle 2.2 expects a 'boolean' ---- 2.1 ---- /** ---- * Find course context ---- * @param object $context - course or lower context ---- * @return object context of the enclosing course, throws exception when related course context found ---- */ ---- function get_course_context($context) { ---- 2.2 ---- /** ---- * Is this context part of any course? If yes return course context. ---- * ---- * @param bool $strict true means throw exception if not found, false means return false if not found ---- * @return course_context context of the enclosing course, null if not found or exception ---- */ ---- public function get_course_context($strict = true) { The 'fix', which shows up in both Moodle 2.1 repositories(git and cvs) uses '$this->page->context->get_course_context(false)' - a boolean. Currently if you update to moodle 2.1.4+ (Build: 20120301) you can expect any course which has the 'People' block to display an entirely blank page. If you go back the previous version where '$currentcontext = $this->page->context;' and it works again. Some one needs to fix the repositories for Moodle 2.1 ... Imho, poor regression testing for Moodle 2.1 core stable!
          Hide
          Rajesh Taneja added a comment -

          Thanks for pointing that James,

          I am creating a new bug to fix this regression.

          Show
          Rajesh Taneja added a comment - Thanks for pointing that James, I am creating a new bug to fix this regression.

            People

            • Votes:
              13 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: