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@0
|
6 use Drupal\migrate_drupal\Plugin\migrate\FieldMigration;
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Plugin class for Drupal 7 user migrations dealing with fields and profiles.
|
Chris@0
|
10 */
|
Chris@0
|
11 class User extends FieldMigration {
|
Chris@0
|
12
|
Chris@0
|
13 /**
|
Chris@0
|
14 * {@inheritdoc}
|
Chris@0
|
15 */
|
Chris@0
|
16 public function getProcess() {
|
Chris@0
|
17 if (!$this->init) {
|
Chris@0
|
18 $this->init = TRUE;
|
Chris@0
|
19 $definition['source'] = [
|
Chris@0
|
20 'entity_type' => 'user',
|
Chris@0
|
21 'ignore_map' => TRUE,
|
Chris@0
|
22 ] + $this->source;
|
Chris@0
|
23 $definition['destination']['plugin'] = 'null';
|
Chris@0
|
24 $definition['idMap']['plugin'] = 'null';
|
Chris@0
|
25 if (\Drupal::moduleHandler()->moduleExists('field')) {
|
Chris@0
|
26 $definition['source']['plugin'] = 'd7_field_instance';
|
Chris@0
|
27 $field_migration = $this->migrationPluginManager->createStubMigration($definition);
|
Chris@0
|
28 foreach ($field_migration->getSourcePlugin() as $row) {
|
Chris@0
|
29 $field_name = $row->getSourceProperty('field_name');
|
Chris@0
|
30 $field_type = $row->getSourceProperty('type');
|
Chris@0
|
31 if (empty($field_type)) {
|
Chris@0
|
32 continue;
|
Chris@0
|
33 }
|
Chris@0
|
34 if ($this->fieldPluginManager->hasDefinition($field_type)) {
|
Chris@0
|
35 if (!isset($this->fieldPluginCache[$field_type])) {
|
Chris@0
|
36 $this->fieldPluginCache[$field_type] = $this->fieldPluginManager->createInstance($field_type, [], $this);
|
Chris@0
|
37 }
|
Chris@0
|
38 $info = $row->getSource();
|
Chris@0
|
39 $this->fieldPluginCache[$field_type]
|
Chris@4
|
40 ->defineValueProcessPipeline($this, $field_name, $info);
|
Chris@0
|
41 }
|
Chris@0
|
42 else {
|
Chris@0
|
43 if ($this->cckPluginManager->hasDefinition($field_type)) {
|
Chris@0
|
44 if (!isset($this->cckPluginCache[$field_type])) {
|
Chris@0
|
45 $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, [], $this);
|
Chris@0
|
46 }
|
Chris@0
|
47 $info = $row->getSource();
|
Chris@0
|
48 $this->cckPluginCache[$field_type]
|
Chris@0
|
49 ->processCckFieldValues($this, $field_name, $info);
|
Chris@0
|
50 }
|
Chris@0
|
51 else {
|
Chris@0
|
52 $this->process[$field_name] = $field_name;
|
Chris@0
|
53 }
|
Chris@0
|
54 }
|
Chris@0
|
55 }
|
Chris@0
|
56 }
|
Chris@0
|
57 try {
|
Chris@0
|
58 $definition['source']['plugin'] = 'profile_field';
|
Chris@0
|
59 $profile_migration = $this->migrationPluginManager->createStubMigration($definition);
|
Chris@0
|
60 // Ensure that Profile is enabled in the source DB.
|
Chris@0
|
61 $profile_migration->checkRequirements();
|
Chris@0
|
62 foreach ($profile_migration->getSourcePlugin() as $row) {
|
Chris@0
|
63 $name = $row->getSourceProperty('name');
|
Chris@0
|
64 $this->process[$name] = $name;
|
Chris@0
|
65 }
|
Chris@0
|
66 }
|
Chris@0
|
67 catch (RequirementsException $e) {
|
Chris@0
|
68 // The checkRequirements() call will fail when the profile module does
|
Chris@0
|
69 // not exist on the source site.
|
Chris@0
|
70 }
|
Chris@0
|
71 }
|
Chris@0
|
72 return parent::getProcess();
|
Chris@0
|
73 }
|
Chris@0
|
74
|
Chris@0
|
75 }
|