From 71ed1742db01d5a58930969ed88f6c44b756e508 Mon Sep 17 00:00:00 2001 From: Ivo Lukac Date: Sat, 9 Nov 2019 19:19:40 +0100 Subject: [PATCH 1/2] added additional argument to migrate command so non-interactive usage is possible --- bundle/Command/MigrateEzImageCommand.php | 34 +++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/bundle/Command/MigrateEzImageCommand.php b/bundle/Command/MigrateEzImageCommand.php index d2c3dbf9..75d1bd3d 100644 --- a/bundle/Command/MigrateEzImageCommand.php +++ b/bundle/Command/MigrateEzImageCommand.php @@ -13,6 +13,7 @@ use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\Question; @@ -57,6 +58,11 @@ protected function configure() $this ->setName('netgen:ngremotemedia:migrate:ezimage') ->setDescription('This command will migrate ezimage field to ngremotemedia field.') + ->addArgument( + 'migrate-field', + InputArgument::IS_ARRAY, + "Migrate one field: content type identifier, image field type identifier, remote media type identifier" + ) ->addOption( 'dry-run', 'd', @@ -255,13 +261,29 @@ protected function execute(InputInterface $input, OutputInterface $output) $dryRun = $input->getOption('dry-run'); $continueOnError = $input->getOption('continue-on-error'); - $this->listFields(); - $output->writeln(''); + $migrateField = $input->getArgument('migrate-field'); + if (count($migrateField) == 3) { + $contentType = $this->contentTypeService->loadContentTypeByIdentifier($migrateField[0]); + + $ezimageFieldIdentifier = $migrateField[1]; + if (!$contentType->getFieldDefinition($ezimageFieldIdentifier)) { + throw new \InvalidArgumentException('Could not find the field with the identifier:'. $ezimageFieldIdentifier); + } + $remoteMediaFieldIdentifier = $migrateField[2]; + if (!$contentType->getFieldDefinition($remoteMediaFieldIdentifier)) { + throw new \InvalidArgumentException('Could not find the field with the identifier:'. $remoteMediaFieldIdentifier); + } + $overwrite = true; + + } else { + $this->listFields(); + $output->writeln(''); - $contentType = $this->getContentType(); - $ezimageFieldIdentifier = $this->getFieldIdentifier($contentType, 'source'); - $remoteMediaFieldIdentifier = $this->getFieldIdentifier($contentType, 'destination'); - $overwrite = $this->getOverwrite(); + $contentType = $this->getContentType(); + $ezimageFieldIdentifier = $this->getFieldIdentifier($contentType, 'source'); + $remoteMediaFieldIdentifier = $this->getFieldIdentifier($contentType, 'destination'); + $overwrite = $this->getOverwrite(); + } $siteaccess = $this->getContainer()->get('ezpublish.siteaccess'); $updated = 0; From 113e95dd3fd9dd614dd4491d113720655bf02c69 Mon Sep 17 00:00:00 2001 From: Ivo Lukac Date: Mon, 11 Nov 2019 09:56:21 +0100 Subject: [PATCH 2/2] returning to interactive overwrite question --- bundle/Command/MigrateEzImageCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundle/Command/MigrateEzImageCommand.php b/bundle/Command/MigrateEzImageCommand.php index 75d1bd3d..33795d53 100644 --- a/bundle/Command/MigrateEzImageCommand.php +++ b/bundle/Command/MigrateEzImageCommand.php @@ -273,7 +273,6 @@ protected function execute(InputInterface $input, OutputInterface $output) if (!$contentType->getFieldDefinition($remoteMediaFieldIdentifier)) { throw new \InvalidArgumentException('Could not find the field with the identifier:'. $remoteMediaFieldIdentifier); } - $overwrite = true; } else { $this->listFields(); @@ -282,9 +281,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $contentType = $this->getContentType(); $ezimageFieldIdentifier = $this->getFieldIdentifier($contentType, 'source'); $remoteMediaFieldIdentifier = $this->getFieldIdentifier($contentType, 'destination'); - $overwrite = $this->getOverwrite(); } + $overwrite = $this->getOverwrite(); + $siteaccess = $this->getContainer()->get('ezpublish.siteaccess'); $updated = 0;