AzuraCast/src/Console/Command/InitializeCommand.php

90 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Console\Command;
use App\Entity;
use App\Environment;
use App\Service\Acme;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(
name: 'azuracast:setup:initialize',
description: 'Ensure key settings are initialized within AzuraCast.',
)]
class InitializeCommand extends CommandAbstract
{
public function __construct(
protected Environment $environment,
protected Entity\Repository\StorageLocationRepository $storageLocationRepo,
protected Acme $acme,
) {
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title(__('Initialize AzuraCast'));
$io->writeln(__('Initializing essential settings...'));
$io->listing(
[
sprintf(
__('Environment: %s'),
$this->environment->getAppEnvironmentEnum()->getName()
),
sprintf(
__('Installation Method: %s'),
$this->environment->isDocker() ? 'Docker' : 'Ansible'
),
]
);
$io->newLine();
$io->section(__('Running Database Migrations'));
$this->runCommand(
$output,
'migrations:migrate',
[
'--allow-no-migration' => true,
]
);
$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();
// Pull Acme certificates if necessary.
try {
$this->acme->getCertificate();
} catch (\Exception) {
// Noop
}
$io->newLine();
$io->success(
[
__('AzuraCast is now initialized.'),
]
);
return 0;
}
}