VersionCollection.php 1.6 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\IVersion;
  9. use OCA\Files_Versions\Versions\IVersionManager;
  10. use OCP\Files\File;
  11. use OCP\IUser;
  12. use Sabre\DAV\Exception\Forbidden;
  13. use Sabre\DAV\Exception\NotFound;
  14. use Sabre\DAV\ICollection;
  15. class VersionCollection implements ICollection {
  16. public function __construct(
  17. private File $file,
  18. private IUser $user,
  19. private IVersionManager $versionManager,
  20. ) {
  21. }
  22. public function createFile($name, $data = null) {
  23. throw new Forbidden();
  24. }
  25. public function createDirectory($name) {
  26. throw new Forbidden();
  27. }
  28. public function getChild($name) {
  29. /** @var VersionFile[] $versions */
  30. $versions = $this->getChildren();
  31. foreach ($versions as $version) {
  32. if ($version->getName() === $name) {
  33. return $version;
  34. }
  35. }
  36. throw new NotFound();
  37. }
  38. public function getChildren(): array {
  39. $versions = $this->versionManager->getVersionsForFile($this->user, $this->file);
  40. return array_map(function (IVersion $version) {
  41. return new VersionFile($version, $this->versionManager);
  42. }, $versions);
  43. }
  44. public function childExists($name): bool {
  45. try {
  46. $this->getChild($name);
  47. return true;
  48. } catch (NotFound $e) {
  49. return false;
  50. }
  51. }
  52. public function delete() {
  53. throw new Forbidden();
  54. }
  55. public function getName(): string {
  56. return (string)$this->file->getId();
  57. }
  58. public function setName($name) {
  59. throw new Forbidden();
  60. }
  61. public function getLastModified(): int {
  62. return 0;
  63. }
  64. }