1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fixed Incorrect key in XenForo_Model_Attachment::getAttachments

Discussion in 'Resolved Bug Reports' started by Chris D, Feb 5, 2013.

  1. Chris D

    Chris D XenForo Developer Staff Member

    PHP:
        /**
         * Gets all attachments (and data) matching the given conditions
         *
         * @param array $conditions
         * @param array $fetchOptions
         *
         * @return array
         */
        
    public function getAttachments(array $conditions = array(), array $fetchOptions = array())
        {
            
    $whereConditions $this->prepareAttachmentConditions($conditions$fetchOptions);

            
    $sqlClauses $this->prepareAttachmentFetchOptions($fetchOptions);
            
    $limitOptions $this->prepareLimitFetchOptions($fetchOptions);

            return 
    $this->fetchAllKeyed($this->limitQueryResults(
                
    '
                    SELECT attachment.*, attachment_data.*
                        ' 
    $sqlClauses['selectFields'] . '
                    FROM xf_attachment AS attachment
                    INNER JOIN xf_attachment_data AS attachment_data ON
                        (attachment_data.data_id = attachment.data_id)
                    ' 
    $sqlClauses['joinTables'] . '
                    WHERE ' 
    $whereConditions '
                    ' 
    $sqlClauses['orderClause'] . '
                '
    $limitOptions['limit'], $limitOptions['offset']
            ), 
    'node_id');
        }
    This query is used to fetch attachments. The fetchAllKeyed function is used, and oddly the key it uses is node_id.

    The node_id key does not exist in the xf_user, xf_attachment or xf_attachment_data tables and these are (by default) the only tables available to this function.

    I have a suspicion that this was a copy/paste error and the key should actually be 'attachment_id'.
     
    cclaerhout likes this.
  2. MattW

    MattW Well-Known Member

    I think you are correct, especially when looking at other functions in that file, as they are using 'attachment_id'
    PHP:
    /**
            * Gets all attachments (with limited data info) that have the specified temp hash.
            *
            * @param string $tempHash
            *
            * @return array Format: [attachment id] => info
            */
            
    public function getAttachmentsByTempHash($tempHash)
            {
                    if (
    strval($tempHash) === '')
                    {
                            return array();
                    }
     
                    return 
    $this->fetchAllKeyed('
                            SELECT attachment.*,
                                    ' 
    self::$dataColumns '
                            FROM xf_attachment AS attachment
                            INNER JOIN xf_attachment_data AS data ON
                                    (data.data_id = attachment.data_id)
                            WHERE attachment.temp_hash = ?
                            ORDER BY attachment.attach_date
                    '
    'attachment_id'$tempHash);
            }
     
    cclaerhout and Chris D like this.
  3. cclaerhout

    cclaerhout Well-Known Member

    Could it be what causes the error on php 5.4 with the attachment variable?
     
    Chris D likes this.
  4. Chris D

    Chris D XenForo Developer Staff Member

    Heh... let me check...

    EDIT: Sadly not :(
     
    cclaerhout likes this.
  5. cclaerhout

    cclaerhout Well-Known Member

    Next time, will be the good one.
     
  6. Mike

    Mike XenForo Developer Staff Member

    Fixed.
     
    MattW, Slavik, TBolley and 1 other person like this.

Share This Page