#1976 -- Add ability to restart a single station from CLI.

This commit is contained in:
Buster "Silver Eagle" Neece 2019-09-18 21:31:13 -05:00
parent bce49487c2
commit a98aebb8e0
No known key found for this signature in database
GPG Key ID: 6D9E12FF03411F4E
4 changed files with 34 additions and 13 deletions

View File

@ -94,9 +94,9 @@ return function(Application $console)
// Maintenance
$console->command(
'azuracast:radio:restart',
'azuracast:radio:restart [station-name]',
Command\RestartRadioCommand::class
)->setDescription('Restart all radio stations.');
)->setDescription('Restart all radio stations, or a single one if specified.');
$console->command(
'sync:run [task]',

View File

@ -1,12 +1,11 @@
<?php
namespace App\Console\Command;
use App\Entity\Repository\StationRepository;
use App\Entity\Station;
use App\Radio\Configuration;
use Azura\Console\Command\CommandAbstract;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class RestartRadioCommand extends CommandAbstract
@ -14,12 +13,27 @@ class RestartRadioCommand extends CommandAbstract
public function __invoke(
SymfonyStyle $io,
EntityManager $em,
Configuration $configuration
Configuration $configuration,
?string $stationName = null
) {
$io->section('Restarting all radio stations...');
/** @var StationRepository $stationRepo */
$stationRepo = $em->getRepository(Station::class);
/** @var Station[] $stations */
$stations = $em->getRepository(Station::class)->findAll();
if (!empty($stationName)) {
$station = $stationRepo->findByIdentifier($stationName);
if (!$station instanceof Station) {
$io->error('Station not found.');
return 1;
}
$stations = [$station];
} else {
$io->section('Restarting all radio stations...');
/** @var Station[] $stations */
$stations = $stationRepo->findAll();
}
$io->progressStart(count($stations));

View File

@ -47,6 +47,17 @@ class StationRepository extends Repository
*/
protected $cache;
/**
* @param string $identifier A numeric or string identifier for a station.
* @return Entity\Station|null
*/
public function findByIdentifier(string $identifier): ?Entity\Station
{
return is_numeric($identifier)
? $this->find($identifier)
: $this->findOneBy(['short_name' => $identifier]);
}
/**
* @return mixed
*/

View File

@ -44,11 +44,7 @@ class GetStation implements MiddlewareInterface
$id = $route_args['station_id'] ?? null;
if (!empty($id)) {
if (is_numeric($id)) {
$record = $this->station_repo->find($id);
} else {
$record = $this->station_repo->findByShortCode($id);
}
$record = $this->station_repo->findByIdentifier($id);
if ($record instanceof Entity\Station) {
$backend = $this->adapters->getBackendAdapter($record);