private function _dummyLocation($countryId, $name, $postCode)
 {
     //CityTranslation::find()->where(['language_id' => 'EN', 'name' => $name])->queryScalar();
     $dummyCity = new \humanized\location\models\location\City(['language_id' => 'EN']);
     try {
         $dummyCity->save();
         try {
             $dummyCityTranslation = new \humanized\location\models\translation\CityTranslation(['language_id' => 'EN', 'city_id' => $dummyCity->id, 'name' => $name]);
             $dummyCityTranslation->save();
             try {
                 $dummyLocation = new \humanized\location\models\location\Location(['postcode' => $postCode, 'city_id' => $dummyCity->id, 'country_id' => $countryId]);
                 $dummyLocation->save();
             } catch (Exception $ex) {
             }
         } catch (Exception $ex) {
         }
     } catch (\Exception $ex) {
     }
 }
Esempio n. 2
0
 public function beforeValidate()
 {
     if (!parent::beforeValidate()) {
         return false;
     }
     //Remote Settings Empty --> Master Mode
     if (!isset($this->uid)) {
         //echo "Generating UID";
         $this->uid = uniqid();
     }
     if (isset($this->name) && isset($this->language)) {
         $params = ['city_translation.name' => $this->name, 'city.language_id' => strtoupper($this->language)];
         $model = City::find()->where($params)->joinWith('name')->one();
         if (!isset($model)) {
             $model = new City(['local_name' => $this->name, 'language_id' => strtoupper($this->language)]);
             $model->save();
         }
         $this->city_id = $model->id;
     }
     return true;
 }
 public function actionDefault($fn)
 {
     if (strlen($fn) != 5) {
         $this->stderror('filename like <country-code>_<language-code> (5 characters - ommit .csv extension)' . "\n");
     }
     //if filename is not 5 characters long, throw an error and display filename model
     $fileName = \Yii::getAlias('@data') . "/location/{$fn}.csv";
     //resolve file url from /location/
     $file = fopen($fileName, "r");
     $countryCode = strtoupper(substr($fn, 0, 2));
     $languageCode = strtoupper(substr($fn, 3, 2));
     $this->stdout('Importing City Data for ' . $countryCode . ' in language ' . $languageCode . "\n");
     //fgetcsv($file, 0);
     while (!feof($file)) {
         $record = fgetcsv($file, 0, ';');
         if (isset($record[0])) {
             $city = new City(['language_id' => $languageCode, 'local_name' => $record[1]]);
             if (!$city->save()) {
                 \yii\helpers\VarDumper::dump($city->errors);
             }
             //    (new CityTranslation(['name' => $record[1], 'city_id' => $city->id, 'language_id' => $languageCode]))->save();
             $location = new Location(['city_id' => $city->id, 'country_id' => $countryCode, 'postcode' => $record[0]]);
             if (!$location->save()) {
                 echo $location->city_id . '=' . $location->country_id . '=' . $location->uid . '=' . $location->postcode;
                 \yii\helpers\VarDumper::dump($location->errors);
             }
         } else {
             break;
         }
     }
 }