1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-07 21:56:33 +02:00

feat(console): add EntriesCopyCommand #543

This commit is contained in:
Awilum
2021-09-14 18:24:46 +03:00
parent 028cd4af34
commit f1b31360d1
2 changed files with 44 additions and 0 deletions

View File

@@ -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 EntriesCopyCommand extends Command
{
protected function configure(): void
{
$this->setName('entries:copy');
$this->setDescription('Copy 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);
$data = serializers()->json()->decode($input->getOption('data') ?? []);
if (entries()->copy($input->getOption('id'), $input->getOption('newID'))) {
$io->success('Entry ' . $input->getOption('id') . ' coppied to ' . $input->getOption('newID'));
return Command::SUCCESS;
} else {
$io->error('Entry ' . $input->getOption('id') . ' wasn\'t coppied to ' . $input->getOption('newID'));
return Command::FAILURE;
}
}
}

View File

@@ -13,6 +13,7 @@ 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 Flextype\Console\Commands\Entries\EntriesCopyCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -24,6 +25,7 @@ class FlextypeConsoleApplication extends ConsoleApplication
console()->add(new EntriesCreateCommand());
console()->add(new EntriesDeleteCommand());
console()->add(new EntriesUpdateCommand());
console()->add(new EntriesCopyCommand());
parent::run();
}