protected function updateWords()
    {
        try {
            $vocabulary = [];
            $allWords = $this->prepareWords();
            $this->addNewWords($allWords);
            $queryVocabulary = (new Query())->from(Vocabulary::tableName())->where(['word' => $allWords]);
            foreach ($queryVocabulary->each() as $vocabularyNew) {
                $vocabulary[$vocabularyNew['id']] = [$vocabularyNew['id'], $this->id];
            }
            if (!empty($vocabulary)) {
                if (!Podium::getInstance()->db->createCommand()->batchInsert(
                        '{{%podium_vocabulary_junction}}', ['word_id', 'post_id'], array_values($vocabulary)
                    )->execute()) {
                    throw new Exception('Words connections saving error!');
                }
            }
            $queryJunction = (new Query())->from('{{%podium_vocabulary_junction}}')->where(['post_id' => $this->id]);
            foreach ($queryJunction->each() as $junk) {
                if (!array_key_exists($junk['word_id'], $vocabulary)) {
                    if (!Podium::getInstance()->db->createCommand()->delete(
                            '{{%podium_vocabulary_junction}}', ['id' => $junk['id']]
                        )->execute()) {
                        throw new Exception('Words connections deleting error!');
                    }
                }
            }
        } catch (Exception $e) {
            Log::error($e->getMessage(), null, __METHOD__);
            throw $e;
        }
    }
protected function updateWords()
    {
        try {
            $vocabulary = [];
            $allWords = $this->prepareWords();
            $this->addNewWords($allWords);
            $queryVocabulary = (new Query())->from(Vocabulary::tableName())->where(['word' => $allWords]);
            foreach ($queryVocabulary->each() as $vocabularyNew) {
                $vocabulary[$vocabularyNew['id']] = [$vocabularyNew['id'], $this->id];
            }
            if (!empty($vocabulary)) {
                if (!Podium::getInstance()->db->createCommand()->batchInsert(
                        '{{%podium_vocabulary_junction}}', ['word_id', 'post_id'], array_values($vocabulary)
                    )->execute()) {
                    throw new Exception('Words connections saving error!');
                }
            }
            $queryJunction = (new Query())->from('{{%podium_vocabulary_junction}}')->where(['post_id' => $this->id]);
            foreach ($queryJunction->each() as $junk) {
                if (!array_key_exists($junk['word_id'], $vocabulary)) {
                    if (!Podium::getInstance()->db->createCommand()->delete(
                            '{{%podium_vocabulary_junction}}', ['id' => $junk['id']]
                        )->execute()) {
                        throw new Exception('Words connections deleting error!');
                    }
                }
            }
        } catch (Exception $e) {
            Log::error($e->getMessage(), null, __METHOD__);
            throw $e;
        }
    }
protected function updateWords ( ) { try { $ vocabulary = [ ] ; $ allWords = $ this -> prepareWords ( ) ; $ this -> addNewWords ( $ allWords ) ; $ queryVocabulary = ( new Query ( ) ) -> from ( Vocabulary :: tableName ( ) ) -> where ( [ 'word' => $ allWords ] ) ; foreach ( $ queryVocabulary -> each ( ) as $ vocabularyNew ) { $ vocabulary [ $ vocabularyNew [ 'id' ] ] = [ $ vocabularyNew [ 'id' ] , $ this -> id ] ; } if ( ! empty ( $ vocabulary ) ) { if ( ! Podium :: getInstance ( ) -> db -> createCommand ( ) -> batchInsert ( '{{%podium_vocabulary_junction}}' , [ 'word_id' , 'post_id' ] , array_values ( $ vocabulary ) ) -> execute ( ) ) { throw new Exception ( 'Words connections saving error!' ) ; } } $ queryJunction = ( new Query ( ) ) -> from ( '{{%podium_vocabulary_junction}}' ) -> where ( [ 'post_id' => $ this -> id ] ) ; foreach ( $ queryJunction -> each ( ) as $ junk ) { if ( ! array_key_exists ( $ junk [ 'word_id' ] , $ vocabulary ) ) { if ( ! Podium :: getInstance ( ) -> db -> createCommand ( ) -> delete ( '{{%podium_vocabulary_junction}}' , [ 'id' => $ junk [ 'id' ] ] ) -> execute ( ) ) { throw new Exception ( 'Words connections deleting error!' ) ; } } } } catch ( Exception $ e ) { Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; throw $ e ; } }
Updates tag words.
@throws Exception
Updates tag words .