ReinstallFileSource.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. /**
  26. * Flatten the field hierarchy. Not correct for all cases.
  27. *
  28. * @param array $record
  29. * The raw source values.
  30. *
  31. * @return array
  32. * The flattened values.
  33. *
  34. * @see \Drupal\reinstall\Plugin\migrate\process\TermParent
  35. */
  36. protected function flattenRecord(array $record) {
  37. $row = new Row($record);
  38. $this->flattenRow($row);
  39. return $row->getSource();
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function fields() {
  45. $ret = [
  46. 'fid' => 'File ID',
  47. 'uid' => 'User ID',
  48. 'uuid' => 'UUID',
  49. 'langcode' => 'ISO 639 language code',
  50. 'filename' => 'File name without directory',
  51. 'uri' => 'File URI, like public://foo.png',
  52. 'filemime' => 'Mime type per https://www.iana.org/assignments/media-types/media-types.xhtml',
  53. 'filesize' => 'File size, in bytes',
  54. 'status' => 'File status (temporary or permanent)',
  55. 'created' => 'Creation timestamp',
  56. 'changed' => 'Modification timestamp',
  57. ];
  58. return $ret;
  59. }
  60. /**
  61. * {@inheritdoc}
  62. */
  63. public function getIds() {
  64. $ids = [
  65. 'fid' => [
  66. 'type' => 'integer',
  67. ],
  68. ];
  69. return $ids;
  70. }
  71. }