Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-67024

Constant debugging message triggered by Moodle cronjob: PHP Notice: Undefined property: stdClass::$mnethostid in /moodle/lib/pagelib.php

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide
      Prerequisite
      1. Outgoing email setup (e.g. using mailcatcher)
      Setup
      1. Create a fresh Moodle installation with developer mode on (e.g. if using MDK, run "mdk install -r mindev users").
      2. Edit config.php and add the following lines (assuming you're using mailcatcher):

        $CFG->smtphosts = 'localhost:1025';
        $CFG->noreplyaddress = 'noreply@moodle.org';
        $CFG->maxeditingtime = 1;
        

      3. Log in as an admin.
      4. Go to "Site administration / Development / Make test course"
      5. Create an XS-sized test course.
      6. Enrol users to the course. (e.g. if using MDK, run "mdk run enrol")
      7. Go to the test forum in the test course.
      8. Set the forum's subscription mode to "Forced subscription".
      9. Create a discussion.
      10. Run cron.
      11. Set the forum's subscription mode to "Auto subscription".
      Test
      1. Log in as a student s1.
      2. Reply to admin's discussion.
      3. Run the following cron command.

        php admin/cli/cron.php | grep mnet
        

      4. Confirm that you don't get the message "Notice: Undefined property: stdClass::$mnethostid"
      Show
      Prerequisite Outgoing email setup (e.g. using mailcatcher) Setup Create a fresh Moodle installation with developer mode on (e.g. if using MDK, run " mdk install -r mindev users "). Edit config.php and add the following lines (assuming you're using mailcatcher): $CFG->smtphosts = 'localhost:1025'; $CFG->noreplyaddress = 'noreply@moodle.org'; $CFG->maxeditingtime = 1; Log in as an admin. Go to " Site administration / Development / Make test course " Create an XS-sized test course. Enrol users to the course. (e.g. if using MDK, run " mdk run enrol ") Go to the test forum in the test course. Set the forum's subscription mode to " Forced subscription ". Create a discussion. Run cron. Set the forum's subscription mode to " Auto subscription ". Test Log in as a student s1. Reply to admin's discussion. Run the following cron command. php admin/cli/cron.php | grep mnet Confirm that you don't get the message " Notice: Undefined property: stdClass::$mnethostid "
    • Affected Branches:
      MOODLE_37_STABLE
    • Fixed Branches:
      MOODLE_37_STABLE, MOODLE_38_STABLE
    • Pull 3.7 Branch:
    • Pull 3.8 Branch:
    • Pull Master Branch:
      MDL-67024-master

      Description

      We are seeing loads of debug messages sent to the Moodle server admin by the Moodle cronjob saying

      PHP Notice:  Undefined property: stdClass::$mnethostid in /var/www/html/moodle_prod/lib/pagelib.php on line 1614
      PHP Notice:  Undefined property: stdClass::$mnethostid in /var/www/html/moodle_prod/lib/pagelib.php on line 1617
      

      Looking at these lines, these is are comparisons made of
      $CFG->mnet_localhost_id and $USER->mnethostid

      In our setup, $CFG->mnet_localhost_id is set to 1 in the mdl_config table.
      All users in the mdl_user table have the column mnethostid also set to 1 without any exception.

      I have the assumption that this particular piece of code is executed by some scheduled task which does not have a full $USER object set.

      This issue was also reported recently by Acqua Alta on MDL-18231 (which is a closed, old ticket) and he mentioned there:

      Every time a teacher sends a bulk message to the students using the "Announcements" forum, the server sends us an e-mail message with the following error message [...]

      Based on this report, I am adding the messages component to this issue.

        Attachments

        1. MDL_67024.jpg
          7 kB
          Anna Carissa Sadia

          Activity

            People

            Assignee:
            farhan6318 Farhan Karmali
            Reporter:
            abias Alexander Bias
            Peer reviewer:
            Alexander Bias
            Integrator:
            Jun Pataleta
            Tester:
            Anna Carissa Sadia
            Participants:
            Component watchers:
            Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
            Votes:
            4 Vote for this issue
            Watchers:
            10 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              11/May/20

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 hours
                4h