Moodle
  1. Moodle
  2. MDL-30370 Meta: Oracle SQL issues
  3. MDL-24678

little bug in the chat_get_latest_message function, in chat lib

    Details

    • Type: Sub-task Sub-task
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.9.7
    • Fix Version/s: None
    • Component/s: Chat
    • Labels:
      None
    • Environment:
      Linux, with postgres, moodle 1.9.7

      Description

      This bug affects all moodle version, i think.

      The bug is in the chat lib (mod/chat/lib.php), in the function chat_get_latest_message($chatid, $groupid=0)

      If the chat message have the same timestamp, it could get wrong last chat message,
      this is cause by this lines (line 440)

      if (!$rs = $db->SelectLimit("SELECT *
      FROM {$CFG->prefix}chat_messages
      WHERE chatid = '$chatid' $groupselect
      ORDER BY timestamp DESC", 1))

      { return false; }

      it's could be fix by change to this code:

      if (!$rs = $db->SelectLimit("SELECT *
      FROM {$CFG->prefix}chat_messages
      WHERE chatid = '$chatid' $groupselect
      ORDER BY timestamp DESC, id DESC", 1))

      { return false; }

      or with this query that not use any limit or sort

      SELECT * FROM mdl_chat_messages WHERE chatid = <CHAT_ID> and timestamp=(SELECT MAX(timestamp) FROM mdl_chat_messages WHERE chatid = <CHAT_ID>) and id=(SELECT MAX(id) from mdl_chat_messages WHERE chatid = <CHAT_ID>);

        Gliffy Diagrams

          Activity

          Hide
          Carlos Alexandre S. da Fonseca added a comment -

          In the second query you forget the $groupselect variable, it's important if chat was configured with separate group

          Show
          Carlos Alexandre S. da Fonseca added a comment - In the second query you forget the $groupselect variable, it's important if chat was configured with separate group
          Hide
          Michael de Raadt added a comment -

          It might be worth checking if this still affects current versions.

          Show
          Michael de Raadt added a comment - It might be worth checking if this still affects current versions.
          Hide
          IwonaZ added a comment -

          Yes, the current version (checked build 2.5beta 20130405) is still affected. The patch that fixes the issue is here:
          https://github.com/tmuras/moodle/compare/master...MDL-24678

          Show
          IwonaZ added a comment - Yes, the current version (checked build 2.5beta 20130405) is still affected. The patch that fixes the issue is here: https://github.com/tmuras/moodle/compare/master...MDL-24678
          Hide
          Dongsheng Cai added a comment -

          This issue was assigned to me automatically, however I will not be able to work on this issue in the immediate future. In order to create a truer sense of the state of this issue and to allow other developers to have chance to become involved, I am removing myself as the assignee of this issue.
          For more information, see http://docs.moodle.org/dev/Changes_to_issue_assignment

          Show
          Dongsheng Cai added a comment - This issue was assigned to me automatically, however I will not be able to work on this issue in the immediate future. In order to create a truer sense of the state of this issue and to allow other developers to have chance to become involved, I am removing myself as the assignee of this issue. For more information, see http://docs.moodle.org/dev/Changes_to_issue_assignment
          Show
          Carlos Alexandre S. da Fonseca added a comment - I have fixed this bug https://github.com/bozoh/moodle/tree/MDL-24678-master and, for moodle 2.6 https://github.com/bozoh/moodle/tree/MDL-24678-moodle_26
          Hide
          Carlos Alexandre S. da Fonseca added a comment -

          Fixed race condition on chat module

          Show
          Carlos Alexandre S. da Fonseca added a comment - Fixed race condition on chat module

            People

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

              Dates

              • Created:
                Updated: