protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('<info>Welcome to the setup of lxHive!</info>');
$helper = $this->getHelper('question');
$question = new Question('Enter a name for this lxHive instance: ', 'Untitled');
$name = $helper->ask($input, $output, $question);
$connectionSuccesful = false;
while (!$connectionSuccesful) {
$question = new Question('Enter the URI of your MongoDB installation (default: "mongodb://127.0.0.1"): ', 'mongodb://127.0.0.1');
$mongoHostname = $helper->ask($input, $output, $question);
$client = new Client($mongoHostname);
try {
$mongoVersion = $client->getDbVersion();
$output->writeln('Connection succesful, MongoDB version ' . $mongoVersion . '.');
$connectionSuccesful = true;
} catch (\MongoConnectionException $e) {
$output->writeln('Connection unsuccesful, please try again.');
}
}
$question = new Question('Enter the name of your MongoDB database (default: "lxHive"): ', 'lxHive');
$mongoDatabase = $helper->ask($input, $output, $question);
$currentConfig = Yaml::parse(file_get_contents(__DIR__ . '/../Config/Config.template.yml'));
$mergingArray = ['name' => $name, 'database' => ['host_uri' => $mongoHostname, 'db_name' => $mongoDatabase]];
$newConfig = array_merge($currentConfig, $mergingArray);
$yamlData = Yaml::dump($newConfig);
file_put_contents(__DIR__ . '/../Config/Config.yml', $yamlData);
$output->writeln('<info>DB setup complete!</info>');
}