annotate core/modules/user/src/Plugin/migrate/ProfileValues.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\user\Plugin\migrate;
Chris@0 4
Chris@0 5 use Drupal\migrate\Exception\RequirementsException;
Chris@16 6 use Drupal\migrate\MigrateExecutable;
Chris@0 7 use Drupal\migrate\Plugin\Migration;
Chris@0 8
Chris@0 9 /**
Chris@0 10 * Plugin class for user migrations dealing with profile values.
Chris@0 11 */
Chris@0 12 class ProfileValues extends Migration {
Chris@0 13
Chris@0 14 /**
Chris@0 15 * Flag determining whether the process plugin has been initialized.
Chris@0 16 *
Chris@0 17 * @var bool
Chris@0 18 */
Chris@0 19 protected $init = FALSE;
Chris@0 20
Chris@0 21 /**
Chris@0 22 * {@inheritdoc}
Chris@0 23 */
Chris@0 24 public function getProcess() {
Chris@0 25 if (!$this->init) {
Chris@0 26 $this->init = TRUE;
Chris@0 27 $definition['source'] = [
Chris@0 28 'plugin' => 'profile_field',
Chris@0 29 'ignore_map' => TRUE,
Chris@0 30 ] + $this->source;
Chris@0 31 $definition['destination']['plugin'] = 'null';
Chris@14 32 $definition['idMap']['plugin'] = 'null';
Chris@0 33 try {
Chris@17 34 $this->checkRequirements();
Chris@0 35 $profile_field_migration = $this->migrationPluginManager->createStubMigration($definition);
Chris@16 36 $migrate_executable = new MigrateExecutable($profile_field_migration);
Chris@0 37 $source_plugin = $profile_field_migration->getSourcePlugin();
Chris@0 38 $source_plugin->checkRequirements();
Chris@0 39 foreach ($source_plugin as $row) {
Chris@0 40 $name = $row->getSourceProperty('name');
Chris@16 41 $fid = $row->getSourceProperty('fid');
Chris@16 42 // The user profile field name can be greater than 32 characters. Use
Chris@16 43 // the migrated profile field name in the process pipeline.
Chris@16 44 $configuration =
Chris@16 45 [
Chris@16 46 'migration' => 'user_profile_field',
Chris@16 47 'source_ids' => $fid,
Chris@17 48 'no_stub' => TRUE,
Chris@16 49 ];
Chris@16 50 $plugin = $this->processPluginManager->createInstance('migration_lookup', $configuration, $profile_field_migration);
Chris@16 51 $new_value = $plugin->transform($fid, $migrate_executable, $row, 'tmp');
Chris@16 52 if (isset($new_value[1])) {
Chris@16 53 // Set the destination to the migrated profile field name.
Chris@16 54 $this->process[$new_value[1]] = $name;
Chris@16 55 }
Chris@0 56 }
Chris@0 57 }
Chris@0 58 catch (RequirementsException $e) {
Chris@0 59 // The checkRequirements() call will fail when the profile module does
Chris@17 60 // not exist on the source site, or if the required migrations have not
Chris@17 61 // yet run.
Chris@0 62 }
Chris@0 63 }
Chris@0 64 return parent::getProcess();
Chris@0 65 }
Chris@0 66
Chris@0 67 }