/**
  * Creates a new Location model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Location();
     if ($model->load(\Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 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) {
     }
 }
 public function actionCopyFromSource()
 {
     $chunkSize = 500;
     $chunkPointer = 1;
     $recordCount = \Yii::$app->db->createCommand('SELECT COUNT(*) FROM source')->queryScalar();
     $unit = $recordCount / 100;
     $this->_msg = 'Processing ' . $recordCount . ' values';
     $base = 'SELECT * FROM source';
     $continue = true;
     while ($continue) {
         $qry = "{$base} LIMIT {$chunkSize} OFFSET {$chunkPointer}";
         echo $qry;
         $records = \Yii::$app->db->createCommand($qry)->queryAll();
         foreach ($records as $record) {
             if ($record['Country'] != 'BE' && $record['Country'] != 'NL') {
                 $location = new Location(['country_id' => strtoupper($record['Country']), 'postcode' => $record['Postcode'], 'cityName' => $record['City'], 'cityLanguage' => $record['Language']]);
                 echo $location->country_id . '::' . $location->postcode . '::' . $location->cityName . '::' . $location->cityLanguage . "\n";
                 $location->save();
             }
         }
         $this->_msg = $chunkPointer / $chunkSize . ' Percent Completed';
         $this->printStatus();
         $chunkPointer += $chunkSize;
         if ($chunkPointer > $recordCount) {
             $continue = false;
         }
     }
     return 0;
 }