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; + } +}