mirror of
https://github.com/flextype/flextype.git
synced 2025-08-07 05:36:54 +02:00
feat(console): add EntriesUpdateCommand #543
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (https://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
namespace Flextype\Console\Commands\Entries;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class EntriesUpdateCommand extends Command
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user