AzuraCast/app/src/AzuraCast/Console/Command/Setup.php

104 lines
3.3 KiB
PHP
Raw Normal View History

<?php
namespace AzuraCast\Console\Command;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Loader;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
2018-05-29 03:17:13 +00:00
use Symfony\Component\Console\Style\SymfonyStyle;
class Setup extends \App\Console\Command\CommandAbstract
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('azuracast:setup')
->setDescription('Run all general AzuraCast setup steps.')
->addOption('update', null, InputOption::VALUE_NONE, 'Only update the existing installation.')
->addOption('load-fixtures', null, InputOption::VALUE_NONE, 'Load predefined fixtures (for development purposes).');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$update_only = (bool)$input->getOption('update');
$load_fixtures = (bool)$input->getOption('load-fixtures');
2018-05-29 03:17:13 +00:00
$io = new SymfonyStyle($input, $output);
$io->title('AzuraCast Setup');
$io->writeln('Welcome to AzuraCast. Please wait while some key dependencies of AzuraCast are set up...');
$io->listing([
'Environment: '.ucfirst(APP_APPLICATION_ENV),
'Installation Method: '.((APP_INSIDE_DOCKER) ? 'Docker' : 'Traditional'),
]);
if ($update_only) {
$io->note('Running in update mode.');
if (!APP_INSIDE_DOCKER) {
$io->section('Migrating Legacy Configuration');
$this->runCommand($output, 'azuracast:config:migrate');
$io->newLine();
}
2018-05-29 03:17:13 +00:00
}
$io->section('Setting Up InfluxDB');
$this->runCommand($output, 'azuracast:setup:influx');
$this->runCommand($output, 'cache:clear');
2018-05-29 03:17:13 +00:00
$io->newLine();
$io->section('Running Database Migrations');
$this->runCommand($output, 'migrations:migrate', [
'--allow-no-migration' => true,
]);
2018-05-29 03:17:13 +00:00
$io->newLine();
$io->section('Generating Database Proxy Classes');
$this->runCommand($output, 'orm:generate-proxies');
if ($load_fixtures || (!APP_IN_PRODUCTION && !$update_only)) {
2018-05-29 03:17:13 +00:00
$io->newLine();
$io->section('Installing Data Fixtures');
$this->runCommand($output, 'azuracast:setup:fixtures');
}
2018-05-29 03:17:13 +00:00
$io->newLine();
$io->section('Refreshing All Stations');
$this->runCommand($output, 'cache:clear');
$this->runCommand($output, 'azuracast:radio:restart');
$local_ip = getHostByName(getHostName()) ?? 'localhost';
2018-05-29 03:17:13 +00:00
$io->newLine();
$io->success([
'AzuraCast installation complete!',
'Visit http://'.$local_ip.' to complete setup.',
]);
return 0;
}
protected function runCommand(OutputInterface $output, $command_name, $command_args = [])
{
$command = $this->getApplication()->find($command_name);
$input = new ArrayInput(['command' => $command_name] + $command_args);
$input->setInteractive(false);
$command->run($input, $output);
}
}