2016-09-03 01:41:17 +00:00
|
|
|
<?php
|
2020-10-14 22:19:31 +00:00
|
|
|
|
2021-07-19 05:53:45 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-08-04 22:05:14 +00:00
|
|
|
namespace App\Console\Command;
|
2016-09-03 01:41:17 +00:00
|
|
|
|
2019-09-19 02:31:13 +00:00
|
|
|
use App\Entity\Repository\StationRepository;
|
2019-08-07 04:33:55 +00:00
|
|
|
use App\Entity\Station;
|
2018-08-04 22:05:14 +00:00
|
|
|
use App\Radio\Configuration;
|
2020-06-26 20:22:53 +00:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2019-03-06 16:51:16 +00:00
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
2016-09-18 00:00:46 +00:00
|
|
|
|
2019-09-10 23:10:57 +00:00
|
|
|
class RestartRadioCommand extends CommandAbstract
|
2016-09-03 01:41:17 +00:00
|
|
|
{
|
2019-09-10 23:10:57 +00:00
|
|
|
public function __invoke(
|
|
|
|
SymfonyStyle $io,
|
2020-06-26 20:22:53 +00:00
|
|
|
EntityManagerInterface $em,
|
2019-09-29 07:50:24 +00:00
|
|
|
StationRepository $stationRepo,
|
2019-09-19 02:31:13 +00:00
|
|
|
Configuration $configuration,
|
|
|
|
?string $stationName = null
|
2020-10-14 22:19:31 +00:00
|
|
|
): int {
|
2019-09-19 02:31:13 +00:00
|
|
|
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 */
|
2019-09-29 07:50:24 +00:00
|
|
|
$stations = $stationRepo->fetchAll();
|
2019-09-19 02:31:13 +00:00
|
|
|
}
|
2016-09-03 01:41:17 +00:00
|
|
|
|
2019-03-06 16:51:16 +00:00
|
|
|
$io->progressStart(count($stations));
|
2016-12-13 05:20:17 +00:00
|
|
|
|
2017-01-24 00:35:16 +00:00
|
|
|
foreach ($stations as $station) {
|
2021-01-19 17:52:45 +00:00
|
|
|
$configuration->writeConfiguration($station, true);
|
2019-03-06 16:51:16 +00:00
|
|
|
$io->progressAdvance();
|
2016-09-03 01:41:17 +00:00
|
|
|
}
|
2016-12-13 05:20:17 +00:00
|
|
|
|
2019-03-06 16:51:16 +00:00
|
|
|
$io->progressFinish();
|
2018-05-07 01:57:06 +00:00
|
|
|
return 0;
|
2016-09-03 01:41:17 +00:00
|
|
|
}
|
2018-08-04 22:05:14 +00:00
|
|
|
}
|