public function actionCountry() { $this->stdout('Request API: Countries.', Console::FG_GREEN); $data = TravelPayoutsApi::getCountries(); $_count = count($data); $this->stdout(' Get: ' . $_count . ' Countries.' . PHP_EOL, Console::FG_GREEN); Console::startProgress(0, $_count); $count = 0; $count_ = 0; foreach ($data as $value) { $name_translations = $value->name_translations; unset($value->name_translations); $country = ReceivedCountry::find()->where(['code' => $value->code])->one(); if (!$country) { $this->stdout($value->code . ' ', Console::FG_YELLOW); $country = new ReceivedCountry(); $country->attributes = (array) $value; $country->alias = $this->translit($value->name); if (!$country->save()) { print_r($value); print_r($country->errors); return Controller::EXIT_CODE_ERROR; } $count++; } else { Console::updateProgress(++$count_, $_count); } $this->setTranslations($value->code, $name_translations, "Country"); } Console::endProgress(); $this->stdout(PHP_EOL . 'Added: ' . $count . ' Countries.' . PHP_EOL, Console::FG_BLUE); return Controller::EXIT_CODE_NORMAL; }