IImportSource.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. public const PATH_USER = 'user.json';
  31. /**
  32. * Reads a file from the export
  33. *
  34. * @param string $path Full path to the file in the export archive.
  35. * @return string The full content of the file.
  36. * @throws UserMigrationException
  37. *
  38. * @since 24.0.0
  39. */
  40. public function getFileContents(string $path): string;
  41. /**
  42. * Reads a file from the export as a stream
  43. *
  44. * @param string $path Full path to the file in the export archive.
  45. * @return resource A stream resource to read from to get the file content.
  46. * @throws UserMigrationException
  47. *
  48. * @since 24.0.0
  49. */
  50. public function getFileAsStream(string $path);
  51. /**
  52. * List the files of a folder
  53. *
  54. * @param string $path Full path to the folder in the export archive.
  55. * @return array The list of files.
  56. * @throws UserMigrationException
  57. *
  58. * @since 24.0.0
  59. */
  60. public function getFolderListing(string $path): array;
  61. /**
  62. * Test if a path exists, which may be a file or a folder
  63. *
  64. * @throws UserMigrationException
  65. *
  66. * @since 24.0.0
  67. */
  68. public function pathExists(string $path): bool;
  69. /**
  70. * Copy files from the export to a Folder
  71. *
  72. * Folder $destination folder to copy into
  73. * string $sourcePath path in the export archive
  74. *
  75. * @throws UserMigrationException
  76. *
  77. * @since 24.0.0
  78. */
  79. public function copyToFolder(Folder $destination, string $sourcePath): void;
  80. /**
  81. * @return array<string,int> Migrators and their versions from the export archive.
  82. * @throws UserMigrationException
  83. *
  84. * @since 24.0.0
  85. */
  86. public function getMigratorVersions(): array;
  87. /**
  88. * @return ?int Version for this migrator from the export archive. Null means migrator missing.
  89. * @throws UserMigrationException
  90. * @param string $migrator Migrator id (as returned by IMigrator::getId)
  91. *
  92. * @since 24.0.0
  93. */
  94. public function getMigratorVersion(string $migrator): ?int;
  95. /**
  96. * Get original uid of the imported account
  97. *
  98. * @throws UserMigrationException
  99. *
  100. * @since 24.0.0
  101. */
  102. public function getOriginalUid(): string;
  103. /**
  104. * Called after import is complete
  105. *
  106. * @throws UserMigrationException
  107. *
  108. * @since 24.0.0
  109. */
  110. public function close(): void;
  111. }