VersionRoot.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /** @var IUser */
  17. private $user;
  18. /** @var IRootFolder */
  19. private $rootFolder;
  20. /** @var IVersionManager */
  21. private $versionManager;
  22. public function __construct(IUser $user, IRootFolder $rootFolder, IVersionManager $versionManager) {
  23. $this->user = $user;
  24. $this->rootFolder = $rootFolder;
  25. $this->versionManager = $versionManager;
  26. }
  27. public function delete() {
  28. throw new Forbidden();
  29. }
  30. public function getName(): string {
  31. return 'versions';
  32. }
  33. public function setName($name) {
  34. throw new Forbidden();
  35. }
  36. public function createFile($name, $data = null) {
  37. throw new Forbidden();
  38. }
  39. public function createDirectory($name) {
  40. throw new Forbidden();
  41. }
  42. public function getChild($name) {
  43. $userFolder = $this->rootFolder->getUserFolder($this->user->getUID());
  44. $fileId = (int)$name;
  45. $node = $userFolder->getFirstNodeById($fileId);
  46. if (!$node) {
  47. throw new NotFound();
  48. }
  49. if (!$node instanceof File) {
  50. throw new NotFound();
  51. }
  52. return new VersionCollection($node, $this->user, $this->versionManager);
  53. }
  54. public function getChildren(): array {
  55. return [];
  56. }
  57. public function childExists($name): bool {
  58. try {
  59. $this->getChild($name);
  60. return true;
  61. } catch (NotFound $e) {
  62. return false;
  63. }
  64. }
  65. public function getLastModified(): int {
  66. return 0;
  67. }
  68. }