Config Variables - Improve config variable system and initialize variables during setup.

This commit is contained in:
2024-12-12 15:38:28 +01:00
parent 28afb11ac4
commit dcd0b5f064
10 changed files with 175 additions and 58 deletions
@@ -3,7 +3,8 @@
namespace App\Controller\Admin;
use App\Entity\ConfigVariable;
use App\Enum\ConfigSectionType;
use App\Enum\ConfigVariableSectionEnum;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
@@ -21,10 +22,15 @@ class ConfigVariableCrudController extends AbstractCrudController
return $crud;
}
public function configureActions(Actions $actions): Actions
{
return $actions->disable("new", "delete");;
}
public function configureFields(string $pageName): iterable
{
yield ChoiceField::new ('section')->setChoices(ConfigSectionType::cases());
yield TextField::new ('key');
yield TextField::new ('value');
yield ChoiceField::new('section')->setChoices(ConfigVariableSectionEnum::cases());
yield TextField::new('key');
yield TextField::new('value');
}
}
+6 -5
View File
@@ -2,6 +2,7 @@
namespace App\Controller;
use App\Consts\ConfigVariableConsts;
use App\DTO\AppSetupConfig;
use App\DTO\ExampleDataConfig;
use App\Entity\ConfigVariable;
@@ -9,9 +10,9 @@ use App\Form\AppSetupFormType;
use App\Form\ExampleDataFormType;
use App\Repository\RoomCategoryRepository;
use App\Service\AppSetupService;
use App\Service\ConfigVariableService;
use App\Service\ExampleDataService;
use Doctrine\ORM\EntityManagerInterface;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
@@ -25,13 +26,13 @@ class AppSetupController extends AbstractController
LoggerInterface $logger,
AppSetupService $setupService,
Request $request,
EntityManagerInterface $entityManager
ConfigVariableService $configVars
): Response {
$configRepo = $entityManager->getRepository(ConfigVariable::class);
$setupStatus = $configRepo->findBy(["key" => "SETUP_STATUS"]);
$setupVar_key = ConfigVariableConsts::getKeyFromConstant(ConfigVariableConsts::CONFIG_INTERNAL_SETUP);
$setupStatus = $configVars->getVariable($setupVar_key);
if ($setupStatus != null && $setupStatus[0] != null && $setupStatus[0]->getValue() == 1) {
if ($setupStatus != null && $setupStatus->getValue()) {
$logger->warning("SomniaRooms was already setup");
return $this->GoToResultPage(