4
0
mirror of https://github.com/AzuraCast/AzuraCast.git synced 2024-06-14 13:16:37 +00:00
AzuraCast/src/Console/Command/SetupCommand.php

144 lines
4.1 KiB
PHP
Raw Normal View History

<?php
2021-07-19 05:53:45 +00:00
declare(strict_types=1);
namespace App\Console\Command;
use App\Entity;
use App\Environment;
use App\Service\AzuraCastCentral;
use Symfony\Component\Console\Attribute\AsCommand;
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;
#[AsCommand(
name: 'azuracast:setup',
description: 'Run all general AzuraCast setup steps.',
)]
2022-07-01 06:06:29 +00:00
final class SetupCommand extends CommandAbstract
{
public function __construct(
2022-07-01 06:06:29 +00:00
private readonly Environment $environment,
private readonly Entity\Repository\SettingsRepository $settingsRepo,
private readonly AzuraCastCentral $acCentral,
private readonly Entity\Repository\StorageLocationRepository $storageLocationRepo
) {
parent::__construct();
}
protected function configure(): void
{
$this->addOption('update', null, InputOption::VALUE_NONE)
->addOption('load-fixtures', null, InputOption::VALUE_NONE)
->addOption('release', null, InputOption::VALUE_NONE)
->addOption('init', null, InputOption::VALUE_NONE);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$update = (bool)$input->getOption('update');
$loadFixtures = (bool)$input->getOption('load-fixtures');
$isInit = (bool)$input->getOption('init');
if ($isInit) {
$update = true;
$loadFixtures = false;
}
2018-05-29 03:17:13 +00:00
if (!$update && !$this->environment->isProduction()) {
$loadFixtures = true;
}
// Header display
if ($isInit) {
$io->title(__('AzuraCast Initializing...'));
} else {
$io->title(__('AzuraCast Setup'));
$io->writeln(
__('Welcome to AzuraCast. Please wait while some key dependencies of AzuraCast are set up...')
);
2018-05-29 03:17:13 +00:00
$io->newLine();
}
$io->section(__('Running Database Migrations'));
$this->runCommand(
$output,
'azuracast:setup:migrate'
);
$io->newLine();
$io->section(__('Generating Database Proxy Classes'));
$this->runCommand($output, 'orm:generate-proxies');
$io->newLine();
$io->section(__('Reload System Data'));
$this->runCommand($output, 'cache:clear');
// Ensure default storage locations exist.
$this->storageLocationRepo->createDefaultStorageLocations();
$io->newLine();
if ($loadFixtures) {
$io->section(__('Installing Data Fixtures'));
2018-05-29 03:17:13 +00:00
$this->runCommand($output, 'azuracast:setup:fixtures');
$io->newLine();
}
$io->section(__('Refreshing All Stations'));
2022-03-15 08:38:32 +00:00
$this->runCommand($output, 'azuracast:station-queues:clear');
2022-03-15 08:58:47 +00:00
$restartArgs = [];
if ($this->environment->isDocker()) {
$restartArgs['--no-supervisor-restart'] = true;
2022-03-15 08:58:47 +00:00
}
2022-03-15 08:38:32 +00:00
$this->runCommand(
$output,
2022-03-15 08:58:47 +00:00
'azuracast:radio:restart',
$restartArgs
2022-03-15 08:38:32 +00:00
);
if ($isInit) {
return 0;
}
// Update system setting logging when updates were last run.
$settings = $this->settingsRepo->readSettings();
$settings->updateUpdateLastRun();
$this->settingsRepo->writeSettings($settings);
if ($update) {
$io->success(
[
__('AzuraCast is now updated to the latest version!'),
]
);
} else {
$public_ip = $this->acCentral->getIp(false);
2021-06-10 03:22:13 +00:00
/** @noinspection HttpUrlsUsage */
$io->success(
[
__('AzuraCast installation complete!'),
2022-05-07 16:44:14 +00:00
sprintf(
__('Visit %s to complete setup.'),
'http://' . $public_ip
),
]
);
}
return 0;
}
}