UserPreImport.php 965 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace Drupal\reinstall\EventSubscriber;
  3. use Drupal\reinstall\ReinstallEvents;
  4. use Drupal\reinstall\SourceEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class UserPreImport implements EventSubscriberInterface {
  7. public static function getSubscribedEvents() {
  8. return [
  9. ReinstallEvents::POST_SOURCE_PARSE => 'onPreImport',
  10. ];
  11. }
  12. public function onPreImport(SourceEvent $event) {
  13. $source = $event->source;
  14. if ($source->getConfiguration()['type'] !== 'user') {
  15. return;
  16. }
  17. $event->source->records = array_filter($event->source->records, [$this, 'filter01']);
  18. return;
  19. }
  20. /**
  21. * Skip users 0 and 1 in imports, as they are core-provided.
  22. *
  23. * @param array $record
  24. * The description of a user entity.
  25. *
  26. * @return bool
  27. * Include it (1) or filter it (0).
  28. */
  29. public function filter01(array $record) {
  30. $ret = ($record['uid'] ?? 0) > 1;
  31. return $ret;
  32. }
  33. }