Refine adapter changes for compatibility.

This commit is contained in:
Buster "Silver Eagle" Neece 2021-01-19 15:16:32 -06:00
parent 4ccddeb5f3
commit 937be1ab21
No known key found for this signature in database
GPG Key ID: 6D9E12FF03411F4E
6 changed files with 31 additions and 98 deletions

View File

@ -45,6 +45,7 @@ class StationRequiresRestart implements EventSubscriber
];
$stations_to_restart = [];
foreach ($collections_to_check as $change_type => $collection) {
foreach ($collection as $entity) {
if (

View File

@ -121,17 +121,9 @@ class StationRepository extends Repository
*/
public function edit(Entity\Station $station): Entity\Station
{
// Create path for station.
$station->ensureDirectoriesExist();
$this->em->persist($station);
$this->em->persist($station->getMediaStorageLocation());
$this->em->persist($station->getRecordingsStorageLocation());
$original_record = $this->em->getUnitOfWork()->getOriginalEntityData($station);
// Generate station ID.
$this->em->flush();
$this->configuration->initializeConfiguration($station);
// Delete media-related items if the media storage is changed.
/** @var Entity\StorageLocation|null $oldMediaStorage */
@ -155,7 +147,9 @@ class StationRepository extends Repository
$this->resetMounts($station, $frontend);
}
$this->configuration->writeConfiguration($station, $adapter_changed);
if ($adapter_changed) {
$this->configuration->writeConfiguration($station, true);
}
return $station;
}

View File

@ -488,7 +488,13 @@ class Station
$frontend_config = $config;
}
$this->frontend_config = $frontend_config->toArray();
$config = $frontend_config->toArray();
if ($this->frontend_config != $config) {
$this->setNeedsRestart(true);
}
$this->frontend_config = $config;
}
public function getBackendType(): ?string
@ -548,7 +554,13 @@ class Station
$backend_config = $config;
}
$this->backend_config = $backend_config->toArray();
$config = $backend_config->toArray();
if ($this->backend_config != $config) {
$this->setNeedsRestart(true);
}
$this->backend_config = $config;
}
public function getAdapterApiKey(): ?string

View File

@ -50,30 +50,6 @@ abstract class AbstractAdapter
* @return bool Whether the newly written configuration differs from what was already on disk.
*/
public function write(Entity\Station $station): bool
{
return $this->compareConfiguration($station, true);
}
/**
* Generate the configuration for this adapter as it would exist with current database settings.
*
* @param Entity\Station $station
*
*/
public function getCurrentConfiguration(Entity\Station $station): ?string
{
return null;
}
/**
* Check whether the configuration currently generated differs from what is currently stored on disk.
*
* @param Entity\Station $station
* @param bool $writeNewConfig
*
* @return bool Whether configuration generated now differs from what is on disk.
*/
public function compareConfiguration(Entity\Station $station, bool $writeNewConfig = false): bool
{
$configPath = $this->getConfigurationPath($station);
if (null === $configPath) {
@ -86,13 +62,22 @@ abstract class AbstractAdapter
$newConfig = $this->getCurrentConfiguration($station);
if ($writeNewConfig) {
file_put_contents($configPath, $newConfig);
}
file_put_contents($configPath, $newConfig);
return 0 !== strcmp($currentConfig, $newConfig);
}
/**
* Generate the configuration for this adapter as it would exist with current database settings.
*
* @param Entity\Station $station
*
*/
public function getCurrentConfiguration(Entity\Station $station): ?string
{
return null;
}
/**
* Returns the main path where configuration data is stored for this adapter.
*
@ -170,25 +155,6 @@ abstract class AbstractAdapter
*/
abstract public function getProgramName(Entity\Station $station): string;
public function supportsSoftReload(): bool
{
return false;
}
/**
* Soft-reloads an adapter, if it's supported by the adapter.
*
* @param Entity\Station $station
*/
public function reload(Entity\Station $station): void
{
if (!$this->supportsSoftReload()) {
$this->restart($station);
}
throw new \RuntimeException('Feature not implemented!');
}
/**
* Restart the executable service.
*

View File

@ -63,35 +63,6 @@ class Configuration
$this->em->flush();
}
public function handleConfigurationChange(Station $station): void
{
if ($this->environment->isTesting()) {
return;
}
$this->initializeConfiguration($station);
if (!$station->isEnabled() || !$station->getHasStarted()) {
return;
}
$frontend = $this->adapters->getFrontendAdapter($station);
$backend = $this->adapters->getBackendAdapter($station);
if (!$frontend->hasCommand($station) && !$backend->hasCommand($station)) {
return;
}
$frontendChanged = $frontend->compareConfiguration($station);
$backendChanged = $backend->compareConfiguration($station);
if ($frontendChanged || $backendChanged) {
$station->setNeedsRestart(true);
$this->em->persist($station);
$this->em->flush();
}
}
/**
* Write all configuration changes to the filesystem and reload supervisord.
*

View File

@ -29,17 +29,6 @@ class Icecast extends AbstractFrontend
return true;
}
public function supportsSoftReload(): bool
{
return true;
}
public function reload(Entity\Station $station): void
{
$this->write($station);
// TODO: Implement soft-reload functionality.
}
public function getNowPlaying(Entity\Station $station, bool $includeClients = true): Result
{
$feConfig = $station->getFrontendConfig();