/**
  * Test node translation migrations with translation enabled.
  */
 public function testTranslations()
 {
     // With content_translation, there should be translation migrations for
     // each content type.
     $this->enableModules(['language', 'content_translation']);
     $migrations = $this->pluginManager->createInstances('d6_node_translation');
     $this->assertArrayHasKey('d6_node_translation:story', $migrations, "Node translation migrations exist after content_translation installed");
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $migration_ids = $input->getArgument('migration-ids');
     $exclude_ids = $input->getOption('exclude');
     $sourceBasepath = $input->getOption('source-base_path');
     $configuration['source']['constants']['source_base_path'] = rtrim($sourceBasepath, '/') . '/';
     // If migrations weren't provided finish execution
     if (empty($migration_ids)) {
         return;
     }
     if (!$this->migrateConnection) {
         $this->registerMigrateDB($input, $output);
         $this->migrateConnection = $this->getDBConnection($io, 'default', 'upgrade');
     }
     if (!($drupal_version = $this->getLegacyDrupalVersion($this->migrateConnection))) {
         $io->error($this->trans('commands.migrate.setup.migrations.questions.not-drupal'));
         return;
     }
     $version_tag = 'Drupal ' . $drupal_version;
     if (!in_array('all', $migration_ids)) {
         $migrations = $migration_ids;
     } else {
         $migrations = array_keys($this->getMigrations($version_tag));
     }
     if (!empty($exclude_ids)) {
         // Remove exclude migration from migration script
         $migrations = array_diff($migrations, $exclude_ids);
     }
     if (count($migrations) == 0) {
         $io->error($this->trans('commands.migrate.execute.messages.no-migrations'));
         return;
     }
     foreach ($migrations as $migration_id) {
         $io->info(sprintf($this->trans('commands.migrate.execute.messages.processing'), $migration_id));
         $migration_service = $this->pluginManagerMigration->createInstance($migration_id, $configuration);
         if ($migration_service) {
             $messages = new MigrateExecuteMessageCapture();
             $executable = new MigrateExecutable($migration_service, $messages);
             $migration_status = $executable->import();
             switch ($migration_status) {
                 case MigrationInterface::RESULT_COMPLETED:
                     $io->info(sprintf($this->trans('commands.migrate.execute.messages.imported'), $migration_id));
                     break;
                 case MigrationInterface::RESULT_INCOMPLETE:
                     $io->info(sprintf($this->trans('commands.migrate.execute.messages.importing-incomplete'), $migration_id));
                     break;
                 case MigrationInterface::RESULT_STOPPED:
                     $io->error(sprintf($this->trans('commands.migrate.execute.messages.import-stopped'), $migration_id));
                     break;
                 case MigrationInterface::RESULT_FAILED:
                     $io->error(sprintf($this->trans('commands.migrate.execute.messages.import-fail'), $migration_id));
                     break;
                 case MigrationInterface::RESULT_SKIPPED:
                     $io->error(sprintf($this->trans('commands.migrate.execute.messages.import-skipped'), $migration_id));
                     break;
                 case MigrationInterface::RESULT_DISABLED:
                     // Skip silently if disabled.
                     break;
             }
         } else {
             $io->error($this->trans('commands.migrate.execute.messages.fail-load'));
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     $migration_ids = $this->configuration['migration'];
     if (!is_array($migration_ids)) {
         $migration_ids = array($migration_ids);
     }
     $scalar = FALSE;
     if (!is_array($value)) {
         $scalar = TRUE;
         $value = array($value);
     }
     $this->skipOnEmpty($value);
     $self = FALSE;
     /** @var \Drupal\migrate\Plugin\MigrationInterface[] $migrations */
     $destination_ids = NULL;
     $source_id_values = array();
     $migrations = $this->migrationPluginManager->createInstances($migration_ids);
     foreach ($migrations as $migration_id => $migration) {
         if ($migration_id == $this->migration->id()) {
             $self = TRUE;
         }
         if (isset($this->configuration['source_ids'][$migration_id])) {
             $configuration = array('source' => $this->configuration['source_ids'][$migration_id]);
             $source_id_values[$migration_id] = $this->processPluginManager->createInstance('get', $configuration, $this->migration)->transform(NULL, $migrate_executable, $row, $destination_property);
         } else {
             $source_id_values[$migration_id] = $value;
         }
         // Break out of the loop as soon as a destination ID is found.
         if ($destination_ids = $migration->getIdMap()->lookupDestinationID($source_id_values[$migration_id])) {
             break;
         }
     }
     if (!$destination_ids && !empty($this->configuration['no_stub'])) {
         return NULL;
     }
     if (!$destination_ids && ($self || isset($this->configuration['stub_id']) || count($migrations) == 1)) {
         // If the lookup didn't succeed, figure out which migration will do the
         // stubbing.
         if ($self) {
             $migration = $this->migration;
         } elseif (isset($this->configuration['stub_id'])) {
             $migration = $migrations[$this->configuration['stub_id']];
         } else {
             $migration = reset($migrations);
         }
         $destination_plugin = $migration->getDestinationPlugin(TRUE);
         // Only keep the process necessary to produce the destination ID.
         $process = $migration->get('process');
         // We already have the source ID values but need to key them for the Row
         // constructor.
         $source_ids = $migration->getSourcePlugin()->getIds();
         $values = array();
         foreach (array_keys($source_ids) as $index => $source_id) {
             $values[$source_id] = $source_id_values[$migration->id()][$index];
         }
         $stub_row = new Row($values + $migration->get('source'), $source_ids, TRUE);
         // Do a normal migration with the stub row.
         $migrate_executable->processRow($stub_row, $process);
         $destination_ids = array();
         try {
             $destination_ids = $destination_plugin->import($stub_row);
         } catch (\Exception $e) {
             $migration->getIdMap()->saveMessage($stub_row->getSourceIdValues(), $e->getMessage());
         }
         if ($destination_ids) {
             $migration->getIdMap()->saveIdMapping($stub_row, $destination_ids, MigrateIdMapInterface::STATUS_NEEDS_UPDATE);
         }
     }
     if ($destination_ids) {
         if ($scalar) {
             if (count($destination_ids) == 1) {
                 return reset($destination_ids);
             }
         } else {
             return $destination_ids;
         }
     }
 }