You are here

private function WeatherCommands::add in Weather 8

Same name and namespace in other branches
  1. 2.0.x src/Commands/WeatherCommands.php \Drupal\weather\Commands\WeatherCommands::add()

Add.

File

src/Commands/WeatherCommands.php, line 98

Class

WeatherCommands
Drush command to add support to weather module (import weather csv file).

Namespace

Drupal\weather\Commands

Code

private function add() : self {
  $s = $this
    ->store();
  $i = 0;
  $c = count($this->items);
  $this
    ->logger()
    ->info("will add: {$c}");
  foreach ($this->items as $item) {
    $s
      ->create([
      'geoid' => $item[0],
      'latitude' => $item[1],
      'longitude' => $item[2],
      'country' => $item[3],
      'name' => $item[4],
      'link' => trim($item[5]),
      'status' => 'original',
    ])
      ->save();
    if (++$i % 50 === 0) {
      $this
        ->logger()
        ->success("add {$i} / {$c}");
    }
  }
  return $this;
}