2019-09-10 23:10:57 +00:00
|
|
|
<?php
|
2020-10-14 22:19:31 +00:00
|
|
|
|
2021-07-19 05:53:45 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-09-21 14:06:24 +00:00
|
|
|
namespace App\Console\Command\Settings;
|
2019-09-10 23:10:57 +00:00
|
|
|
|
2020-09-21 14:06:24 +00:00
|
|
|
use App\Console\Command\CommandAbstract;
|
2019-09-10 23:10:57 +00:00
|
|
|
use App\Entity;
|
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
|
|
2020-09-21 14:06:24 +00:00
|
|
|
class SetCommand extends CommandAbstract
|
2019-09-10 23:10:57 +00:00
|
|
|
{
|
|
|
|
public function __invoke(
|
|
|
|
SymfonyStyle $io,
|
2020-12-10 22:46:03 +00:00
|
|
|
Entity\Repository\SettingsRepository $settingsTableRepo,
|
2019-09-10 23:10:57 +00:00
|
|
|
string $settingKey,
|
|
|
|
string $settingValue
|
2020-10-14 22:19:31 +00:00
|
|
|
): int {
|
2019-09-10 23:10:57 +00:00
|
|
|
$io->title('AzuraCast Settings');
|
|
|
|
|
|
|
|
if (strtolower($settingValue) === 'null') {
|
2020-12-04 08:41:55 +00:00
|
|
|
$settingsTableRepo->writeSettings([$settingKey => null]);
|
2019-09-10 23:10:57 +00:00
|
|
|
|
|
|
|
$io->success(sprintf('Setting "%s" removed.', $settingKey));
|
2020-10-14 22:19:31 +00:00
|
|
|
return 0;
|
2019-09-10 23:10:57 +00:00
|
|
|
}
|
|
|
|
|
2021-04-23 22:12:47 +00:00
|
|
|
if (str_starts_with($settingValue, '{')) {
|
2020-07-08 07:03:50 +00:00
|
|
|
$settingValue = json_decode($settingValue, true, 512, JSON_THROW_ON_ERROR);
|
2019-09-10 23:10:57 +00:00
|
|
|
}
|
|
|
|
|
2020-12-04 08:41:55 +00:00
|
|
|
$settingsTableRepo->writeSettings([$settingKey => $settingValue]);
|
2019-09-10 23:10:57 +00:00
|
|
|
|
|
|
|
$io->success(sprintf('Setting "%s" updated.', $settingKey));
|
2020-10-14 22:19:31 +00:00
|
|
|
|
|
|
|
return 0;
|
2019-09-10 23:10:57 +00:00
|
|
|
}
|
|
|
|
}
|