VersionRoot.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Files_Versions\Sabre;
  8. use OCA\Files_Versions\Versions\IVersionManager;
  9. use OCP\Files\File;
  10. use OCP\Files\IRootFolder;
  11. use OCP\IUser;
  12. use Sabre\DAV\Exception\Forbidden;
  13. use Sabre\DAV\Exception\NotFound;
  14. use Sabre\DAV\ICollection;
  15. class VersionRoot implements ICollection {
  16. public function __construct(
  17. private IUser $user,
  18. private IRootFolder $rootFolder,
  19. private IVersionManager $versionManager,
  20. ) {
  21. }
  22. public function delete() {
  23. throw new Forbidden();
  24. }
  25. public function getName(): string {
  26. return 'versions';
  27. }
  28. public function setName($name) {
  29. throw new Forbidden();
  30. }
  31. public function createFile($name, $data = null) {
  32. throw new Forbidden();
  33. }
  34. public function createDirectory($name) {
  35. throw new Forbidden();
  36. }
  37. public function getChild($name) {
  38. $userFolder = $this->rootFolder->getUserFolder($this->user->getUID());
  39. $fileId = (int)$name;
  40. $node = $userFolder->getFirstNodeById($fileId);
  41. if (!$node) {
  42. throw new NotFound();
  43. }
  44. if (!$node instanceof File) {
  45. throw new NotFound();
  46. }
  47. return new VersionCollection($node, $this->user, $this->versionManager);
  48. }
  49. public function getChildren(): array {
  50. return [];
  51. }
  52. public function childExists($name): bool {
  53. try {
  54. $this->getChild($name);
  55. return true;
  56. } catch (NotFound $e) {
  57. return false;
  58. }
  59. }
  60. public function getLastModified(): int {
  61. return 0;
  62. }
  63. }