public function cleanKeywordLinks(AbstractClassContent $content, $keywords)
    {
        if (!is_array($keywords)) {
            $keywords = [$keywords];
        }

        $keywordUids = [];
        foreach ($keywords as $keyword) {
            if (
                $keyword instanceof Keyword
                && !empty($keyword->value)
                && (null !== $realKeyword = $this->_em->find('BackBee\NestedNode\KeyWord', $keyword->value))
            ) {
                $keywordUids[] = $realKeyword->getUid();
            }
        }

        $query = $this->_em
            ->getConnection()
            ->createQueryBuilder()
            ->select('c.keyword_uid')
            ->from('keywords_contents', 'c')
        ;
        $query->where($query->expr()->eq('c.content_uid', $query->expr()->literal($content->getUid())));
        $savedKeywords = $query->execute()->fetchAll(\PDO::FETCH_COLUMN);

        $linksToBeRemoved = array_diff($savedKeywords, $keywordUids);
        if (count($linksToBeRemoved)) {
            $query = $this->_em
                ->getConnection()
                ->createQueryBuilder()
                ->delete('keywords_contents')
            ;

            array_walk(
                $linksToBeRemoved,
                function(&$value, $key, $query) {
                    $value = $query->expr()->literal($value);
                },
                $query
            );

            $query
                ->where($query->expr()->eq('content_uid', $query->expr()->literal($content->getUid())))
                ->andWhere($query->expr()->in('keyword_uid', $linksToBeRemoved))
                ->execute()
            ;
        }
    }
public function cleanKeywordLinks(AbstractClassContent $content, $keywords)
    {
        if (!is_array($keywords)) {
            $keywords = [$keywords];
        }

        $keywordUids = [];
        foreach ($keywords as $keyword) {
            if (
                $keyword instanceof Keyword
                && !empty($keyword->value)
                && (null !== $realKeyword = $this->_em->find('BackBee\NestedNode\KeyWord', $keyword->value))
            ) {
                $keywordUids[] = $realKeyword->getUid();
            }
        }

        $query = $this->_em
            ->getConnection()
            ->createQueryBuilder()
            ->select('c.keyword_uid')
            ->from('keywords_contents', 'c')
        ;
        $query->where($query->expr()->eq('c.content_uid', $query->expr()->literal($content->getUid())));
        $savedKeywords = $query->execute()->fetchAll(\PDO::FETCH_COLUMN);

        $linksToBeRemoved = array_diff($savedKeywords, $keywordUids);
        if (count($linksToBeRemoved)) {
            $query = $this->_em
                ->getConnection()
                ->createQueryBuilder()
                ->delete('keywords_contents')
            ;

            array_walk(
                $linksToBeRemoved,
                function(&$value, $key, $query) {
                    $value = $query->expr()->literal($value);
                },
                $query
            );

            $query
                ->where($query->expr()->eq('content_uid', $query->expr()->literal($content->getUid())))
                ->andWhere($query->expr()->in('keyword_uid', $linksToBeRemoved))
                ->execute()
            ;
        }
    }
public function cleanKeywordLinks ( AbstractClassContent $ content , $ keywords ) { if ( ! is_array ( $ keywords ) ) { $ keywords = [ $ keywords ] ; } $ keywordUids = [ ] ; foreach ( $ keywords as $ keyword ) { if ( $ keyword instanceof Keyword && ! empty ( $ keyword -> value ) && ( null !== $ realKeyword = $ this -> _em -> find ( 'BackBee\NestedNode\KeyWord' , $ keyword -> value ) ) ) { $ keywordUids [ ] = $ realKeyword -> getUid ( ) ; } } $ query = $ this -> _em -> getConnection ( ) -> createQueryBuilder ( ) -> select ( 'c.keyword_uid' ) -> from ( 'keywords_contents' , 'c' ) ; $ query -> where ( $ query -> expr ( ) -> eq ( 'c.content_uid' , $ query -> expr ( ) -> literal ( $ content -> getUid ( ) ) ) ) ; $ savedKeywords = $ query -> execute ( ) -> fetchAll ( \ PDO :: FETCH_COLUMN ) ; $ linksToBeRemoved = array_diff ( $ savedKeywords , $ keywordUids ) ; if ( count ( $ linksToBeRemoved ) ) { $ query = $ this -> _em -> getConnection ( ) -> createQueryBuilder ( ) -> delete ( 'keywords_contents' ) ; array_walk ( $ linksToBeRemoved , function ( & $ value , $ key , $ query ) { $ value = $ query -> expr ( ) -> literal ( $ value ) ; } , $ query ) ; $ query -> where ( $ query -> expr ( ) -> eq ( 'content_uid' , $ query -> expr ( ) -> literal ( $ content -> getUid ( ) ) ) ) -> andWhere ( $ query -> expr ( ) -> in ( 'keyword_uid' , $ linksToBeRemoved ) ) -> execute ( ) ; } }
Deletes outdated keyword content joins.

@param AbstractClassContent $content
@param mixed                $keywords
Deletes outdated keyword content joins .