• 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

Chris D

XenForo developer
Staff member
#1
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'.
 

MattW

Well-known member
#2
I have a suspicion that this was a copy/paste error and the key should actually be 'attachment_id'.
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);
        }