/** * Executes the load localities command * * @param InputInterface $input Input interface * @param OutputInterface $output Output interface */ protected function execute(InputInterface $input, OutputInterface $output) { $container = $this->getContainer(); $importer = $container->get('geonames.locality.importer'); $countries = $input->getArgument('country'); $filter = new Filter(); if (is_string($input->getOption('filter'))) { $filterRules = explode(",", $input->getOption('filter')); if (count($filterRules) > 0) { foreach ($filterRules as $rule) { $filter->addRule($rule); $output->writeLn("Added filter rule: " . $rule); } } } // Display importer information if requested if ($input->getOption('info')) { $table = $this->getHelper('table'); $table->setLayout(TableHelper::LAYOUT_BORDERLESS); $table->setHeaders(['Feature', 'Repository']); foreach ($importer->getLocalityRepositories() as $feature => $repository) { $table->addRow([$feature, get_class($repository)]); } $table->render($output); return; } // Import the specified countries $progress = $this->getHelper('progress'); $importer->import($countries, $filter, new OutputLogger($output), $progress, $output); }
/** * Imports an individual locality into the the locality repositories * * @param LocalityRepositoryInterface $localityRepository Locality repository * @param Locality $locality Locality * @param CountryInterface $country Country * @param Filter $filter Locality Filter * @param LoggerInterface $log Import log */ public function importLocality(LocalityRepositoryInterface $localityRepository, Locality $locality, CountryInterface $country = null, Filter $filter, LoggerInterface $log = null) { $log = $log ?: new NullLogger(); if ($filter != null && $filter->applyRules($locality) == false) { return null; } $countryRepository = $this->getCountryRepository(); $timezoneRepository = $this->getTimezoneRepository(); // Load the country for the locality if required if (!$country || $locality->getCountryCode() !== $country->getCode()) { $country = $countryRepository->getCountry($locality->getCountryCode()); if (!$country) { $log->error("Country code '{code}' does not exist in repository {repository}", ['code' => $country, 'repository' => get_class($countryRepository)]); return null; } } // Set the country $locality->setCountry($country); // Load the timezone for the locality if ($locality->getTimezoneIdentifier()) { $timezone = $timezoneRepository->getTimezone($locality->getTimezoneIdentifier()); if (!$timezone) { $log->warning("Timezone code '{code}' does not exist in repository {repository}", ['code' => $locality->getTimezoneIdentifier(), 'repository' => get_class($timezoneRepository)]); } } else { $timezone = null; } // Set the timezone $locality->setTimezone($timezone); // Register that the locality was imported /*$log->debug("'{locality}' imported into repository {repository}", [ 'locality' => $locality->getNameAscii(), 'repository' => get_class($localityRepository), ]);*/ // Import the localty into the repository $locality = $localityRepository->importLocality($locality); return $locality; }