ReinstallUserSource.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace Drupal\reinstall\Plugin\migrate\source;
  3. use Drupal\migrate\Plugin\MigrationInterface;
  4. use Drupal\migrate\Row;
  5. /**
  6. * Source plugin for terms from a YAML file.
  7. *
  8. * @MigrateSource(
  9. * id = "reinstall_users"
  10. * )
  11. */
  12. class ReinstallUserSource extends SimpleSource {
  13. /**
  14. * Constructor.
  15. */
  16. public function __construct(
  17. array $configuration,
  18. string $pluginId,
  19. array $pluginDefinition,
  20. MigrationInterface $migration
  21. ) {
  22. parent::__construct($configuration, $pluginId, $pluginDefinition, $migration);
  23. $rawRecords = array_map([$this, 'flattenRecord'], $this->initialParse($configuration));
  24. $records = array_filter($rawRecords, [$this, 'filter01']);
  25. $this->records = $records;
  26. }
  27. /**
  28. * Flatten the field hierarchy. Not correct for all cases.
  29. *
  30. * @param array $record
  31. * The raw source values.
  32. *
  33. * @return array
  34. * The flattened values.
  35. *
  36. * @see \Drupal\reinstall\Plugin\migrate\process\TermParent
  37. */
  38. protected function flattenRecord(array $record) {
  39. $row = new Row($record);
  40. $this->flattenRow($row);
  41. return $row->getSource();
  42. }
  43. /**
  44. * Skip users 0 and 1 in imports, as they are core-provided.
  45. *
  46. * @param array $record
  47. * The description of a user entity.
  48. *
  49. * @return bool
  50. * Include it (1) or filter it (0).
  51. */
  52. protected function filter01(array $record) {
  53. return ($record['uid'] ?? 0) > 1;
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function fields() {
  59. $ret = [
  60. 'uid' => 'User ID',
  61. 'uuid' => 'UUID',
  62. 'langcode' => 'ISO 639 language code',
  63. 'preferred_langcode' => 'ISO 639 preferred language code',
  64. 'preferred_admin_langcode' => 'ISO 639 preferred administrative language code',
  65. 'name' => 'The user name (PK)',
  66. 'mail' => 'The current user e-mail address',
  67. 'timezone' => 'The user timezone',
  68. 'status' => 'The user status',
  69. 'access' => 'Latest access timestamp',
  70. 'login' => 'Latest login timestamp',
  71. 'init' => 'Initial user e-mail address',
  72. 'created' => 'User creation timestamp',
  73. 'changed' => 'Modification timestamp',
  74. 'default_langcode' => 'ISO 639 default language code',
  75. ];
  76. return $ret;
  77. }
  78. /**
  79. * {@inheritdoc}
  80. */
  81. public function getIds() {
  82. $ids = [
  83. 'uid' => [
  84. 'type' => 'integer',
  85. ],
  86. ];
  87. return $ids;
  88. }
  89. }