diff --git a/src/flextype/core/Console/Commands/Entries/EntriesCopyCommand.php b/src/flextype/core/Console/Commands/Entries/EntriesCopyCommand.php new file mode 100644 index 00000000..33bd2b7a --- /dev/null +++ b/src/flextype/core/Console/Commands/Entries/EntriesCopyCommand.php @@ -0,0 +1,42 @@ +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; + } + } +} \ No newline at end of file diff --git a/src/flextype/core/Console/FlextypeConsoleApplication.php b/src/flextype/core/Console/FlextypeConsoleApplication.php index 7b9abfde..773f426e 100644 --- a/src/flextype/core/Console/FlextypeConsoleApplication.php +++ b/src/flextype/core/Console/FlextypeConsoleApplication.php @@ -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(); }