Пример #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $points = DestinationPoint::with(['city', 'country'])->whereNull('destination_points.latitude')->orderBy('id')->get();
     $count = 0;
     foreach ($points as $point) {
         $count++;
         if (0 == $count % 1000) {
             $unprocessed_points = DestinationPoint::with(['city', 'country'])->whereNull('destination_points.latitude')->count();
             $collected_cycles_count = gc_collect_cycles();
             $this->comment($unprocessed_points . ' unprocessed destination points (' . $this->getMemoryUsage() . ' / ' . $collected_cycles_count . ' cycles)');
         }
         if (!($country = $point->country()->first())) {
             return $this->error("Skipped point #{$point->id}: country not found");
         }
         if (!($city = $point->city()->first())) {
             return $this->error("Skipped point #{$point->id}: city not found");
         }
         $address = $point->address;
         if (false === mb_strpos($address, $city->name)) {
             $address = $city->name . ', ' . $address;
         }
         if (false === mb_strpos($address, $country->name)) {
             $address = $country->name . ', ' . $address;
         }
         try {
             if ($point = $this->geocode($point, $address)) {
                 $point->save();
             }
         } catch (ChainNoResultException $e) {
             $this->error("Not founded {$address}");
         }
     }
     return;
 }