protected function execute(InputInterface $input, OutputInterface $output)
{
$this->detectMagento($output);
if (!$this->initMagento()) {
return;
}
$helper = $this->getHelper('question');
$question = new Question('<question>Save the maps to [default: http.magerunmaps]: </question>', 'http.magerunmaps');
$defaultStoreFront = \Mage::app()->getDefaultStoreView()->getCode();
$map = 'map $host $storecode {';
$map .= "\n hostnames; \n";
$map .= "default " . $defaultStoreFront . ";\n";
foreach (\Mage::app()->getStores() as $store) {
$map .= "." . parse_url(\Mage::getStoreConfig('web/unsecure/base_url', $store))['host'] . " " . $store->getCode() . "; \n";
$table[$store->getId()] = array($store->getId(), $store->getCode(), \Mage::getStoreConfig('web/unsecure/base_url', $store), \Mage::getStoreConfig('web/secure/base_url', $store));
}
$map .= "}";
if ($input->getOption('save')) {
$filename = $helper->ask($input, $output, $question);
if ($filename && !file_exists($filename)) {
if (file_put_contents($filename, $map)) {
$output->writeln('<info>Succesfully written maps to ' . $filename . '</info>');
} else {
$output->writeln("<error>There was an issue writing to " . $filename . ".</error>");
}
} else {
$output->writeln('<info>File already exists, outputting it.</info>');
$this->writeSection($output, 'Mage run maps for Nginx. [Byte Hypernode]');
$output->writeln($map);
}
} else {
$this->writeSection($output, 'Mage run maps for Nginx. [Byte Hypernode]');
$output->writeln($map);
}
}