Esempio n. 1
0
 /**
  * {@inheritdoc}
  *
  * Set the block plugin id.
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     if (is_array($value)) {
         list($module, $delta) = $value;
         switch ($module) {
             case 'aggregator':
                 list($type, $id) = explode('-', $delta);
                 if ($type == 'category') {
                     // @TODO skip row.
                     // throw new MigrateSkipRowException();
                 }
                 $value = 'aggregator_feed_block';
                 break;
             case 'menu':
                 $value = "system_menu_block:{$delta}";
                 break;
             case 'block':
                 if ($this->blockContentStorage) {
                     $block_ids = $this->processPluginManager->createInstance('migration', array('migration' => 'd6_custom_block'), $this->migration)->transform($delta, $migrate_executable, $row, $destination_property);
                     $value = 'block_content:' . $this->blockContentStorage->load($block_ids[0])->uuid();
                 } else {
                     throw new MigrateSkipRowException();
                 }
                 break;
             default:
                 throw new MigrateSkipRowException();
         }
     }
     return $value;
 }
Esempio n. 2
0
 /**
  * Gets a cckfield plugin instance.
  *
  * @param string $field_type
  *   The field type (plugin ID).
  * @param \Drupal\migrate\Entity\MigrationInterface|NULL $migration
  *   The migration, if any.
  *
  * @return \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
  *   The cckfield plugin instance.
  */
 protected function getCckPlugin($field_type, MigrationInterface $migration = NULL)
 {
     if (empty($this->cckPluginCache[$field_type])) {
         $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, [], $migration);
     }
     return $this->cckPluginCache[$field_type];
 }
 /**
  * {@inheritdoc}
  *
  * A specific createInstance method is necessary to pass the migration on.
  */
 public function createInstance($plugin_id, array $configuration = array(), MigrationInterface $migration = NULL)
 {
     if (substr($plugin_id, 0, 7) == 'entity:' && !$this->entityManager->getDefinition(substr($plugin_id, 7), FALSE)) {
         $plugin_id = 'null';
     }
     return parent::createInstance($plugin_id, $configuration, $migration);
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function getProcess()
 {
     if (!$this->init) {
         $this->init = TRUE;
         $source_plugin = $this->migrationPluginManager->createInstance($this->pluginId)->getSourcePlugin();
         if ($source_plugin instanceof RequirementsInterface) {
             try {
                 $source_plugin->checkRequirements();
             } catch (RequirementsException $e) {
                 // Kill the rest of the method.
                 $source_plugin = [];
             }
         }
         foreach ($source_plugin as $row) {
             $field_type = $row->getSourceProperty('type');
             if (!isset($this->processedFieldTypes[$field_type]) && $this->cckPluginManager->hasDefinition($field_type)) {
                 $this->processedFieldTypes[$field_type] = TRUE;
                 // Allow the cckfield plugin to alter the migration as necessary so
                 // that it knows how to handle fields of this type.
                 if (!isset($this->cckPluginCache[$field_type])) {
                     $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, [], $this);
                 }
                 call_user_func([$this->cckPluginCache[$field_type], $this->pluginDefinition['cck_plugin_method']], $this);
             }
         }
     }
     return parent::getProcess();
 }
Esempio n. 5
0
 /**
  * Builds migration entities from templates.
  *
  * @param array $templates
  *   The parsed templates (each of which is an array parsed from YAML), keyed
  *   by ID.
  *
  * @return \Drupal\migrate\Entity\MigrationInterface[]
  *   The migration entities derived from the templates.
  */
 public function createMigrations(array $templates)
 {
     /** @var \Drupal\migrate\Entity\MigrationInterface[] $migrations */
     $migrations = [];
     foreach ($templates as $template_id => $template) {
         if (isset($template['builder'])) {
             $variants = $this->builderManager->createInstance($template['builder']['plugin'], $template['builder'])->buildMigrations($template);
         } else {
             $variants = array(Migration::create($template));
         }
         /** @var \Drupal\migrate\Entity\MigrationInterface[] $variants */
         foreach ($variants as $variant) {
             $variant->set('template', $template_id);
         }
         $migrations = array_merge($migrations, $variants);
     }
     return $migrations;
 }
 /**
  * {@inheritdoc}
  */
 public function createInstance($field_type, array $configuration = array(), MigrationInterface $migration = NULL)
 {
     $core = static::DEFAULT_CORE_VERSION;
     if (!empty($configuration['core'])) {
         $core = $configuration['core'];
     } elseif (!empty($migration->getPluginDefinition()['migration_tags'])) {
         foreach ($migration->getPluginDefinition()['migration_tags'] as $tag) {
             if ($tag == 'Drupal 7') {
                 $core = 7;
             }
         }
     }
     foreach ($this->getDefinitions() as $plugin_id => $definition) {
         if (in_array($core, $definition['core'])) {
             if (array_key_exists($field_type, $definition['type_map']) || $field_type === $plugin_id) {
                 return parent::createInstance($plugin_id, $configuration, $migration);
             }
         }
     }
     throw new PluginNotFoundException($field_type);
 }
Esempio n. 7
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;
         }
     }
 }
Esempio n. 8
0
 /**
  * {@inheritdoc}
  */
 public function getIdMap()
 {
     if (!isset($this->idMapPlugin)) {
         $configuration = $this->idMap;
         $plugin = isset($configuration['plugin']) ? $configuration['plugin'] : 'sql';
         $this->idMapPlugin = $this->idMapPluginManager->createInstance($plugin, $configuration, $this);
     }
     return $this->idMapPlugin;
 }
 /**
  * MigrateSourcePluginManager constructor.
  *
  * @param string $type
  *   The type of the plugin: row, source, process, destination, entity_field,
  *   id_map.
  * @param \Traversable $namespaces
  *   An object that implements \Traversable which contains the root paths
  *   keyed by the corresponding namespace to look for plugin implementations.
  * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
  *   Cache backend instance to use.
  * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
  *   The module handler to invoke the alter hook with.
  */
 public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler)
 {
     parent::__construct($type, $namespaces, $cache_backend, $module_handler, 'Drupal\\migrate\\Annotation\\MigrateSource');
 }
 /**
  * {@inheritdoc}
  */
 public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, $annotation = 'Drupal\\Component\\Annotation\\PluginID')
 {
     parent::__construct($type, $namespaces, $cache_backend, $module_handler, $annotation);
     $this->factory = new ContainerFactory($this, 'Drupal\\migrate_drupal\\Plugin\\MigrateLoadInterface');
 }