/**
  * @return $this
  * @throws \yii\base\InvalidConfigException
  */
 public function translated()
 {
     $messageTableName = Message::tableName();
     $query = Message::find()->select($messageTableName . '.id');
     $i = 0;
     foreach (Yii::$app->getI18n()->languages as $language) {
         if ($i === 0) {
             $query->andWhere($messageTableName . '.language = :language and ' . $messageTableName . '.translation is not null', [':language' => $language]);
         } else {
             $query->innerJoin($messageTableName . ' t' . $i, 't' . $i . '.id = ' . $messageTableName . '.id and t' . $i . '.language = :language and t' . $i . '.translation is not null', [':language' => $language]);
         }
         $i++;
     }
     $ids = $query->indexBy('id')->all();
     $this->andWhere(['in', 'id', array_keys($ids)]);
     return $this;
 }
예제 #2
0
 public function actionFlush()
 {
     $tableNames = [Message::tableName(), SourceMessage::tableName()];
     $db = Yii::$app->getDb();
     foreach ($tableNames as $tableName) {
         $db->createCommand()->delete($tableName)->execute();
     }
     echo PHP_EOL . 'Done.' . PHP_EOL;
 }