1
0

VersionRoot.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  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 OCA\Files_Versions\Sabre;
  25. use OCA\Files_Versions\Versions\IVersionManager;
  26. use OCP\Files\File;
  27. use OCP\Files\IRootFolder;
  28. use OCP\IUser;
  29. use Sabre\DAV\Exception\Forbidden;
  30. use Sabre\DAV\Exception\NotFound;
  31. use Sabre\DAV\ICollection;
  32. class VersionRoot implements ICollection {
  33. /** @var IUser */
  34. private $user;
  35. /** @var IRootFolder */
  36. private $rootFolder;
  37. /** @var IVersionManager */
  38. private $versionManager;
  39. public function __construct(IUser $user, IRootFolder $rootFolder, IVersionManager $versionManager) {
  40. $this->user = $user;
  41. $this->rootFolder = $rootFolder;
  42. $this->versionManager = $versionManager;
  43. }
  44. public function delete() {
  45. throw new Forbidden();
  46. }
  47. public function getName(): string {
  48. return 'versions';
  49. }
  50. public function setName($name) {
  51. throw new Forbidden();
  52. }
  53. public function createFile($name, $data = null) {
  54. throw new Forbidden();
  55. }
  56. public function createDirectory($name) {
  57. throw new Forbidden();
  58. }
  59. public function getChild($name) {
  60. $userFolder = $this->rootFolder->getUserFolder($this->user->getUID());
  61. $fileId = (int)$name;
  62. $nodes = $userFolder->getById($fileId);
  63. if ($nodes === []) {
  64. throw new NotFound();
  65. }
  66. $node = array_pop($nodes);
  67. if (!$node instanceof File) {
  68. throw new NotFound();
  69. }
  70. return new VersionCollection($userFolder, $node, $this->user, $this->versionManager);
  71. }
  72. public function getChildren(): array {
  73. return [];
  74. }
  75. public function childExists($name): bool {
  76. try {
  77. $this->getChild($name);
  78. return true;
  79. } catch (NotFound $e) {
  80. return false;
  81. }
  82. }
  83. public function getLastModified(): int {
  84. return 0;
  85. }
  86. }