DeletedCalendarObject.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\CalDAV\Trashbin;
  8. use OCA\DAV\CalDAV\CalDavBackend;
  9. use OCA\DAV\CalDAV\IRestorable;
  10. use Sabre\CalDAV\ICalendarObject;
  11. use Sabre\DAV\Exception\Forbidden;
  12. use Sabre\DAVACL\ACLTrait;
  13. use Sabre\DAVACL\IACL;
  14. class DeletedCalendarObject implements IACL, ICalendarObject, IRestorable {
  15. use ACLTrait;
  16. public function __construct(
  17. private string $name,
  18. /** @var mixed[] */
  19. private array $objectData,
  20. private string $principalUri,
  21. private CalDavBackend $calDavBackend,
  22. ) {
  23. }
  24. public function delete() {
  25. $this->calDavBackend->deleteCalendarObject(
  26. $this->objectData['calendarid'],
  27. $this->objectData['uri'],
  28. CalDavBackend::CALENDAR_TYPE_CALENDAR,
  29. true
  30. );
  31. }
  32. public function getName() {
  33. return $this->name;
  34. }
  35. public function setName($name) {
  36. throw new Forbidden();
  37. }
  38. public function getLastModified() {
  39. return 0;
  40. }
  41. public function put($data) {
  42. throw new Forbidden();
  43. }
  44. public function get() {
  45. return $this->objectData['calendardata'];
  46. }
  47. public function getContentType() {
  48. $mime = 'text/calendar; charset=utf-8';
  49. if (isset($this->objectData['component']) && $this->objectData['component']) {
  50. $mime .= '; component=' . $this->objectData['component'];
  51. }
  52. return $mime;
  53. }
  54. public function getETag() {
  55. return $this->objectData['etag'];
  56. }
  57. public function getSize() {
  58. return (int)$this->objectData['size'];
  59. }
  60. public function restore(): void {
  61. $this->calDavBackend->restoreCalendarObject($this->objectData);
  62. }
  63. public function getDeletedAt(): ?int {
  64. return $this->objectData['deleted_at'] ? (int)$this->objectData['deleted_at'] : null;
  65. }
  66. public function getCalendarUri(): string {
  67. return $this->objectData['calendaruri'];
  68. }
  69. public function getACL(): array {
  70. return [
  71. [
  72. 'privilege' => '{DAV:}read', // For queries
  73. 'principal' => $this->getOwner(),
  74. 'protected' => true,
  75. ],
  76. [
  77. 'privilege' => '{DAV:}unbind', // For moving and deletion
  78. 'principal' => '{DAV:}owner',
  79. 'protected' => true,
  80. ],
  81. ];
  82. }
  83. public function getOwner() {
  84. return $this->principalUri;
  85. }
  86. }