ReinstallUserSource.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. protected function flattenRecord($record) {
  28. $row = new Row($record);
  29. $this->flattenRow($row);
  30. return $row->getSource();
  31. }
  32. protected function filter01($record) {
  33. return ($record['uid'] ?? 0) > 1;
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function fields() {
  39. $ret = [
  40. 'uid' => 'User ID',
  41. 'uuid' => 'UUID',
  42. 'langcode' => 'ISO 639 language code',
  43. 'preferred_langcode' => 'ISO 639 preferred language code',
  44. 'preferred_admin_langcode' => 'ISO 639 preferred administrative language code',
  45. 'name' => 'The user name (PK)',
  46. 'mail' => 'The current user e-mail address',
  47. 'timezone' => 'The user timezone',
  48. 'status' => 'The user status',
  49. 'access' => 'Latest access timestamp',
  50. 'login' => 'Latest login timestamp',
  51. 'init' => 'Initial user e-mail address',
  52. 'created' => 'User creation timestamp',
  53. 'changed' => 'Modification timestamp',
  54. 'default_langcode' => 'ISO 639 default language code',
  55. ];
  56. return $ret;
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. public function getIds() {
  62. $ids = [
  63. 'uid' => [
  64. 'type' => 'integer',
  65. ],
  66. ];
  67. return $ids;
  68. }
  69. }