Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate command easier for scripting #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions bundle/Command/MigrateEzImageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -255,12 +261,28 @@ 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);
}

} else {
$this->listFields();
$output->writeln('');

$contentType = $this->getContentType();
$ezimageFieldIdentifier = $this->getFieldIdentifier($contentType, 'source');
$remoteMediaFieldIdentifier = $this->getFieldIdentifier($contentType, 'destination');
}

$contentType = $this->getContentType();
$ezimageFieldIdentifier = $this->getFieldIdentifier($contentType, 'source');
$remoteMediaFieldIdentifier = $this->getFieldIdentifier($contentType, 'destination');
$overwrite = $this->getOverwrite();

$siteaccess = $this->getContainer()->get('ezpublish.siteaccess');
Expand Down