Migrate variables to camelCase (controllers).
This commit is contained in:
parent
0669d003c9
commit
5238522a0f
|
@ -35,10 +35,10 @@ final class AuditLogAction
|
|||
->setParameter('start', $start->getTimestamp())
|
||||
->setParameter('end', $end->getTimestamp());
|
||||
|
||||
$search_phrase = trim($request->getQueryParam('searchPhrase', ''));
|
||||
if (!empty($search_phrase)) {
|
||||
$searchPhrase = trim($request->getQueryParam('searchPhrase', ''));
|
||||
if (!empty($searchPhrase)) {
|
||||
$qb->andWhere('(a.user LIKE :query OR a.identifier LIKE :query OR a.target LIKE :query)')
|
||||
->setParameter('query', '%' . $search_phrase . '%');
|
||||
->setParameter('query', '%' . $searchPhrase . '%');
|
||||
}
|
||||
|
||||
$qb->orderBy('a.timestamp', 'DESC');
|
||||
|
|
|
@ -42,10 +42,10 @@ final class PermissionsAction
|
|||
): ResponseInterface {
|
||||
$permissions = [];
|
||||
foreach ($this->acl->listPermissions() as $group => $actions) {
|
||||
foreach ($actions as $action_id => $action_name) {
|
||||
foreach ($actions as $actionId => $actionName) {
|
||||
$permissions[$group][] = [
|
||||
'id' => $action_id,
|
||||
'name' => $action_name,
|
||||
'id' => $actionId,
|
||||
'name' => $actionName,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,10 +72,10 @@ final class RelaysController
|
|||
|
||||
$row->type = $station->getFrontendType()->value;
|
||||
|
||||
$frontend_config = $station->getFrontendConfig();
|
||||
$row->port = $frontend_config->getPort();
|
||||
$row->relay_pw = $frontend_config->getRelayPassword();
|
||||
$row->admin_pw = $frontend_config->getAdminPassword();
|
||||
$frontendConfig = $station->getFrontendConfig();
|
||||
$row->port = $frontendConfig->getPort();
|
||||
$row->relay_pw = $frontendConfig->getRelayPassword();
|
||||
$row->admin_pw = $frontendConfig->getAdminPassword();
|
||||
|
||||
$mounts = [];
|
||||
|
||||
|
@ -103,7 +103,7 @@ final class RelaysController
|
|||
*/
|
||||
private function getManageableStations(ServerRequest $request): array
|
||||
{
|
||||
$all_stations = $this->em->createQuery(
|
||||
$allStations = $this->em->createQuery(
|
||||
<<<'DQL'
|
||||
SELECT s, sm
|
||||
FROM App\Entity\Station s
|
||||
|
@ -117,7 +117,7 @@ final class RelaysController
|
|||
$acl = $request->getAcl();
|
||||
|
||||
return array_filter(
|
||||
$all_stations,
|
||||
$allStations,
|
||||
static function (Station $station) use ($acl) {
|
||||
return $acl->isAllowed(StationPermissions::Broadcasting, $station->getId());
|
||||
}
|
||||
|
@ -128,20 +128,20 @@ final class RelaysController
|
|||
ServerRequest $request,
|
||||
Response $response
|
||||
): ResponseInterface {
|
||||
$relay_repo = $this->em->getRepository(Relay::class);
|
||||
$relayRepo = $this->em->getRepository(Relay::class);
|
||||
|
||||
$body = (array)$request->getParsedBody();
|
||||
|
||||
if (!empty($body['base_url'])) {
|
||||
$base_url = $body['base_url'];
|
||||
$baseUrl = $body['base_url'];
|
||||
} else {
|
||||
/** @noinspection HttpUrlsUsage */
|
||||
$base_url = 'http://' . $this->readSettings()->getIp($request);
|
||||
$baseUrl = 'http://' . $this->readSettings()->getIp($request);
|
||||
}
|
||||
|
||||
$relay = $relay_repo->findOneBy(['base_url' => $base_url]);
|
||||
$relay = $relayRepo->findOneBy(['base_url' => $baseUrl]);
|
||||
if (!$relay instanceof Relay) {
|
||||
$relay = new Relay($base_url);
|
||||
$relay = new Relay($baseUrl);
|
||||
}
|
||||
|
||||
$relay->setName($body['name'] ?? 'Relay');
|
||||
|
@ -151,26 +151,26 @@ final class RelaysController
|
|||
$this->em->persist($relay);
|
||||
|
||||
// List existing remotes to avoid duplication.
|
||||
$existing_remotes = [];
|
||||
$existingRemotes = [];
|
||||
|
||||
foreach ($relay->getRemotes() as $remote) {
|
||||
/** @var StationRemote $remote */
|
||||
$existing_remotes[$remote->getStation()->getId()][$remote->getMount()] = $remote;
|
||||
$existingRemotes[$remote->getStation()->getId()][$remote->getMount()] = $remote;
|
||||
}
|
||||
|
||||
// Iterate through all remotes that *should* exist.
|
||||
foreach ($this->getManageableStations($request) as $station) {
|
||||
$station_id = $station->getId();
|
||||
$stationId = $station->getId();
|
||||
|
||||
foreach ($station->getMounts() as $mount) {
|
||||
/** @var StationMount $mount */
|
||||
$mount_path = $mount->getName();
|
||||
$mountPath = $mount->getName();
|
||||
|
||||
if (isset($existing_remotes[$station_id][$mount_path])) {
|
||||
if (isset($existingRemotes[$stationId][$mountPath])) {
|
||||
/** @var StationRemote $remote */
|
||||
$remote = $existing_remotes[$station_id][$mount_path];
|
||||
$remote = $existingRemotes[$stationId][$mountPath];
|
||||
|
||||
unset($existing_remotes[$station_id][$mount_path]);
|
||||
unset($existingRemotes[$stationId][$mountPath]);
|
||||
} else {
|
||||
$remote = new StationRemote($station);
|
||||
}
|
||||
|
@ -189,9 +189,9 @@ final class RelaysController
|
|||
}
|
||||
|
||||
// Remove all remotes that weren't processed earlier.
|
||||
foreach ($existing_remotes as $existing_remote_station) {
|
||||
foreach ($existing_remote_station as $existing_remote) {
|
||||
$this->em->remove($existing_remote);
|
||||
foreach ($existingRemotes as $existingRemoteStation) {
|
||||
foreach ($existingRemoteStation as $existingRemote) {
|
||||
$this->em->remove($existingRemote);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -246,23 +246,23 @@ final class RolesController extends AbstractAdminApiCrudController
|
|||
}
|
||||
|
||||
if (isset($newPermissions['global'])) {
|
||||
foreach ($newPermissions['global'] as $perm_name) {
|
||||
if ($this->acl->isValidPermission($perm_name, true)) {
|
||||
$perm_record = new RolePermission($role, null, $perm_name);
|
||||
$this->em->persist($perm_record);
|
||||
foreach ($newPermissions['global'] as $permName) {
|
||||
if ($this->acl->isValidPermission($permName, true)) {
|
||||
$permRecord = new RolePermission($role, null, $permName);
|
||||
$this->em->persist($permRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($newPermissions['station'])) {
|
||||
foreach ($newPermissions['station'] as $station_id => $station_perms) {
|
||||
$station = $this->em->find(Station::class, $station_id);
|
||||
foreach ($newPermissions['station'] as $stationId => $stationPerms) {
|
||||
$station = $this->em->find(Station::class, $stationId);
|
||||
|
||||
if ($station instanceof Station) {
|
||||
foreach ($station_perms as $perm_name) {
|
||||
if ($this->acl->isValidPermission($perm_name, false)) {
|
||||
$perm_record = new RolePermission($role, $station, $perm_name);
|
||||
$this->em->persist($perm_record);
|
||||
foreach ($stationPerms as $permName) {
|
||||
if ($this->acl->isValidPermission($permName, false)) {
|
||||
$permRecord = new RolePermission($role, $station, $permName);
|
||||
$this->em->persist($permRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,8 +88,8 @@ final class CloneAction extends StationsController
|
|||
}
|
||||
|
||||
// Set new radio base directory
|
||||
$station_base_dir = $this->environment->getStationDirectory();
|
||||
$newStation->setRadioBaseDir($station_base_dir . '/' . $newStation->getShortName());
|
||||
$stationBaseDir = $this->environment->getStationDirectory();
|
||||
$newStation->setRadioBaseDir($stationBaseDir . '/' . $newStation->getShortName());
|
||||
|
||||
$newStation->ensureDirectoriesExist();
|
||||
|
||||
|
|
|
@ -262,7 +262,7 @@ class StationsController extends AbstractAdminApiCrudController
|
|||
*/
|
||||
protected function editRecord(?array $data, object $record = null, array $context = []): object
|
||||
{
|
||||
$create_mode = (null === $record);
|
||||
$createMode = (null === $record);
|
||||
|
||||
if (null === $data) {
|
||||
throw new InvalidArgumentException('Could not parse input data.');
|
||||
|
@ -275,7 +275,7 @@ class StationsController extends AbstractAdminApiCrudController
|
|||
throw ValidationException::fromValidationErrors($errors);
|
||||
}
|
||||
|
||||
return ($create_mode)
|
||||
return ($createMode)
|
||||
? $this->handleCreate($record)
|
||||
: $this->handleEdit($record);
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ class StationsController extends AbstractAdminApiCrudController
|
|||
|
||||
protected function handleEdit(Station $station): Station
|
||||
{
|
||||
$original_record = $this->em->getUnitOfWork()->getOriginalEntityData($station);
|
||||
$originalRecord = $this->em->getUnitOfWork()->getOriginalEntityData($station);
|
||||
|
||||
$this->em->persist($station);
|
||||
$this->em->flush();
|
||||
|
@ -299,7 +299,7 @@ class StationsController extends AbstractAdminApiCrudController
|
|||
|
||||
// Delete media-related items if the media storage is changed.
|
||||
/** @var StorageLocation|null $oldMediaStorage */
|
||||
$oldMediaStorage = $original_record['media_storage_location'];
|
||||
$oldMediaStorage = $originalRecord['media_storage_location'];
|
||||
$newMediaStorage = $station->getMediaStorageLocation();
|
||||
|
||||
if (null === $oldMediaStorage || $oldMediaStorage->getId() !== $newMediaStorage->getId()) {
|
||||
|
@ -312,25 +312,25 @@ class StationsController extends AbstractAdminApiCrudController
|
|||
}
|
||||
|
||||
// Get the original values to check for changes.
|
||||
$old_frontend = $original_record['frontend_type'];
|
||||
$old_backend = $original_record['backend_type'];
|
||||
$old_hls = (bool)$original_record['enable_hls'];
|
||||
$oldFrontend = $originalRecord['frontend_type'];
|
||||
$oldBackend = $originalRecord['backend_type'];
|
||||
$oldHls = (bool)$originalRecord['enable_hls'];
|
||||
|
||||
$frontend_changed = ($old_frontend !== $station->getFrontendType());
|
||||
$backend_changed = ($old_backend !== $station->getBackendType());
|
||||
$adapter_changed = $frontend_changed || $backend_changed;
|
||||
$frontendChanged = ($oldFrontend !== $station->getFrontendType());
|
||||
$backendChanged = ($oldBackend !== $station->getBackendType());
|
||||
$adapterChanged = $frontendChanged || $backendChanged;
|
||||
|
||||
$hls_changed = $old_hls !== $station->getEnableHls();
|
||||
$hlsChanged = $oldHls !== $station->getEnableHls();
|
||||
|
||||
if ($frontend_changed) {
|
||||
if ($frontendChanged) {
|
||||
$this->stationRepo->resetMounts($station);
|
||||
}
|
||||
|
||||
if ($hls_changed || $backend_changed) {
|
||||
if ($hlsChanged || $backendChanged) {
|
||||
$this->stationRepo->resetHls($station);
|
||||
}
|
||||
|
||||
if ($adapter_changed || !$station->getIsEnabled()) {
|
||||
if ($adapterChanged || !$station->getIsEnabled()) {
|
||||
try {
|
||||
$this->configuration->writeConfiguration(
|
||||
station: $station,
|
||||
|
|
|
@ -61,18 +61,18 @@ final class PutTwoFactorAction extends UsersController
|
|||
$totp->setParameter('image', 'https://www.azuracast.com/img/logo.png');
|
||||
|
||||
// Generate QR code
|
||||
$totp_uri = $totp->getProvisioningUri();
|
||||
$totpUri = $totp->getProvisioningUri();
|
||||
|
||||
$renderer = new BaconQrCode\Renderer\ImageRenderer(
|
||||
new BaconQrCode\Renderer\RendererStyle\RendererStyle(300),
|
||||
new BaconQrCode\Renderer\Image\SvgImageBackEnd()
|
||||
);
|
||||
$qrCodeImage = (new BaconQrCode\Writer($renderer))->writeString($totp_uri);
|
||||
$qrCodeImage = (new BaconQrCode\Writer($renderer))->writeString($totpUri);
|
||||
$qrCodeBase64 = 'data:image/svg+xml;base64,' . base64_encode($qrCodeImage);
|
||||
|
||||
return $response->withJson([
|
||||
'secret' => $secret,
|
||||
'totp_uri' => $totp_uri,
|
||||
'totp_uri' => $totpUri,
|
||||
'qr_code' => $qrCodeBase64,
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
|
|
|
@ -166,7 +166,7 @@ final class UploadAction
|
|||
return $response->withJson(
|
||||
new StationPlaylistImportResult(
|
||||
message: sprintf(__('%d files processed.'), $processed),
|
||||
import_results: $importResults
|
||||
importResults: $importResults
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -80,15 +80,15 @@ final class FlowUploadAction
|
|||
|
||||
// If the user is looking at a playlist's contents, add uploaded media to that playlist.
|
||||
if ($stationMedia instanceof StationMedia && !empty($allParams['searchPhrase'])) {
|
||||
$search_phrase = $allParams['searchPhrase'];
|
||||
$searchPhrase = $allParams['searchPhrase'];
|
||||
|
||||
if (str_starts_with($search_phrase, 'playlist:')) {
|
||||
$playlist_name = substr($search_phrase, 9);
|
||||
if (str_starts_with($searchPhrase, 'playlist:')) {
|
||||
$playlistName = substr($searchPhrase, 9);
|
||||
|
||||
$playlist = $this->em->getRepository(StationPlaylist::class)->findOneBy(
|
||||
[
|
||||
'station_id' => $station->getId(),
|
||||
'name' => $playlist_name,
|
||||
'name' => $playlistName,
|
||||
]
|
||||
);
|
||||
|
||||
|
|
|
@ -233,9 +233,9 @@ final class ListAction
|
|||
? $row->path
|
||||
: basename($row->path);
|
||||
|
||||
$max_length = 60;
|
||||
if (mb_strlen($shortname) > $max_length) {
|
||||
$shortname = mb_substr($shortname, 0, $max_length - 15) . '...' . mb_substr($shortname, -12);
|
||||
$maxLength = 60;
|
||||
if (mb_strlen($shortname) > $maxLength) {
|
||||
$shortname = mb_substr($shortname, 0, $maxLength - 15) . '...' . mb_substr($shortname, -12);
|
||||
}
|
||||
$row->path_short = $shortname;
|
||||
|
||||
|
|
|
@ -205,23 +205,23 @@ final class FilesController extends AbstractStationApiCrudController
|
|||
$request->getParsedBody();
|
||||
|
||||
// Convert the body into an UploadFile API entity first.
|
||||
/** @var UploadFile $api_record */
|
||||
$api_record = $this->serializer->denormalize($request->getParsedBody(), UploadFile::class, null, []);
|
||||
/** @var UploadFile $apiRecord */
|
||||
$apiRecord = $this->serializer->denormalize($request->getParsedBody(), UploadFile::class, null, []);
|
||||
|
||||
// Validate the UploadFile API record.
|
||||
$errors = $this->validator->validate($api_record);
|
||||
$errors = $this->validator->validate($apiRecord);
|
||||
if (count($errors) > 0) {
|
||||
throw ValidationException::fromValidationErrors($errors);
|
||||
}
|
||||
|
||||
// Write file to temp path.
|
||||
$tempPath = $station->getRadioTempDir() . '/' . $api_record->getSanitizedFilename();
|
||||
file_put_contents($tempPath, $api_record->getFileContents());
|
||||
$tempPath = $station->getRadioTempDir() . '/' . $apiRecord->getSanitizedFilename();
|
||||
file_put_contents($tempPath, $apiRecord->getFileContents());
|
||||
|
||||
// Process temp path as regular media record.
|
||||
$record = $this->mediaProcessor->processAndUpload(
|
||||
$mediaStorage,
|
||||
$api_record->getSanitizedPath(),
|
||||
$apiRecord->getSanitizedPath(),
|
||||
$tempPath
|
||||
);
|
||||
|
||||
|
@ -235,7 +235,7 @@ final class FilesController extends AbstractStationApiCrudController
|
|||
public function editAction(
|
||||
ServerRequest $request,
|
||||
Response $response,
|
||||
string $station_id,
|
||||
string $stationId,
|
||||
string $id
|
||||
): ResponseInterface {
|
||||
$station = $this->getStation($request);
|
||||
|
@ -251,7 +251,7 @@ final class FilesController extends AbstractStationApiCrudController
|
|||
throw new InvalidArgumentException('Could not parse input data.');
|
||||
}
|
||||
|
||||
$custom_fields = $data['custom_fields'] ?? null;
|
||||
$customFields = $data['custom_fields'] ?? null;
|
||||
$playlists = $data['playlists'] ?? null;
|
||||
unset($data['custom_fields'], $data['playlists']);
|
||||
|
||||
|
@ -276,44 +276,44 @@ final class FilesController extends AbstractStationApiCrudController
|
|||
$this->em->persist($record);
|
||||
$this->em->flush();
|
||||
|
||||
if (null !== $custom_fields) {
|
||||
$this->customFieldsRepo->setCustomFields($record, $custom_fields);
|
||||
if (null !== $customFields) {
|
||||
$this->customFieldsRepo->setCustomFields($record, $customFields);
|
||||
}
|
||||
|
||||
if (null !== $playlists) {
|
||||
/** @var StationPlaylist[] $affected_playlists */
|
||||
$affected_playlists = [];
|
||||
/** @var StationPlaylist[] $affectedPlaylists */
|
||||
$affectedPlaylists = [];
|
||||
|
||||
// Remove existing playlists.
|
||||
$media_playlists = $this->playlistMediaRepo->clearPlaylistsFromMedia($record, $station);
|
||||
$mediaPlaylists = $this->playlistMediaRepo->clearPlaylistsFromMedia($record, $station);
|
||||
$this->em->flush();
|
||||
|
||||
foreach ($media_playlists as $playlist_id => $playlist) {
|
||||
if (!isset($affected_playlists[$playlist_id])) {
|
||||
$affected_playlists[$playlist_id] = $playlist;
|
||||
foreach ($mediaPlaylists as $playlistId => $playlist) {
|
||||
if (!isset($affectedPlaylists[$playlistId])) {
|
||||
$affectedPlaylists[$playlistId] = $playlist;
|
||||
}
|
||||
}
|
||||
|
||||
// Set new playlists.
|
||||
foreach ($playlists as $new_playlist) {
|
||||
if (is_array($new_playlist)) {
|
||||
$playlist_id = $new_playlist['id'];
|
||||
$playlist_weight = $new_playlist['weight'] ?? 0;
|
||||
foreach ($playlists as $newPlaylist) {
|
||||
if (is_array($newPlaylist)) {
|
||||
$playlistId = $newPlaylist['id'];
|
||||
$playlistWeight = $newPlaylist['weight'] ?? 0;
|
||||
} else {
|
||||
$playlist_id = (int)$new_playlist;
|
||||
$playlist_weight = 0;
|
||||
$playlistId = (int)$newPlaylist;
|
||||
$playlistWeight = 0;
|
||||
}
|
||||
|
||||
$playlist = $this->em->getRepository(StationPlaylist::class)->findOneBy(
|
||||
[
|
||||
'station' => $station,
|
||||
'id' => $playlist_id,
|
||||
'id' => $playlistId,
|
||||
]
|
||||
);
|
||||
|
||||
if ($playlist instanceof StationPlaylist) {
|
||||
$affected_playlists[$playlist->getId()] = $playlist;
|
||||
$this->playlistMediaRepo->addMediaToPlaylist($record, $playlist, $playlist_weight);
|
||||
$affectedPlaylists[$playlist->getId()] = $playlist;
|
||||
$this->playlistMediaRepo->addMediaToPlaylist($record, $playlist, $playlistWeight);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,10 +322,10 @@ final class FilesController extends AbstractStationApiCrudController
|
|||
// Handle playlist changes.
|
||||
$backend = $this->adapters->getBackendAdapter($station);
|
||||
if ($backend instanceof Liquidsoap) {
|
||||
foreach ($affected_playlists as $playlist_id => $playlist_row) {
|
||||
foreach ($affectedPlaylists as $playlistId => $playlistRow) {
|
||||
// Instruct the message queue to start a new "write playlist to file" task.
|
||||
$message = new WritePlaylistFileMessage();
|
||||
$message->playlist_id = $playlist_id;
|
||||
$message->playlist_id = $playlistId;
|
||||
|
||||
$this->messageBus->dispatch($message);
|
||||
}
|
||||
|
@ -397,12 +397,12 @@ final class FilesController extends AbstractStationApiCrudController
|
|||
|
||||
// Delete the media file off the filesystem.
|
||||
// Write new PLS playlist configuration.
|
||||
foreach ($this->mediaRepo->remove($record, true) as $playlist_id => $playlist) {
|
||||
foreach ($this->mediaRepo->remove($record, true) as $playlistId => $playlist) {
|
||||
$backend = $this->adapters->getBackendAdapter($playlist->getStation());
|
||||
if ($backend instanceof Liquidsoap) {
|
||||
// Instruct the message queue to start a new "write playlist to file" task.
|
||||
$message = new WritePlaylistFileMessage();
|
||||
$message->playlist_id = $playlist_id;
|
||||
$message->playlist_id = $playlistId;
|
||||
|
||||
$this->messageBus->dispatch($message);
|
||||
}
|
||||
|
|
|
@ -80,9 +80,9 @@ final class HistoryController
|
|||
set_time_limit($this->environment->getSyncLongExecutionTime());
|
||||
|
||||
$station = $request->getStation();
|
||||
$station_tz = $station->getTimezoneObject();
|
||||
$stationTz = $station->getTimezoneObject();
|
||||
|
||||
$dateRange = $this->getDateRange($request, $station_tz);
|
||||
$dateRange = $this->getDateRange($request, $stationTz);
|
||||
$start = $dateRange->getStart();
|
||||
$end = $dateRange->getEnd();
|
||||
|
||||
|
@ -118,10 +118,10 @@ final class HistoryController
|
|||
);
|
||||
}
|
||||
|
||||
$search_phrase = trim($request->getQueryParam('searchPhrase') ?? '');
|
||||
if (!empty($search_phrase)) {
|
||||
$searchPhrase = trim($request->getQueryParam('searchPhrase') ?? '');
|
||||
if (!empty($searchPhrase)) {
|
||||
$qb->andWhere('(sh.title LIKE :query OR sh.artist LIKE :query)')
|
||||
->setParameter('query', '%' . $search_phrase . '%');
|
||||
->setParameter('query', '%' . $searchPhrase . '%');
|
||||
}
|
||||
|
||||
$qb->orderBy('sh.timestamp_start', 'DESC');
|
||||
|
@ -131,9 +131,9 @@ final class HistoryController
|
|||
$router = $request->getRouter();
|
||||
|
||||
$paginator->setPostprocessor(
|
||||
function ($sh_row) use ($router) {
|
||||
/** @var SongHistory $sh_row */
|
||||
$row = $this->songHistoryApiGenerator->detailed($sh_row);
|
||||
function ($shRow) use ($router) {
|
||||
/** @var SongHistory $shRow */
|
||||
$row = $this->songHistoryApiGenerator->detailed($shRow);
|
||||
$row->resolveUrls($router->getBaseUrl());
|
||||
|
||||
return $row;
|
||||
|
|
|
@ -75,17 +75,17 @@ final class IndexController
|
|||
ServerRequest $request,
|
||||
Response $response
|
||||
): ResponseInterface {
|
||||
$stations_raw = $this->em->getRepository(Station::class)
|
||||
$stationsRaw = $this->em->getRepository(Station::class)
|
||||
->findBy(['is_enabled' => 1]);
|
||||
|
||||
$stations = [];
|
||||
foreach ($stations_raw as $row) {
|
||||
foreach ($stationsRaw as $row) {
|
||||
/** @var Station $row */
|
||||
$api_row = ($this->stationApiGenerator)($row);
|
||||
$api_row->resolveUrls($request->getRouter()->getBaseUrl());
|
||||
$apiRow = ($this->stationApiGenerator)($row);
|
||||
$apiRow->resolveUrls($request->getRouter()->getBaseUrl());
|
||||
|
||||
if ($api_row->is_public) {
|
||||
$stations[] = $api_row;
|
||||
if ($apiRow->is_public) {
|
||||
$stations[] = $apiRow;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ final class GetOrderAction
|
|||
throw new Exception(__('This playlist is not a sequential playlist.'));
|
||||
}
|
||||
|
||||
$media_items = $this->em->createQuery(
|
||||
$mediaItems = $this->em->createQuery(
|
||||
<<<'DQL'
|
||||
SELECT spm, sm
|
||||
FROM App\Entity\StationPlaylistMedia spm
|
||||
|
@ -64,7 +64,7 @@ final class GetOrderAction
|
|||
];
|
||||
return $row;
|
||||
},
|
||||
$media_items
|
||||
$mediaItems
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ final class ImportAction
|
|||
$mediaLookup = [];
|
||||
$basenameLookup = [];
|
||||
|
||||
$media_info_raw = $this->em->createQuery(
|
||||
$mediaInfoRaw = $this->em->createQuery(
|
||||
<<<'DQL'
|
||||
SELECT sm.id, sm.path
|
||||
FROM App\Entity\StationMedia sm
|
||||
|
@ -76,7 +76,7 @@ final class ImportAction
|
|||
)->setParameter('storageLocation', $storageLocation)
|
||||
->getArrayResult();
|
||||
|
||||
foreach ($media_info_raw as $row) {
|
||||
foreach ($mediaInfoRaw as $row) {
|
||||
$pathParts = explode('/', $row['path']);
|
||||
|
||||
$basename = File::sanitizeFileName(array_pop($pathParts));
|
||||
|
@ -100,12 +100,12 @@ final class ImportAction
|
|||
// Run all paths against the lookup list of hashes.
|
||||
$matches = [];
|
||||
|
||||
$matchFunction = static function ($path_raw) use ($mediaLookup, $basenameLookup) {
|
||||
$matchFunction = static function ($pathRaw) use ($mediaLookup, $basenameLookup) {
|
||||
// De-Windows paths (if applicable)
|
||||
$path_raw = str_replace('\\', '/', $path_raw);
|
||||
$pathRaw = str_replace('\\', '/', $pathRaw);
|
||||
|
||||
// Work backwards from the basename to try to find matches.
|
||||
$pathParts = explode('/', $path_raw);
|
||||
$pathParts = explode('/', $pathRaw);
|
||||
|
||||
$basename = File::sanitizeFileName(array_pop($pathParts));
|
||||
$basenameWithoutExt = Path::getFilenameWithoutExtension($basename);
|
||||
|
@ -142,11 +142,11 @@ final class ImportAction
|
|||
return [null, null];
|
||||
};
|
||||
|
||||
foreach ($paths as $path_raw) {
|
||||
[$matchedPath, $match] = $matchFunction($path_raw);
|
||||
foreach ($paths as $pathRaw) {
|
||||
[$matchedPath, $match] = $matchFunction($pathRaw);
|
||||
|
||||
$importResults[] = [
|
||||
'path' => $path_raw,
|
||||
'path' => $pathRaw,
|
||||
'match' => $matchedPath,
|
||||
];
|
||||
|
||||
|
|
|
@ -25,17 +25,17 @@ final class ToggleAction
|
|||
): ResponseInterface {
|
||||
$record = $this->playlistRepo->requireForStation($id, $request->getStation());
|
||||
|
||||
$new_value = !$record->getIsEnabled();
|
||||
$record->setIsEnabled($new_value);
|
||||
$newValue = !$record->getIsEnabled();
|
||||
$record->setIsEnabled($newValue);
|
||||
|
||||
$em = $this->playlistRepo->getEntityManager();
|
||||
$em->persist($record);
|
||||
$em->flush();
|
||||
|
||||
$flash_message = ($new_value)
|
||||
$flashMessage = ($newValue)
|
||||
? __('Playlist enabled.')
|
||||
: __('Playlist disabled.');
|
||||
|
||||
return $response->withJson(new Status(true, $flash_message));
|
||||
return $response->withJson(new Status(true, $flashMessage));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,7 +241,7 @@ final class PlaylistsController extends AbstractScheduledEntityController
|
|||
|
||||
$return = $this->toArray($record);
|
||||
|
||||
$song_totals = $this->em->createQuery(
|
||||
$songTotals = $this->em->createQuery(
|
||||
<<<'DQL'
|
||||
SELECT count(sm.id) AS num_songs, sum(sm.length) AS total_length
|
||||
FROM App\Entity\StationMedia sm
|
||||
|
@ -253,8 +253,8 @@ final class PlaylistsController extends AbstractScheduledEntityController
|
|||
|
||||
$return['short_name'] = StationPlaylist::generateShortName($return['name']);
|
||||
|
||||
$return['num_songs'] = (int)$song_totals[0]['num_songs'];
|
||||
$return['total_length'] = (int)$song_totals[0]['total_length'];
|
||||
$return['num_songs'] = (int)$songTotals[0]['num_songs'];
|
||||
$return['total_length'] = (int)$songTotals[0]['total_length'];
|
||||
|
||||
$isInternal = ('true' === $request->getParam('internal', 'false'));
|
||||
$router = $request->getRouter();
|
||||
|
|
|
@ -44,63 +44,63 @@ final class ChartsAction extends AbstractReportAction
|
|||
$dateRange
|
||||
);
|
||||
|
||||
$daily_chart = new stdClass();
|
||||
$daily_chart->label = __('Listeners by Day');
|
||||
$daily_chart->type = 'line';
|
||||
$daily_chart->fill = false;
|
||||
$dailyChart = new stdClass();
|
||||
$dailyChart->label = __('Listeners by Day');
|
||||
$dailyChart->type = 'line';
|
||||
$dailyChart->fill = false;
|
||||
|
||||
$dailyAlt = [
|
||||
'label' => $daily_chart->label,
|
||||
'label' => $dailyChart->label,
|
||||
'values' => [],
|
||||
];
|
||||
|
||||
$daily_averages = [];
|
||||
$dailyAverages = [];
|
||||
|
||||
$days_of_week = [];
|
||||
$daysOfWeek = [];
|
||||
|
||||
foreach ($dailyStats as $stat) {
|
||||
/** @var CarbonImmutable $statTime */
|
||||
$statTime = $stat['moment'];
|
||||
$statTime = $statTime->shiftTimezone($stationTz);
|
||||
|
||||
$avg_row = new stdClass();
|
||||
$avg_row->x = $statTime->getTimestampMs();
|
||||
$avg_row->y = round((float)$stat['number_avg'], 2);
|
||||
$daily_averages[] = $avg_row;
|
||||
$avgRow = new stdClass();
|
||||
$avgRow->x = $statTime->getTimestampMs();
|
||||
$avgRow->y = round((float)$stat['number_avg'], 2);
|
||||
$dailyAverages[] = $avgRow;
|
||||
|
||||
$row_date = $statTime->format('Y-m-d');
|
||||
$rowDate = $statTime->format('Y-m-d');
|
||||
|
||||
$dailyAlt['values'][] = [
|
||||
'label' => $row_date,
|
||||
'label' => $rowDate,
|
||||
'type' => 'time',
|
||||
'original' => $avg_row->x,
|
||||
'value' => $avg_row->y . ' ' . __('Listeners'),
|
||||
'original' => $avgRow->x,
|
||||
'value' => $avgRow->y . ' ' . __('Listeners'),
|
||||
];
|
||||
|
||||
$day_of_week = (int)$statTime->format('N') - 1;
|
||||
$days_of_week[$day_of_week][] = $stat['number_avg'];
|
||||
$dayOfWeek = (int)$statTime->format('N') - 1;
|
||||
$daysOfWeek[$dayOfWeek][] = $stat['number_avg'];
|
||||
}
|
||||
|
||||
$daily_chart->data = $daily_averages;
|
||||
$dailyChart->data = $dailyAverages;
|
||||
|
||||
$stats['daily'] = [
|
||||
'metrics' => [
|
||||
$daily_chart,
|
||||
$dailyChart,
|
||||
],
|
||||
'alt' => [
|
||||
$dailyAlt,
|
||||
],
|
||||
];
|
||||
|
||||
$day_of_week_chart = new stdClass();
|
||||
$day_of_week_chart->label = __('Listeners by Day of Week');
|
||||
$dayOfWeekChart = new stdClass();
|
||||
$dayOfWeekChart->label = __('Listeners by Day of Week');
|
||||
|
||||
$dayOfWeekAlt = [
|
||||
'label' => $day_of_week_chart->label,
|
||||
'label' => $dayOfWeekChart->label,
|
||||
'values' => [],
|
||||
];
|
||||
|
||||
$days_of_week_names = [
|
||||
$daysOfWeekNames = [
|
||||
__('Monday'),
|
||||
__('Tuesday'),
|
||||
__('Wednesday'),
|
||||
|
@ -110,27 +110,27 @@ final class ChartsAction extends AbstractReportAction
|
|||
__('Sunday'),
|
||||
];
|
||||
|
||||
$day_of_week_stats = [];
|
||||
$dayOfWeekStats = [];
|
||||
|
||||
foreach ($days_of_week_names as $day_index => $day_name) {
|
||||
$day_totals = $days_of_week[$day_index] ?? [0];
|
||||
foreach ($daysOfWeekNames as $dayIndex => $dayName) {
|
||||
$dayTotals = $daysOfWeek[$dayIndex] ?? [0];
|
||||
|
||||
$stat_value = round(array_sum($day_totals) / count($day_totals), 2);
|
||||
$day_of_week_stats[] = $stat_value;
|
||||
$statValue = round(array_sum($dayTotals) / count($dayTotals), 2);
|
||||
$dayOfWeekStats[] = $statValue;
|
||||
|
||||
$dayOfWeekAlt['values'][] = [
|
||||
'label' => $day_name,
|
||||
'label' => $dayName,
|
||||
'type' => 'string',
|
||||
'value' => $stat_value . ' ' . __('Listeners'),
|
||||
'value' => $statValue . ' ' . __('Listeners'),
|
||||
];
|
||||
}
|
||||
|
||||
$day_of_week_chart->data = $day_of_week_stats;
|
||||
$dayOfWeekChart->data = $dayOfWeekStats;
|
||||
|
||||
$stats['day_of_week'] = [
|
||||
'labels' => $days_of_week_names,
|
||||
'labels' => $daysOfWeekNames,
|
||||
'metrics' => [
|
||||
$day_of_week_chart,
|
||||
$dayOfWeekChart,
|
||||
],
|
||||
'alt' => [
|
||||
$dayOfWeekAlt,
|
||||
|
@ -144,7 +144,7 @@ final class ChartsAction extends AbstractReportAction
|
|||
AnalyticsIntervals::Hourly
|
||||
);
|
||||
|
||||
$totals_by_hour = [];
|
||||
$totalsByHour = [];
|
||||
|
||||
foreach ($hourlyStats as $stat) {
|
||||
/** @var CarbonImmutable $statTime */
|
||||
|
@ -152,40 +152,40 @@ final class ChartsAction extends AbstractReportAction
|
|||
$statTime = $statTime->shiftTimezone($stationTz);
|
||||
|
||||
$hour = $statTime->hour;
|
||||
$totals_by_hour[$hour][] = $stat['number_avg'];
|
||||
$totalsByHour[$hour][] = $stat['number_avg'];
|
||||
}
|
||||
|
||||
$hourly_labels = [];
|
||||
$hourly_chart = new stdClass();
|
||||
$hourly_chart->label = __('Listeners by Hour');
|
||||
$hourlyLabels = [];
|
||||
$hourlyChart = new stdClass();
|
||||
$hourlyChart->label = __('Listeners by Hour');
|
||||
|
||||
$hourly_rows = [];
|
||||
$hourlyRows = [];
|
||||
|
||||
$hourlyAlt = [
|
||||
'label' => $hourly_chart->label,
|
||||
'label' => $hourlyChart->label,
|
||||
'values' => [],
|
||||
];
|
||||
|
||||
for ($i = 0; $i < 24; $i++) {
|
||||
$hourly_labels[] = $i . ':00';
|
||||
$totals = $totals_by_hour[$i] ?? [0];
|
||||
$hourlyLabels[] = $i . ':00';
|
||||
$totals = $totalsByHour[$i] ?? [0];
|
||||
|
||||
$stat_value = round(array_sum($totals) / count($totals), 2);
|
||||
$hourly_rows[] = $stat_value;
|
||||
$statValue = round(array_sum($totals) / count($totals), 2);
|
||||
$hourlyRows[] = $statValue;
|
||||
|
||||
$hourlyAlt['values'][] = [
|
||||
'label' => $i . ':00',
|
||||
'type' => 'string',
|
||||
'value' => $stat_value . ' ' . __('Listeners'),
|
||||
'value' => $statValue . ' ' . __('Listeners'),
|
||||
];
|
||||
}
|
||||
|
||||
$hourly_chart->data = $hourly_rows;
|
||||
$hourlyChart->data = $hourlyRows;
|
||||
|
||||
$stats['hourly'] = [
|
||||
'labels' => $hourly_labels,
|
||||
'labels' => $hourlyLabels,
|
||||
'metrics' => [
|
||||
$hourly_chart,
|
||||
$hourlyChart,
|
||||
],
|
||||
'alt' => [
|
||||
$hourlyAlt,
|
||||
|
|
|
@ -65,7 +65,7 @@ final class SoundExchangeAction
|
|||
],
|
||||
];
|
||||
|
||||
$all_media = $this->em->createQuery(
|
||||
$allMedia = $this->em->createQuery(
|
||||
<<<'DQL'
|
||||
SELECT sm, spm, sp, smcf
|
||||
FROM App\Entity\StationMedia sm
|
||||
|
@ -79,9 +79,9 @@ final class SoundExchangeAction
|
|||
->setParameter('storageLocation', $station->getMediaStorageLocation())
|
||||
->getArrayResult();
|
||||
|
||||
$media_by_id = array_column($all_media, null, 'id');
|
||||
$mediaById = array_column($allMedia, null, 'id');
|
||||
|
||||
$history_rows = $this->em->createQuery(
|
||||
$historyRows = $this->em->createQuery(
|
||||
<<<'DQL'
|
||||
SELECT sh.song_id AS song_id, sh.text, sh.artist, sh.title, sh.media_id, COUNT(sh.id) AS plays,
|
||||
SUM(sh.unique_listeners) AS unique_listeners
|
||||
|
@ -97,16 +97,16 @@ final class SoundExchangeAction
|
|||
->getArrayResult();
|
||||
|
||||
// TODO: Fix this (not all song rows have a media_id)
|
||||
$history_rows_by_id = array_column($history_rows, null, 'media_id');
|
||||
$historyRowsById = array_column($historyRows, null, 'media_id');
|
||||
|
||||
// Remove any reference to the "Stream Offline" song.
|
||||
$offline_song_hash = Song::createOffline()->getSongId();
|
||||
unset($history_rows_by_id[$offline_song_hash]);
|
||||
$offlineSongHash = Song::createOffline()->getSongId();
|
||||
unset($historyRowsById[$offlineSongHash]);
|
||||
|
||||
// Assemble report items
|
||||
$station_name = $station->getName();
|
||||
$stationName = $station->getName();
|
||||
|
||||
$set_isrc_query = $this->em->createQuery(
|
||||
$setIsrcQuery = $this->em->createQuery(
|
||||
<<<'DQL'
|
||||
UPDATE App\Entity\StationMedia sm
|
||||
SET sm.isrc = :isrc
|
||||
|
@ -114,56 +114,56 @@ final class SoundExchangeAction
|
|||
DQL
|
||||
);
|
||||
|
||||
foreach ($history_rows_by_id as $song_id => $history_row) {
|
||||
$song_row = $media_by_id[$song_id] ?? $history_row;
|
||||
foreach ($historyRowsById as $songId => $historyRow) {
|
||||
$songRow = $mediaById[$songId] ?? $historyRow;
|
||||
|
||||
// Try to find the ISRC if it's not already listed.
|
||||
if ($fetchIsrc && empty($song_row['isrc'])) {
|
||||
$isrc = $this->findISRC($song_row);
|
||||
$song_row['isrc'] = $isrc;
|
||||
if ($fetchIsrc && empty($songRow['isrc'])) {
|
||||
$isrc = $this->findISRC($songRow);
|
||||
$songRow['isrc'] = $isrc;
|
||||
|
||||
if (null !== $isrc && isset($song_row['media_id'])) {
|
||||
$set_isrc_query->setParameter('isrc', $isrc)
|
||||
->setParameter('media_id', $song_row['media_id'])
|
||||
if (null !== $isrc && isset($songRow['media_id'])) {
|
||||
$setIsrcQuery->setParameter('isrc', $isrc)
|
||||
->setParameter('media_id', $songRow['media_id'])
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
|
||||
$export[] = [
|
||||
$station_name,
|
||||
$stationName,
|
||||
'A',
|
||||
$song_row['artist'] ?? '',
|
||||
$song_row['title'] ?? '',
|
||||
$song_row['isrc'] ?? '',
|
||||
$song_row['album'] ?? '',
|
||||
$songRow['artist'] ?? '',
|
||||
$songRow['title'] ?? '',
|
||||
$songRow['isrc'] ?? '',
|
||||
$songRow['album'] ?? '',
|
||||
'',
|
||||
$history_row['unique_listeners'],
|
||||
$historyRow['unique_listeners'],
|
||||
];
|
||||
}
|
||||
|
||||
// Assemble export into SoundExchange format
|
||||
$export_txt_raw = [];
|
||||
foreach ($export as $export_row) {
|
||||
foreach ($export_row as $i => $export_col) {
|
||||
if (!is_numeric($export_col)) {
|
||||
$export_row[$i] = '^' . str_replace(['^', '|'], ['', ''], strtoupper($export_col)) . '^';
|
||||
$exportTxtRaw = [];
|
||||
foreach ($export as $exportRow) {
|
||||
foreach ($exportRow as $i => $exportCol) {
|
||||
if (!is_numeric($exportCol)) {
|
||||
$exportRow[$i] = '^' . str_replace(['^', '|'], ['', ''], strtoupper($exportCol)) . '^';
|
||||
}
|
||||
}
|
||||
$export_txt_raw[] = implode('|', $export_row);
|
||||
$exportTxtRaw[] = implode('|', $exportRow);
|
||||
}
|
||||
$export_txt = implode("\n", $export_txt_raw);
|
||||
$exportTxt = implode("\n", $exportTxtRaw);
|
||||
|
||||
// Example: WABC01012009-31012009_A.txt
|
||||
$export_filename = strtoupper($station->getShortName())
|
||||
$exportFilename = strtoupper($station->getShortName())
|
||||
. $startDate->format('dmY') . '-'
|
||||
. $endDate->format('dmY') . '_A.txt';
|
||||
|
||||
return $response->renderStringAsFile($export_txt, 'text/plain', $export_filename);
|
||||
return $response->renderStringAsFile($exportTxt, 'text/plain', $exportFilename);
|
||||
}
|
||||
|
||||
private function findISRC(array $song_row): ?string
|
||||
private function findISRC(array $songRow): ?string
|
||||
{
|
||||
$song = Song::createFromArray($song_row);
|
||||
$song = Song::createFromArray($songRow);
|
||||
|
||||
try {
|
||||
foreach ($this->musicBrainz->findRecordingsForSong($song, 'isrcs') as $recording) {
|
||||
|
|
|
@ -32,10 +32,10 @@ final class ToggleAction
|
|||
$em->persist($record);
|
||||
$em->flush();
|
||||
|
||||
$flash_message = ($newValue)
|
||||
$flashMessage = ($newValue)
|
||||
? __('Web hook enabled.')
|
||||
: __('Web hook disabled.');
|
||||
|
||||
return $response->withJson(new Status(true, $flash_message));
|
||||
return $response->withJson(new Status(true, $flashMessage));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,62 +17,62 @@ trait HasLogViewer
|
|||
protected function streamLogToResponse(
|
||||
ServerRequest $request,
|
||||
Response $response,
|
||||
string $log_path,
|
||||
bool $tail_file = true,
|
||||
string $logPath,
|
||||
bool $tailFile = true,
|
||||
array $filteredTerms = []
|
||||
): ResponseInterface {
|
||||
clearstatcache();
|
||||
|
||||
if (!is_file($log_path)) {
|
||||
if (!is_file($logPath)) {
|
||||
throw new NotFoundException('Log file not found!');
|
||||
}
|
||||
|
||||
if (!$tail_file) {
|
||||
$log = file_get_contents($log_path) ?: '';
|
||||
$log_contents = $this->processLog(
|
||||
if (!$tailFile) {
|
||||
$log = file_get_contents($logPath) ?: '';
|
||||
$logContents = $this->processLog(
|
||||
rawLog: $log,
|
||||
filteredTerms: $filteredTerms
|
||||
);
|
||||
|
||||
return $response->withJson(
|
||||
[
|
||||
'contents' => $log_contents,
|
||||
'contents' => $logContents,
|
||||
'eof' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$params = $request->getQueryParams();
|
||||
$last_viewed_size = (int)($params['position'] ?? 0);
|
||||
$lastViewedSize = (int)($params['position'] ?? 0);
|
||||
|
||||
$log_size = filesize($log_path);
|
||||
if ($last_viewed_size > $log_size) {
|
||||
$last_viewed_size = $log_size;
|
||||
$logSize = filesize($logPath);
|
||||
if ($lastViewedSize > $logSize) {
|
||||
$lastViewedSize = $logSize;
|
||||
}
|
||||
|
||||
$log_visible_size = ($log_size - $last_viewed_size);
|
||||
$cut_first_line = false;
|
||||
$logVisibleSize = ($logSize - $lastViewedSize);
|
||||
$cutFirstLine = false;
|
||||
|
||||
if ($log_visible_size > self::$maximum_log_size) {
|
||||
$log_visible_size = self::$maximum_log_size;
|
||||
$cut_first_line = true;
|
||||
if ($logVisibleSize > self::$maximum_log_size) {
|
||||
$logVisibleSize = self::$maximum_log_size;
|
||||
$cutFirstLine = true;
|
||||
}
|
||||
|
||||
$log_contents = '';
|
||||
$logContents = '';
|
||||
|
||||
if ($log_visible_size > 0) {
|
||||
$fp = fopen($log_path, 'rb');
|
||||
if ($logVisibleSize > 0) {
|
||||
$fp = fopen($logPath, 'rb');
|
||||
if (false === $fp) {
|
||||
throw new RuntimeException(sprintf('Could not open file at path "%s".', $log_path));
|
||||
throw new RuntimeException(sprintf('Could not open file at path "%s".', $logPath));
|
||||
}
|
||||
|
||||
fseek($fp, -$log_visible_size, SEEK_END);
|
||||
$log_contents_raw = fread($fp, $log_visible_size) ?: '';
|
||||
fseek($fp, -$logVisibleSize, SEEK_END);
|
||||
$logContentsRaw = fread($fp, $logVisibleSize) ?: '';
|
||||
fclose($fp);
|
||||
|
||||
$log_contents = $this->processLog(
|
||||
rawLog: $log_contents_raw,
|
||||
cutFirstLine: $cut_first_line,
|
||||
$logContents = $this->processLog(
|
||||
rawLog: $logContentsRaw,
|
||||
cutFirstLine: $cutFirstLine,
|
||||
cutEmptyLastLine: true,
|
||||
filteredTerms: $filteredTerms
|
||||
);
|
||||
|
@ -80,8 +80,8 @@ trait HasLogViewer
|
|||
|
||||
return $response->withJson(
|
||||
[
|
||||
'contents' => $log_contents,
|
||||
'position' => $log_size,
|
||||
'contents' => $logContents,
|
||||
'position' => $logSize,
|
||||
'eof' => false,
|
||||
]
|
||||
);
|
||||
|
|
|
@ -35,13 +35,13 @@ final class LoginAction
|
|||
$settings = $this->readSettings();
|
||||
|
||||
if (!$settings->isSetupComplete()) {
|
||||
$num_users = (int)$this->em->createQuery(
|
||||
$numUsers = (int)$this->em->createQuery(
|
||||
<<<'DQL'
|
||||
SELECT COUNT(u.id) FROM App\Entity\User u
|
||||
DQL
|
||||
)->getSingleScalarResult();
|
||||
|
||||
if (0 === $num_users) {
|
||||
if (0 === $numUsers) {
|
||||
return $response->withRedirect($request->getRouter()->named('setup:index'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ final class PlaylistAction
|
|||
$station = $request->getStation();
|
||||
|
||||
$streams = [];
|
||||
$stream_urls = [];
|
||||
$streamUrls = [];
|
||||
|
||||
$fa = $this->adapters->getFrontendAdapter($station);
|
||||
if (null !== $fa) {
|
||||
|
@ -36,12 +36,12 @@ final class PlaylistAction
|
|||
continue;
|
||||
}
|
||||
|
||||
$stream_url = $fa->getUrlForMount($station, $mount);
|
||||
$streamUrl = $fa->getUrlForMount($station, $mount);
|
||||
|
||||
$stream_urls[] = $stream_url;
|
||||
$streamUrls[] = $streamUrl;
|
||||
$streams[] = [
|
||||
'name' => $station->getName() . ' - ' . $mount->getDisplayName(),
|
||||
'url' => $stream_url,
|
||||
'url' => $streamUrl,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -51,13 +51,13 @@ final class PlaylistAction
|
|||
continue;
|
||||
}
|
||||
|
||||
$stream_url = $this->adapters->getRemoteAdapter($remote)
|
||||
$streamUrl = $this->adapters->getRemoteAdapter($remote)
|
||||
->getPublicUrl($remote);
|
||||
|
||||
$stream_urls[] = $stream_url;
|
||||
$streamUrls[] = $streamUrl;
|
||||
$streams[] = [
|
||||
'name' => $station->getName() . ' - ' . $remote->getDisplayName(),
|
||||
'url' => $stream_url,
|
||||
'url' => $streamUrl,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -73,10 +73,10 @@ final class PlaylistAction
|
|||
];
|
||||
|
||||
if ($backendConfig->getHlsIsDefault()) {
|
||||
array_unshift($stream_urls, $streamUrl);
|
||||
array_unshift($streamUrls, $streamUrl);
|
||||
array_unshift($streams, $streamRow);
|
||||
} else {
|
||||
$stream_urls[] = $streamUrl;
|
||||
$streamUrls[] = $streamUrl;
|
||||
$streams[] = $streamRow;
|
||||
}
|
||||
}
|
||||
|
@ -86,9 +86,9 @@ final class PlaylistAction
|
|||
switch ($format) {
|
||||
// M3U Playlist Format
|
||||
case 'm3u':
|
||||
$m3u_file = implode("\n", $stream_urls);
|
||||
$m3uFile = implode("\n", $streamUrls);
|
||||
|
||||
$response->getBody()->write($m3u_file);
|
||||
$response->getBody()->write($m3uFile);
|
||||
return $response
|
||||
->withHeader('Content-Type', 'audio/x-mpegurl')
|
||||
->withHeader('Content-Disposition', 'attachment; filename=' . $station->getShortName() . '.m3u');
|
||||
|
|
|
@ -38,14 +38,14 @@ final class WebDjAction
|
|||
throw new StationUnsupportedException();
|
||||
}
|
||||
|
||||
$wss_url = (string)$backend->getWebStreamingUrl($station, $request->getRouter()->getBaseUrl());
|
||||
$wssUrl = (string)$backend->getWebStreamingUrl($station, $request->getRouter()->getBaseUrl());
|
||||
|
||||
return $request->getView()->renderToResponse(
|
||||
response: $response->withHeader('X-Frame-Options', '*'),
|
||||
templateName: 'frontend/public/webdj',
|
||||
templateArgs: [
|
||||
'station' => $station,
|
||||
'wss_url' => $wss_url,
|
||||
'wss_url' => $wssUrl,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
|
@ -45,8 +45,8 @@ final class SetupController
|
|||
ServerRequest $request,
|
||||
Response $response
|
||||
): ResponseInterface {
|
||||
$current_step = $this->getSetupStep($request);
|
||||
return $response->withRedirect($request->getRouter()->named('setup:' . $current_step));
|
||||
$currentStep = $this->getSetupStep($request);
|
||||
return $response->withRedirect($request->getRouter()->named('setup:' . $currentStep));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,9 +58,9 @@ final class SetupController
|
|||
Response $response
|
||||
): ResponseInterface {
|
||||
// Verify current step.
|
||||
$current_step = $this->getSetupStep($request);
|
||||
if ($current_step !== 'register' && $this->environment->isProduction()) {
|
||||
return $response->withRedirect($request->getRouter()->named('setup:' . $current_step));
|
||||
$currentStep = $this->getSetupStep($request);
|
||||
if ($currentStep !== 'register' && $this->environment->isProduction()) {
|
||||
return $response->withRedirect($request->getRouter()->named('setup:' . $currentStep));
|
||||
}
|
||||
|
||||
$csrf = $request->getCsrf();
|
||||
|
@ -128,9 +128,9 @@ final class SetupController
|
|||
Response $response
|
||||
): ResponseInterface {
|
||||
// Verify current step.
|
||||
$current_step = $this->getSetupStep($request);
|
||||
if ($current_step !== 'station' && $this->environment->isProduction()) {
|
||||
return $response->withRedirect($request->getRouter()->named('setup:' . $current_step));
|
||||
$currentStep = $this->getSetupStep($request);
|
||||
if ($currentStep !== 'station' && $this->environment->isProduction()) {
|
||||
return $response->withRedirect($request->getRouter()->named('setup:' . $currentStep));
|
||||
}
|
||||
|
||||
$router = $request->getRouter();
|
||||
|
@ -161,9 +161,9 @@ final class SetupController
|
|||
$router = $request->getRouter();
|
||||
|
||||
// Verify current step.
|
||||
$current_step = $this->getSetupStep($request);
|
||||
if ($current_step !== 'settings' && $this->environment->isProduction()) {
|
||||
return $response->withRedirect($router->named('setup:' . $current_step));
|
||||
$currentStep = $this->getSetupStep($request);
|
||||
if ($currentStep !== 'settings' && $this->environment->isProduction()) {
|
||||
return $response->withRedirect($router->named('setup:' . $currentStep));
|
||||
}
|
||||
|
||||
return $request->getView()->renderVuePage(
|
||||
|
@ -209,13 +209,13 @@ final class SetupController
|
|||
}
|
||||
|
||||
// Step 1: Register
|
||||
$num_users = (int)$this->em->createQuery(
|
||||
$numUsers = (int)$this->em->createQuery(
|
||||
<<<'DQL'
|
||||
SELECT COUNT(u.id) FROM App\Entity\User u
|
||||
DQL
|
||||
)->getSingleScalarResult();
|
||||
|
||||
if (0 === $num_users) {
|
||||
if (0 === $numUsers) {
|
||||
return 'register';
|
||||
}
|
||||
|
||||
|
@ -226,13 +226,13 @@ final class SetupController
|
|||
}
|
||||
|
||||
// Step 2: Set up Station
|
||||
$num_stations = (int)$this->em->createQuery(
|
||||
$numStations = (int)$this->em->createQuery(
|
||||
<<<'DQL'
|
||||
SELECT COUNT(s.id) FROM App\Entity\Station s
|
||||
DQL
|
||||
)->getSingleScalarResult();
|
||||
|
||||
if (0 === $num_stations) {
|
||||
if (0 === $numStations) {
|
||||
return 'station';
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ final class ProfileController
|
|||
}
|
||||
|
||||
// Statistics about backend playback.
|
||||
$num_songs = $this->em->createQuery(
|
||||
$numSongs = $this->em->createQuery(
|
||||
<<<'DQL'
|
||||
SELECT COUNT(sm.id)
|
||||
FROM App\Entity\StationMedia sm
|
||||
|
@ -51,7 +51,7 @@ final class ProfileController
|
|||
)->setParameter('station_id', $station->getId())
|
||||
->getSingleScalarResult();
|
||||
|
||||
$num_playlists = $this->em->createQuery(
|
||||
$numPlaylists = $this->em->createQuery(
|
||||
<<<'DQL'
|
||||
SELECT COUNT(sp.id)
|
||||
FROM App\Entity\StationPlaylist sp
|
||||
|
@ -195,8 +195,8 @@ final class ProfileController
|
|||
'frontendStopUri' => $router->fromHere('api:stations:frontend', ['do' => 'stop']),
|
||||
|
||||
// Backend
|
||||
'numSongs' => (int)$num_songs,
|
||||
'numPlaylists' => (int)$num_playlists,
|
||||
'numSongs' => (int)$numSongs,
|
||||
'numPlaylists' => (int)$numPlaylists,
|
||||
'manageMediaUri' => $router->fromHere('stations:files:index'),
|
||||
'managePlaylistsUri' => $router->fromHere('stations:playlists:index'),
|
||||
'backendRestartUri' => $router->fromHere('api:stations:backend', ['do' => 'restart']),
|
||||
|
@ -209,7 +209,7 @@ final class ProfileController
|
|||
public function editAction(
|
||||
ServerRequest $request,
|
||||
Response $response,
|
||||
string $station_id
|
||||
string $stationId
|
||||
): ResponseInterface {
|
||||
$router = $request->getRouter();
|
||||
|
||||
|
|
Loading…
Reference in a new issue