From 028cd4af34f60d256572a2ef79e9560d6d38abb1 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 14 Sep 2021 18:24:11 +0300 Subject: [PATCH] feat(console): add EntriesUpdateCommand #543 --- .../Commands/Entries/EntriesUpdateCommand.php | 42 +++++++++++++++++++ .../Console/FlextypeConsoleApplication.php | 2 + 2 files changed, 44 insertions(+) create mode 100644 src/flextype/core/Console/Commands/Entries/EntriesUpdateCommand.php diff --git a/src/flextype/core/Console/Commands/Entries/EntriesUpdateCommand.php b/src/flextype/core/Console/Commands/Entries/EntriesUpdateCommand.php new file mode 100644 index 00000000..c34af1e9 --- /dev/null +++ b/src/flextype/core/Console/Commands/Entries/EntriesUpdateCommand.php @@ -0,0 +1,42 @@ +setName('entries:update'); + $this->setDescription('Update entry.'); + $this->addOption('id', null, InputOption::VALUE_REQUIRED, 'Unique identifier of the entry.'); + $this->addOption('data', null, InputOption::VALUE_OPTIONAL, 'Data to update for the entry.'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + + $data = serializers()->json()->decode($input->getOption('data') ?? []); + + if (entries()->update($input->getOption('id'), $data)) { + $io->success('Updated entry ' . $input->getOption('id')); + return Command::SUCCESS; + } else { + $io->error('Entry ' . $input->getOption('id') . ' wasn\'t updated.'); + return Command::FAILURE; + } + } +} \ No newline at end of file diff --git a/src/flextype/core/Console/FlextypeConsoleApplication.php b/src/flextype/core/Console/FlextypeConsoleApplication.php index 4cc61918..7b9abfde 100644 --- a/src/flextype/core/Console/FlextypeConsoleApplication.php +++ b/src/flextype/core/Console/FlextypeConsoleApplication.php @@ -11,6 +11,7 @@ namespace Flextype\Console; use Symfony\Component\Console\Application as ConsoleApplication; use Flextype\Console\Commands\Entries\EntriesCreateCommand; +use Flextype\Console\Commands\Entries\EntriesUpdateCommand; use Flextype\Console\Commands\Entries\EntriesDeleteCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -22,6 +23,7 @@ class FlextypeConsoleApplication extends ConsoleApplication // Add Console Commands console()->add(new EntriesCreateCommand()); console()->add(new EntriesDeleteCommand()); + console()->add(new EntriesUpdateCommand()); parent::run(); }