Moodle
  1. Moodle
  2. MDL-34535

messagelib is using is_int() on userids, which causes message send to fail sometimes. Needs to be is_numeric().

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.3
    • Fix Version/s: 2.2.5, 2.3.2
    • Component/s: Messages
    • Labels:
    • Testing Instructions:
      Hide
      1. Dump the attached test.php in root of your moodle install
      2. Edit test.php and change the $eventdata->userto to a valid user id
      3. Run test.php from browser
      4. make sure you get "Success" echoed
      5. login as the userto user and make sure you get the msg
      Show
      Dump the attached test.php in root of your moodle install Edit test.php and change the $eventdata->userto to a valid user id Run test.php from browser make sure you get "Success" echoed login as the userto user and make sure you get the msg
    • Affected Branches:
      MOODLE_23_STABLE
    • Fixed Branches:
      MOODLE_22_STABLE, MOODLE_23_STABLE
    • Pull Master Branch:
      MDL-34535-master
    • Rank:
      42962

      Description

      Writing a module that send a message like this fails because line 63 of messagelib.php doesn't recognise the userid which comes in as a string.

      $eventdata = new stdClass();
      $eventdata->component = 'mod_coursework';
      $eventdata->name = 'deadlinechanged';
      $eventdata->userfrom = $USER;
      // $dbrecord is from a standard $DB->get_record() call
      $eventdata->userto = $dbrecord->studentid;
      // etc
      
      message_send($eventdata);
      
      1. test.php
        0.5 kB
        Ankit Agarwal

        Activity

        Hide
        Michael de Raadt added a comment -

        Oh for a strongly typed language...

        Thanks for spotting that and suggesting a fix.

        Show
        Michael de Raadt added a comment - Oh for a strongly typed language... Thanks for spotting that and suggesting a fix.
        Hide
        Petr Škoda added a comment -

        hi, our is_number() might be more suitable for integers because is_numeric() is for floats too.

        Show
        Petr Škoda added a comment - hi, our is_number() might be more suitable for integers because is_numeric() is for floats too.
        Hide
        Rossiani Wijaya added a comment -

        Looks good Ankit.
        +1 for integration.

        Show
        Rossiani Wijaya added a comment - Looks good Ankit. +1 for integration.
        Hide
        Ankit Agarwal added a comment -

        Thanks for the review Rosie,
        Sending this for integration.

        Show
        Ankit Agarwal added a comment - Thanks for the review Rosie, Sending this for integration.
        Hide
        Dan Poltawski added a comment -

        Integrated, thanks guys.

        Maybe you could provide a test.php rather than making the person hack their course/view.php for test instructions

        Show
        Dan Poltawski added a comment - Integrated, thanks guys. Maybe you could provide a test.php rather than making the person hack their course/view.php for test instructions
        Hide
        Ankit Agarwal added a comment -

        Thanks Dan, updated testing instructions and added the testing script
        Cheers

        Show
        Ankit Agarwal added a comment - Thanks Dan, updated testing instructions and added the testing script Cheers
        Hide
        Frédéric Massart added a comment -

        Test successful on 2.2, 2.3 and master. Yay! \o/

        Show
        Frédéric Massart added a comment - Test successful on 2.2, 2.3 and master. Yay! \o/
        Hide
        Eloy Lafuente (stronk7) added a comment -

        YEAR!*

        CAF*, TOT!*

        • Your effort amazingly resulted. (unbelievable :-P)
        • Closing as fixed.
        • Tons of thanks.
        Show
        Eloy Lafuente (stronk7) added a comment - YEAR!* CAF*, TOT!* Your effort amazingly resulted. (unbelievable :-P) Closing as fixed. Tons of thanks.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: