From 07fd0cf7a0bce1aebae33bc2862e198a3d7697d5 Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Mon, 3 Jun 2024 13:25:01 +0200 Subject: [PATCH] Add command to set system vars --- src/Command/SystemVarsSetCommand.php | 64 ++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/Command/SystemVarsSetCommand.php diff --git a/src/Command/SystemVarsSetCommand.php b/src/Command/SystemVarsSetCommand.php new file mode 100644 index 0000000..b5c623e --- /dev/null +++ b/src/Command/SystemVarsSetCommand.php @@ -0,0 +1,64 @@ +addArgument('name', InputArgument::REQUIRED, 'The name of the SystemVar') + ->addArgument('value', InputArgument::REQUIRED, 'The value of the SystemVar'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + $name = $input->getArgument('name'); + + $systemVar = $this->systemVarRepository->findOneBy(['name' => $name]); + if (!$systemVar) { + $systemVar = new SystemVar; + } + + $systemVar->setName($name); + $systemVar->setValue($input->getArgument('value')); + + $errors = $this->validator->validate($systemVar); + if (count($errors) > 0) { + $io->error((string) $errors); + + return Command::FAILURE; + } + + $this->entityManager->persist($systemVar); + $this->entityManager->flush(); + + $io->table(['Name', 'Value'], [[$systemVar->getName(), $systemVar->getValue()]]); + + return Command::SUCCESS; + } +}