IImportSource.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2022 Côme Chilliet <come.chilliet@nextcloud.com>
  5. *
  6. * @author Côme Chilliet <come.chilliet@nextcloud.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCP\UserMigration;
  25. use OCP\Files\Folder;
  26. /**
  27. * @since 24.0.0
  28. */
  29. interface IImportSource {
  30. /**
  31. * @since 24.0.0
  32. */
  33. public const PATH_USER = 'user.json';
  34. /**
  35. * Reads a file from the export
  36. *
  37. * @param string $path Full path to the file in the export archive.
  38. * @return string The full content of the file.
  39. * @throws UserMigrationException
  40. *
  41. * @since 24.0.0
  42. */
  43. public function getFileContents(string $path): string;
  44. /**
  45. * Reads a file from the export as a stream
  46. *
  47. * @param string $path Full path to the file in the export archive.
  48. * @return resource A stream resource to read from to get the file content.
  49. * @throws UserMigrationException
  50. *
  51. * @since 24.0.0
  52. */
  53. public function getFileAsStream(string $path);
  54. /**
  55. * List the files of a folder
  56. *
  57. * @param string $path Full path to the folder in the export archive.
  58. * @return array The list of files.
  59. * @throws UserMigrationException
  60. *
  61. * @since 24.0.0
  62. */
  63. public function getFolderListing(string $path): array;
  64. /**
  65. * Test if a path exists, which may be a file or a folder
  66. *
  67. * @throws UserMigrationException
  68. *
  69. * @since 24.0.0
  70. */
  71. public function pathExists(string $path): bool;
  72. /**
  73. * Copy files from the export to a Folder
  74. *
  75. * Folder $destination folder to copy into
  76. * string $sourcePath path in the export archive
  77. *
  78. * @throws UserMigrationException
  79. *
  80. * @since 24.0.0
  81. */
  82. public function copyToFolder(Folder $destination, string $sourcePath): void;
  83. /**
  84. * @return array<string,int> Migrators and their versions from the export archive.
  85. * @throws UserMigrationException
  86. *
  87. * @since 24.0.0
  88. */
  89. public function getMigratorVersions(): array;
  90. /**
  91. * @return ?int Version for this migrator from the export archive. Null means migrator missing.
  92. * @throws UserMigrationException
  93. * @param string $migrator Migrator id (as returned by IMigrator::getId)
  94. *
  95. * @since 24.0.0
  96. */
  97. public function getMigratorVersion(string $migrator): ?int;
  98. /**
  99. * Get original uid of the imported account
  100. *
  101. * @throws UserMigrationException
  102. *
  103. * @since 24.0.0
  104. */
  105. public function getOriginalUid(): string;
  106. /**
  107. * Called after import is complete
  108. *
  109. * @throws UserMigrationException
  110. *
  111. * @since 24.0.0
  112. */
  113. public function close(): void;
  114. }