2016-09-03 01:41:17 +00:00
|
|
|
<?php
|
2018-08-04 22:05:14 +00:00
|
|
|
namespace App\Console\Command;
|
2016-09-03 01:41:17 +00:00
|
|
|
|
2018-08-04 22:05:14 +00:00
|
|
|
use App\Radio\Configuration;
|
2018-11-12 16:59:15 +00:00
|
|
|
use Azura\Console\Command\CommandAbstract;
|
2016-09-27 04:16:34 +00:00
|
|
|
use Doctrine\ORM\EntityManager;
|
2018-08-04 22:05:14 +00:00
|
|
|
use App\Entity\Station;
|
2016-09-18 00:00:46 +00:00
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
2018-11-12 16:59:15 +00:00
|
|
|
class RestartRadio extends CommandAbstract
|
2016-09-03 01:41:17 +00:00
|
|
|
{
|
|
|
|
/**
|
2016-09-18 00:00:46 +00:00
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
protected function configure()
|
|
|
|
{
|
2017-06-18 02:11:01 +00:00
|
|
|
$this->setName('azuracast:radio:restart')
|
2016-09-18 00:00:46 +00:00
|
|
|
->setDescription('Restart all radio stations.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
2016-09-03 01:41:17 +00:00
|
|
|
*/
|
2016-09-18 00:00:46 +00:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
2016-09-03 01:41:17 +00:00
|
|
|
{
|
2018-02-27 06:28:09 +00:00
|
|
|
$output->writeLn('Restarting all radio stations...');
|
2016-09-03 01:41:17 +00:00
|
|
|
|
2018-02-01 11:49:40 +00:00
|
|
|
/** @var \Supervisor\Supervisor $supervisor */
|
2018-05-07 01:57:06 +00:00
|
|
|
$supervisor = $this->get(\Supervisor\Supervisor::class);
|
2016-12-13 05:20:17 +00:00
|
|
|
|
2016-09-27 04:16:34 +00:00
|
|
|
/** @var EntityManager $em */
|
2018-05-07 01:57:06 +00:00
|
|
|
$em = $this->get(EntityManager::class);
|
2018-02-01 11:49:40 +00:00
|
|
|
|
|
|
|
/** @var Configuration $configuration */
|
2018-05-07 01:57:06 +00:00
|
|
|
$configuration = $this->get(Configuration::class);
|
2018-02-01 11:49:40 +00:00
|
|
|
|
|
|
|
/** @var Station[] $stations */
|
2016-09-27 04:16:34 +00:00
|
|
|
$stations = $em->getRepository(Station::class)->findAll();
|
2016-09-03 01:41:17 +00:00
|
|
|
|
2016-12-13 05:20:17 +00:00
|
|
|
$supervisor->stopAllProcesses();
|
|
|
|
|
2017-01-24 00:35:16 +00:00
|
|
|
foreach ($stations as $station) {
|
2018-02-27 06:28:09 +00:00
|
|
|
$output->writeLn('Restarting station #' . $station->getId() . ': ' . $station->getName());
|
2018-02-01 11:49:40 +00:00
|
|
|
$configuration->writeConfiguration($station);
|
2018-05-04 22:16:58 +00:00
|
|
|
|
|
|
|
$station->setHasStarted(true);
|
|
|
|
$station->setNeedsRestart(false);
|
|
|
|
|
|
|
|
$em->persist($station);
|
2016-09-03 01:41:17 +00:00
|
|
|
}
|
2016-12-13 05:20:17 +00:00
|
|
|
|
|
|
|
$supervisor->startAllProcesses();
|
2018-05-04 22:16:58 +00:00
|
|
|
$em->flush();
|
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
|
|
|
}
|