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

Fixed Error when getMetadataKey return array

guiltar

Well-known member
#1
Class XenForo_Search_SourceHandler_MySqlFt has method
PHP:
    public function insertIntoIndex($contentType, $contentId, $title, $message, $itemDate, $userId, $discussionId = 0, array $metadata = array())
    {
        $metadataPieces = array(
            $this->getMetadataKey('user', $userId),
            $this->getMetadataKey('content', $contentType)
        );
        foreach ($metadata AS $metadataKey => $value)
        {
            $metadataPieces[] = $this->getMetadataKey($metadataKey, $value);
        }
 
        $db = $this->_getDb();
        $row = '(' . $db->quote($contentType) . ', ' . $db->quote(intval($contentId))
            . ', ' . $db->quote($title) . ', ' . $db->quote($message)
            . ', ' . $db->quote(implode(' ', $metadataPieces))
            . ', ' . $db->quote(intval($itemDate)) . ', ' . $db->quote(intval($userId))
            . ', ' . $db->quote(intval($discussionId)) . ')';
PHP:
    * @return string|array String if $value was a string, array if $value was an array
    */
    public function getMetadataKey($keyName, $value)
    {
Notice that getMetadataKey can return array and this causes error while imploding $metadataPieces.
 

Yoskaldyr

Well-known member
#2
simple fix:
PHP:
        foreach ($metadata AS $metadataKey => $value)
        {
            $metadataPieces[] = $this->getMetadataKey($metadataKey, $value);
        }
replace with
PHP:
        foreach ($metadata AS $metadataKey => $value)
        {
            $metadataPiece = $this->getMetadataKey($metadataKey, $value);
            $metadataPieces[] = (is_array($metadataPiece)) ? implode(' ', $metadataPiece) : $metadataPiece;
        }
 

guiltar

Well-known member
#3
Or such a way
PHP:
        foreach ($metadata AS $metadataKey => $value)
        {
            $metadataPiece = $this->getMetadataKey($metadataKey, $value);
            $metadataPieces = array_merge($metadataPieces, is_array($metadataPiece) ? $metadataPiece : array($metadataPiece));
        }