AzuraCast/src/Console/Command/RestartRadio.php

59 lines
1.6 KiB
PHP
Raw Normal View History

<?php
namespace App\Console\Command;
use App\Radio\Configuration;
use Azura\Console\Command\CommandAbstract;
use Doctrine\ORM\EntityManager;
use App\Entity\Station;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class RestartRadio extends CommandAbstract
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('azuracast:radio:restart')
->setDescription('Restart all radio stations.');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeLn('Restarting all radio stations...');
/** @var \Supervisor\Supervisor $supervisor */
2018-05-07 01:57:06 +00:00
$supervisor = $this->get(\Supervisor\Supervisor::class);
/** @var EntityManager $em */
2018-05-07 01:57:06 +00:00
$em = $this->get(EntityManager::class);
/** @var Configuration $configuration */
2018-05-07 01:57:06 +00:00
$configuration = $this->get(Configuration::class);
/** @var Station[] $stations */
$stations = $em->getRepository(Station::class)->findAll();
$supervisor->stopAllProcesses();
foreach ($stations as $station) {
$output->writeLn('Restarting station #' . $station->getId() . ': ' . $station->getName());
$configuration->writeConfiguration($station);
$station->setHasStarted(true);
$station->setNeedsRestart(false);
$em->persist($station);
}
$supervisor->startAllProcesses();
$em->flush();
2018-05-07 01:57:06 +00:00
return 0;
}
}