1
0

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