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