1. 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

Discussion in 'Resolved Bug Reports' started by guiltar, Apr 30, 2012.

  1. guiltar

    guiltar Well-Known Member

    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 likes this.
  2. Yoskaldyr

    Yoskaldyr Well-Known Member

    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;
            }
     
    mrGTB likes this.
  3. guiltar

    guiltar Well-Known Member

    Or such a way
    PHP:
            foreach ($metadata AS $metadataKey => $value)
            {
                
    $metadataPiece $this->getMetadataKey($metadataKey$value);
                
    $metadataPieces array_merge($metadataPiecesis_array($metadataPiece) ? $metadataPiece : array($metadataPiece));
            }
     
    TheVisitors and mrGTB like this.
  4. Mike

    Mike XenForo Developer Staff Member

    Fixed, thanks.
     
  5. Pepelac

    Pepelac Well-Known Member

    Fixed, but with small problem: undefined variable $metaDataPieces at line 53.

    Just rename it to $metadataPieces
     
    Jake Bunce likes this.
  6. Vincent

    Vincent Well-Known Member

    Create a new thread for this, else the devs won't notice after their time away.
     
  7. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Moved back to bugs. Thanks.
     
  8. Mike

    Mike XenForo Developer Staff Member

    Fixed... properly this time.
     
    Slavik and guiltar like this.

Share This Page