original_string: public static function delete_conversation_by_id(int $userid, int $conversationid) {
          global $DB, $USER;
  
          // Get all messages belonging to this conversation that have not already been deleted by this user.
          $sql = "SELECT m.*
                   FROM {messages} m
             INNER JOIN {message_conversations} mc
                     ON m.conversationid = mc.id
              LEFT JOIN {message_user_actions} mua
                     ON (mua.messageid = m.id AND mua.userid = ? AND mua.action = ?)
                  WHERE mua.id is NULL
                    AND mc.id = ?
               ORDER BY m.timecreated ASC";
          $messages = $DB->get_records_sql($sql, [$userid, self::MESSAGE_ACTION_DELETED, $conversationid]);
  
          // Ok, mark these as deleted.
          foreach ($messages as $message) {
              $mua = new \stdClass();
              $mua->userid = $userid;
              $mua->messageid = $message->id;
              $mua->action = self::MESSAGE_ACTION_DELETED;
              $mua->timecreated = time();
              $mua->id = $DB->insert_record('message_user_actions', $mua);
  
              \core\event\message_deleted::create_from_ids($userid, $USER->id,
                  $message->id, $mua->id)->trigger();
          }
      }
code: public static function delete_conversation_by_id(int $userid, int $conversationid) {
          global $DB, $USER;
  
          // Get all messages belonging to this conversation that have not already been deleted by this user.
          $sql = "SELECT m.*
                   FROM {messages} m
             INNER JOIN {message_conversations} mc
                     ON m.conversationid = mc.id
              LEFT JOIN {message_user_actions} mua
                     ON (mua.messageid = m.id AND mua.userid = ? AND mua.action = ?)
                  WHERE mua.id is NULL
                    AND mc.id = ?
               ORDER BY m.timecreated ASC";
          $messages = $DB->get_records_sql($sql, [$userid, self::MESSAGE_ACTION_DELETED, $conversationid]);
  
          // Ok, mark these as deleted.
          foreach ($messages as $message) {
              $mua = new \stdClass();
              $mua->userid = $userid;
              $mua->messageid = $message->id;
              $mua->action = self::MESSAGE_ACTION_DELETED;
              $mua->timecreated = time();
              $mua->id = $DB->insert_record('message_user_actions', $mua);
  
              \core\event\message_deleted::create_from_ids($userid, $USER->id,
                  $message->id, $mua->id)->trigger();
          }
      }
code_tokens: public static function delete_conversation_by_id ( int $ userid , int $ conversationid ) { global $ DB , $ USER ; // Get all messages belonging to this conversation that have not already been deleted by this user. $ sql = "SELECT m.*
                   FROM {messages} m
             INNER JOIN {message_conversations} mc
                     ON m.conversationid = mc.id
              LEFT JOIN {message_user_actions} mua
                     ON (mua.messageid = m.id AND mua.userid = ? AND mua.action = ?)
                  WHERE mua.id is NULL
                    AND mc.id = ?
               ORDER BY m.timecreated ASC" ; $ messages = $ DB -> get_records_sql ( $ sql , [ $ userid , self :: MESSAGE_ACTION_DELETED , $ conversationid ] ) ; // Ok, mark these as deleted. foreach ( $ messages as $ message ) { $ mua = new \ stdClass ( ) ; $ mua -> userid = $ userid ; $ mua -> messageid = $ message -> id ; $ mua -> action = self :: MESSAGE_ACTION_DELETED ; $ mua -> timecreated = time ( ) ; $ mua -> id = $ DB -> insert_record ( 'message_user_actions' , $ mua ) ; \ core \ event \ message_deleted :: create_from_ids ( $ userid , $ USER -> id , $ message -> id , $ mua -> id ) -> trigger ( ) ; } }
docstring: Deletes a conversation for a specified user.
  
  This function does not verify any permissions.
  
  @param int $userid The user id of who we want to delete the messages for (this may be done by the admin
  but will still seem as if it was by the user)
  @param int $conversationid The id of the other user in the conversation
docstring_tokens: Deletes a conversation for a specified user .