public function fire()
{
$country = $this->input->getOption('country');
$development = $this->input->getOption('development');
$fetchOnly = $this->input->getOption('fetch-only');
$wipeFiles = $this->input->getOption('wipe-files');
// i'm sorry but you can't have both :(
if ($development and !is_null($country)) {
throw new RuntimeException("You have to select between a country or a development version of GeoNames.");
}
// set a development names, lighter download
$development and $this->setDevelopment();
// set a specific country names
$country and $this->setCountry($country);
// path to download our files
$path = $this->getPath();
// if we forced to wipe files, we will delete the directory
$wipeFiles and $this->filesystem->deleteDirectory($path);
// create the directory if it doesn't exists
if (!$this->filesystem->isDirectory($path)) {
$this->filesystem->makeDirectory($path, 0755, true);
}
$files = $this->getFiles();
// loop all the files that we need to donwload
foreach ($files as $file) {
$filename = basename($file);
if ($this->fileExists($path, $filename)) {
$this->line("<info>File exists:</info> {$filename}");
continue;
}
$this->line("<info>Downloading:</info> {$file}");
$this->downloadFile($file, $path, $filename);
// if the file is ends with zip, we will try to unzip it and remove the zip file
if (substr($filename, -strlen('zip')) === "zip") {
$this->line("<info>Unzip:</info> {$filename}");
$filename = $this->extractZip($path, $filename);
}
}
// if we only want to fetch files, we must stop the execution of the command
if ($fetchOnly) {
$this->line('<info>Files fetched.</info>');
return;
}
$this->line("<info>It is time to seed the database. This may take 'a while'...</info>");
// finally seed the common seeders
$this->seedCommand('ContinentsTableSeeder');
$this->seedCommand('CountriesTableSeeder');
$this->seedCommand('AdminDivionsTableSeeder');
$this->seedCommand('AdminSubdivionsTableSeeder');
$this->seedCommand('HierarchiesTableSeeder');
$this->seedCommand('FeaturesTableSeeder');
$this->seedCommand('TimezonesTableSeeder');
// depending if we run a country, development or plain names we will run
// different seeders. Note that the langauge codes file is only
// available with the allCountries.zip file.
if ($development) {
$this->seedCommand('DevelopmentNamesTableSeeder');
} elseif ($country) {
$this->seedCommand('CountryNamesTableSeeder', '--country=' . $country);
} else {
$this->seedCommand('AlternateNamesTableSeeder');
$this->seedCommand('LanguageCodesTableSeeder');
$this->seedCommand('NamesTableSeeder');
}
}