Moodle
  1. Moodle
  2. MDL-39947

PHP Notice when counting unread forum posts

    Details

    • Testing Instructions:
      Hide
      1. Login as admin
      2. Enrol 2 students to the course (s1, s2)
      3. Create 1 group, and 1 grouping in the course
        • The group contains both students
        • The grouping contains the group 1
      4. Create a forum with
        • Tracking enabled
        • Separate groups
        • Grouping set to A
      5. Login as both students and enable forum tracking in your preference
      6. Login as s1 and post to the forum
      7. Login as s2 and make sure you see the number of unread posts (1) in the course page
      8. Login as admin and delete the grouping A
      9. Login back as s2
      10. Make sure you see the number of unread posts
      11. Make sure you don't see any notice
      Show
      Login as admin Enrol 2 students to the course (s1, s2) Create 1 group, and 1 grouping in the course The group contains both students The grouping contains the group 1 Create a forum with Tracking enabled Separate groups Grouping set to A Login as both students and enable forum tracking in your preference Login as s1 and post to the forum Login as s2 and make sure you see the number of unread posts (1) in the course page Login as admin and delete the grouping A Login back as s2 Make sure you see the number of unread posts Make sure you don't see any notice
    • Affected Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_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:
    • Rank:
      50702

      Description

      Due to a bug in the forum_tp_count_forum_unread_posts() function, for some users in some forum discussions, it's possible for the function to trigger a large amount of php notices.

      This is due to the following line assuming an array element exists:

      $mygroups = $modinfo->groups[$cm->groupingid];
      

      This same assignment occurs earlier in the forum/lib.php file, but has protection like so:

          if (array_key_exists($cm->groupingid, $modinfo->groups)) {
              $mygroups = $modinfo->groups[$cm->groupingid];
          } else {
              $mygroups = false; // Will be set below
          }
      

      My proposed solution is to use this same checking & assignment as it achieves the same result and fixes the bug.

        Issue Links

          Activity

          Hide
          Frédéric Massart added a comment -

          Thanks for your patch Adam.

          Would you be able to write some testing instructions for this patch? A bit of information on how to replicate your issue would be useful as well.

          Many thanks!
          Fred

          Show
          Frédéric Massart added a comment - Thanks for your patch Adam. Would you be able to write some testing instructions for this patch? A bit of information on how to replicate your issue would be useful as well. Many thanks! Fred
          Hide
          Frédéric Massart added a comment -

          I reviewed the patch, and wrote some testing instructions. Pushing for integration. Cheers!

          Show
          Frédéric Massart added a comment - I reviewed the patch, and wrote some testing instructions. Pushing for integration. Cheers!
          Hide
          Dan Poltawski added a comment -

          Integrated to master, 25, 24 and 23 - thanks Adam!

          Show
          Dan Poltawski added a comment - Integrated to master, 25, 24 and 23 - thanks Adam!
          Hide
          Ankit Agarwal added a comment - - edited

          I am not sure which of these are related, but am facing following issues at step 10:-

          1. on course page as admin, visible name of the forum changed from "forum with tracking and sep groups(Grouping 1)" to "forum with tracking and sep groups()", as admin
          2. Following notice is generated, visiting the course page as admin:-
            Notice: Undefined index: 1 in /var/www/int/master/moodle/course/renderer.php on line 720 Call Stack: 0.0008 799104 1. {main}() /var/www/int/master/moodle/course/view.php:0 1.4017 110570560 
            2. require('/var/www/int/master/moodle/course/format/weeks/format.php') /var/www/int/master/moodle/course/view.php:278 1.4022 110578280 
            3. format_section_renderer_base->print_multiple_section_page() /var/www/int/master/moodle/course/format/weeks/format.php:49 1.4033 110581600 
            4. core_course_renderer->course_section_cm_list() /var/www/int/master/moodle/course/format/renderer.php:723 1.6801 111032984 
            5. core_course_renderer->course_section_cm() /var/www/int/master/moodle/course/renderer.php:961 1.6801 111033312 
            6. core_course_renderer->course_section_cm_name() /var/www/int/master/moodle/course/renderer.php:877 
            Notice: Trying to get property of non-object in /var/www/int/master/moodle/course/renderer.php on line 720 Call Stack: 0.0008 799104 1. {main}() /var/www/int/master/moodle/course/view.php:0 1.4017 110570560 
            2. require('/var/www/int/master/moodle/course/format/weeks/format.php') /var/www/int/master/moodle/course/view.php:278 1.4022 110578280 
            3. format_section_renderer_base->print_multiple_section_page() /var/www/int/master/moodle/course/format/weeks/format.php:49 1.4033 110581600 
            4. core_course_renderer->course_section_cm_list() /var/www/int/master/moodle/course/format/renderer.php:723 1.6801 111032984 
            5. core_course_renderer->course_section_cm() /var/www/int/master/moodle/course/renderer.php:961 1.6801 111033312 
            6. core_course_renderer->course_section_cm_name() /var/www/int/master/moodle/course/renderer.php:877 
            
          3. As student 2 I am not able to see the "1 unread post anymore"

          I will investigate a bit more to see if I can figure out what is happening.
          Cheers

          Show
          Ankit Agarwal added a comment - - edited I am not sure which of these are related, but am facing following issues at step 10:- on course page as admin, visible name of the forum changed from "forum with tracking and sep groups(Grouping 1)" to "forum with tracking and sep groups()", as admin Following notice is generated, visiting the course page as admin:- Notice: Undefined index: 1 in / var /www/ int /master/moodle/course/renderer.php on line 720 Call Stack: 0.0008 799104 1. {main}() / var /www/ int /master/moodle/course/view.php:0 1.4017 110570560 2. require('/ var /www/ int /master/moodle/course/format/weeks/format.php') / var /www/ int /master/moodle/course/view.php:278 1.4022 110578280 3. format_section_renderer_base->print_multiple_section_page() / var /www/ int /master/moodle/course/format/weeks/format.php:49 1.4033 110581600 4. core_course_renderer->course_section_cm_list() / var /www/ int /master/moodle/course/format/renderer.php:723 1.6801 111032984 5. core_course_renderer->course_section_cm() / var /www/ int /master/moodle/course/renderer.php:961 1.6801 111033312 6. core_course_renderer->course_section_cm_name() / var /www/ int /master/moodle/course/renderer.php:877 Notice: Trying to get property of non-object in / var /www/ int /master/moodle/course/renderer.php on line 720 Call Stack: 0.0008 799104 1. {main}() / var /www/ int /master/moodle/course/view.php:0 1.4017 110570560 2. require('/ var /www/ int /master/moodle/course/format/weeks/format.php') / var /www/ int /master/moodle/course/view.php:278 1.4022 110578280 3. format_section_renderer_base->print_multiple_section_page() / var /www/ int /master/moodle/course/format/weeks/format.php:49 1.4033 110581600 4. core_course_renderer->course_section_cm_list() / var /www/ int /master/moodle/course/format/renderer.php:723 1.6801 111032984 5. core_course_renderer->course_section_cm() / var /www/ int /master/moodle/course/renderer.php:961 1.6801 111033312 6. core_course_renderer->course_section_cm_name() / var /www/ int /master/moodle/course/renderer.php:877 As student 2 I am not able to see the "1 unread post anymore" I will investigate a bit more to see if I can figure out what is happening. Cheers
          Hide
          Ankit Agarwal added a comment -

          Created MDL-40145 for the first two issues, since they are not related.

          Show
          Ankit Agarwal added a comment - Created MDL-40145 for the first two issues, since they are not related.
          Hide
          Ankit Agarwal added a comment -

          Discussed this with Fred, and we found out the 3rd issue is because of MDL-40145 as well.
          Passing.
          Thanks

          Show
          Ankit Agarwal added a comment - Discussed this with Fred, and we found out the 3rd issue is because of MDL-40145 as well. Passing. Thanks
          Hide
          Frédéric Massart added a comment -

          Thanks Ankit! orz

          Show
          Frédéric Massart added a comment - Thanks Ankit! orz
          Hide
          Marina Glancy added a comment -

          Thanks for your awesome work! This has now become a part of Moodle.

          Closing as fixed!

          Show
          Marina Glancy added a comment - Thanks for your awesome work! This has now become a part of Moodle. Closing as fixed!

            People

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

              Dates

              • Created:
                Updated:
                Resolved: