1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-08 14:16:46 +02:00

feat(console): add EntriesMoveCommand #543

This commit is contained in:
Awilum
2021-09-14 18:27:42 +03:00
parent 781c52b351
commit 38dd8f2f44
2 changed files with 42 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
<?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 EntriesMoveCommand extends Command
{
protected function configure(): void
{
$this->setName('entries:move');
$this->setDescription('Move entry.');
$this->addOption('id', null, InputOption::VALUE_REQUIRED, 'Unique identifier of the entry.');
$this->addOption('newID', null, InputOption::VALUE_REQUIRED, 'New Unique identifier of the entry');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
if (entries()->move($input->getOption('id'), $input->getOption('newID'))) {
$io->success('Entry ' . $input->getOption('id') . ' moved to ' . $input->getOption('newID'));
return Command::SUCCESS;
} else {
$io->error('Entry ' . $input->getOption('id') . ' wasn\'t moved to ' . $input->getOption('newID'));
return Command::FAILURE;
}
}
}

View File

@@ -14,6 +14,7 @@ use Flextype\Console\Commands\Entries\EntriesCreateCommand;
use Flextype\Console\Commands\Entries\EntriesUpdateCommand;
use Flextype\Console\Commands\Entries\EntriesDeleteCommand;
use Flextype\Console\Commands\Entries\EntriesCopyCommand;
use Flextype\Console\Commands\Entries\EntriesMoveCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -26,6 +27,7 @@ class FlextypeConsoleApplication extends ConsoleApplication
console()->add(new EntriesDeleteCommand());
console()->add(new EntriesUpdateCommand());
console()->add(new EntriesCopyCommand());
console()->add(new EntriesMoveCommand());
parent::run();
}