DeletedCalendarObject.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. /** @var string */
  17. private $name;
  18. /** @var mixed[] */
  19. private $objectData;
  20. /** @var string */
  21. private $principalUri;
  22. /** @var CalDavBackend */
  23. private $calDavBackend;
  24. public function __construct(string $name,
  25. array $objectData,
  26. string $principalUri,
  27. CalDavBackend $calDavBackend) {
  28. $this->name = $name;
  29. $this->objectData = $objectData;
  30. $this->calDavBackend = $calDavBackend;
  31. $this->principalUri = $principalUri;
  32. }
  33. public function delete() {
  34. $this->calDavBackend->deleteCalendarObject(
  35. $this->objectData['calendarid'],
  36. $this->objectData['uri'],
  37. CalDavBackend::CALENDAR_TYPE_CALENDAR,
  38. true
  39. );
  40. }
  41. public function getName() {
  42. return $this->name;
  43. }
  44. public function setName($name) {
  45. throw new Forbidden();
  46. }
  47. public function getLastModified() {
  48. return 0;
  49. }
  50. public function put($data) {
  51. throw new Forbidden();
  52. }
  53. public function get() {
  54. return $this->objectData['calendardata'];
  55. }
  56. public function getContentType() {
  57. $mime = 'text/calendar; charset=utf-8';
  58. if (isset($this->objectData['component']) && $this->objectData['component']) {
  59. $mime .= '; component='.$this->objectData['component'];
  60. }
  61. return $mime;
  62. }
  63. public function getETag() {
  64. return $this->objectData['etag'];
  65. }
  66. public function getSize() {
  67. return (int) $this->objectData['size'];
  68. }
  69. public function restore(): void {
  70. $this->calDavBackend->restoreCalendarObject($this->objectData);
  71. }
  72. public function getDeletedAt(): ?int {
  73. return $this->objectData['deleted_at'] ? (int) $this->objectData['deleted_at'] : null;
  74. }
  75. public function getCalendarUri(): string {
  76. return $this->objectData['calendaruri'];
  77. }
  78. public function getACL(): array {
  79. return [
  80. [
  81. 'privilege' => '{DAV:}read', // For queries
  82. 'principal' => $this->getOwner(),
  83. 'protected' => true,
  84. ],
  85. [
  86. 'privilege' => '{DAV:}unbind', // For moving and deletion
  87. 'principal' => '{DAV:}owner',
  88. 'protected' => true,
  89. ],
  90. ];
  91. }
  92. public function getOwner() {
  93. return $this->principalUri;
  94. }
  95. }