ReinstallFileSource.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_files"
  10. * )
  11. */
  12. class ReinstallFileSource extends SimpleSource {
  13. /**
  14. * Constructor.
  15. */
  16. public function __construct(
  17. array $configuration,
  18. string $pluginId,
  19. array $pluginDefinition,
  20. MigrationInterface $migration = NULL
  21. ) {
  22. parent::__construct($configuration, $pluginId, $pluginDefinition, $migration);
  23. $this->records = array_map([$this, 'flattenRecord'], $this->initialParse($configuration));
  24. }
  25. protected function flattenRecord($record) {
  26. $row = new Row($record);
  27. $this->flattenRow($row);
  28. return $row->getSource();
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function fields() {
  34. $ret = [
  35. 'fid' => 'File ID',
  36. 'uid' => 'User ID',
  37. 'uuid' => 'UUID',
  38. 'langcode' => 'ISO 639 language code',
  39. 'filename' => 'File name without directory',
  40. 'uri' => 'File URI, like public://foo.png',
  41. 'filemime' => 'Mime type per https://www.iana.org/assignments/media-types/media-types.xhtml',
  42. 'filesize' => 'File size, in bytes',
  43. 'status' => 'File status (temporary or permanent)',
  44. 'created' => 'Creation timestamp',
  45. 'changed' => 'Modification timestamp',
  46. ];
  47. return $ret;
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function getIds() {
  53. $ids = [
  54. 'fid' => [
  55. 'type' => 'integer',
  56. ],
  57. ];
  58. return $ids;
  59. }
  60. }