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@16
|
7 use Drupal\migrate\MigrateSkipRowException;
|
Chris@0
|
8 use Drupal\migrate\Plugin\Migration;
|
Chris@0
|
9
|
Chris@0
|
10 /**
|
Chris@0
|
11 * Plugin class for user migrations dealing with profile values.
|
Chris@0
|
12 */
|
Chris@0
|
13 class ProfileValues extends Migration {
|
Chris@0
|
14
|
Chris@0
|
15 /**
|
Chris@0
|
16 * Flag determining whether the process plugin has been initialized.
|
Chris@0
|
17 *
|
Chris@0
|
18 * @var bool
|
Chris@0
|
19 */
|
Chris@0
|
20 protected $init = FALSE;
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@0
|
23 * {@inheritdoc}
|
Chris@0
|
24 */
|
Chris@0
|
25 public function getProcess() {
|
Chris@0
|
26 if (!$this->init) {
|
Chris@0
|
27 $this->init = TRUE;
|
Chris@0
|
28 $definition['source'] = [
|
Chris@0
|
29 'plugin' => 'profile_field',
|
Chris@0
|
30 'ignore_map' => TRUE,
|
Chris@0
|
31 ] + $this->source;
|
Chris@0
|
32 $definition['destination']['plugin'] = 'null';
|
Chris@14
|
33 $definition['idMap']['plugin'] = 'null';
|
Chris@0
|
34 try {
|
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@16
|
48 ];
|
Chris@16
|
49 $plugin = $this->processPluginManager->createInstance('migration_lookup', $configuration, $profile_field_migration);
|
Chris@16
|
50 $new_value = $plugin->transform($fid, $migrate_executable, $row, 'tmp');
|
Chris@16
|
51 if (isset($new_value[1])) {
|
Chris@16
|
52 // Set the destination to the migrated profile field name.
|
Chris@16
|
53 $this->process[$new_value[1]] = $name;
|
Chris@16
|
54 }
|
Chris@16
|
55 else {
|
Chris@16
|
56 throw new MigrateSkipRowException("Can't migrate source field $name.");
|
Chris@16
|
57 }
|
Chris@0
|
58 }
|
Chris@0
|
59 }
|
Chris@0
|
60 catch (RequirementsException $e) {
|
Chris@0
|
61 // The checkRequirements() call will fail when the profile module does
|
Chris@0
|
62 // not exist on the source site.
|
Chris@0
|
63 }
|
Chris@0
|
64 }
|
Chris@0
|
65 return parent::getProcess();
|
Chris@0
|
66 }
|
Chris@0
|
67
|
Chris@0
|
68 }
|