summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/CalDAV/Calendar.php
diff options
context:
space:
mode:
authorAnna Larch <anna@nextcloud.com>2021-12-06 20:01:22 +0100
committerAnna Larch <anna@nextcloud.com>2022-03-16 12:48:50 +0100
commit0745fc50126e92406ec95265ef1ff5d4b5575d3e (patch)
tree452e44b917c0d242669ee93d58fc84d5210802e5 /apps/dav/lib/CalDAV/Calendar.php
parenta626307da8e9a4e5124da1c35429892f745b2de9 (diff)
downloadnextcloud-server-0745fc50126e92406ec95265ef1ff5d4b5575d3e.tar.gz
nextcloud-server-0745fc50126e92406ec95265ef1ff5d4b5575d3e.zip
Move calendar objects between calendars instead of deleting and recreating them
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'apps/dav/lib/CalDAV/Calendar.php')
-rw-r--r--apps/dav/lib/CalDAV/Calendar.php31
1 files changed, 29 insertions, 2 deletions
diff --git a/apps/dav/lib/CalDAV/Calendar.php b/apps/dav/lib/CalDAV/Calendar.php
index fa29fc8d588..75c815c3b0a 100644
--- a/apps/dav/lib/CalDAV/Calendar.php
+++ b/apps/dav/lib/CalDAV/Calendar.php
@@ -33,11 +33,15 @@ use DateTimeInterface;
use OCA\DAV\CalDAV\Trashbin\Plugin as TrashbinPlugin;
use OCA\DAV\DAV\Sharing\IShareable;
use OCA\DAV\Exception\UnsupportedLimitOnInitialSyncException;
+use OCP\DB\Exception;
use OCP\IConfig;
use OCP\IL10N;
+use Psr\Log\LoggerInterface;
use Sabre\CalDAV\Backend\BackendInterface;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
+use Sabre\DAV\IMoveTarget;
+use Sabre\DAV\INode;
use Sabre\DAV\PropPatch;
/**
@@ -46,7 +50,7 @@ use Sabre\DAV\PropPatch;
* @package OCA\DAV\CalDAV
* @property CalDavBackend $caldavBackend
*/
-class Calendar extends \Sabre\CalDAV\Calendar implements IRestorable, IShareable {
+class Calendar extends \Sabre\CalDAV\Calendar implements IRestorable, IShareable, IMoveTarget {
/** @var IConfig */
private $config;
@@ -57,6 +61,9 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IRestorable, IShareable
/** @var bool */
private $useTrashbin = true;
+ /** @var LoggerInterface */
+ private $logger;
+
/**
* Calendar constructor.
*
@@ -65,7 +72,7 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IRestorable, IShareable
* @param IL10N $l10n
* @param IConfig $config
*/
- public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) {
+ public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config, LoggerInterface $logger) {
// Convert deletion date to ISO8601 string
if (isset($calendarInfo[TrashbinPlugin::PROPERTY_DELETED_AT])) {
$calendarInfo[TrashbinPlugin::PROPERTY_DELETED_AT] = (new DateTimeImmutable())
@@ -85,6 +92,7 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IRestorable, IShareable
$this->config = $config;
$this->l10n = $l10n;
+ $this->logger = $logger;
}
/**
@@ -415,6 +423,9 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IRestorable, IShareable
return parent::getChanges($syncToken, $syncLevel, $limit);
}
+ /**
+ * @inheritDoc
+ */
public function restore(): void {
$this->caldavBackend->restoreCalendar((int) $this->calendarInfo['id']);
}
@@ -422,4 +433,20 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IRestorable, IShareable
public function disableTrashbin(): void {
$this->useTrashbin = false;
}
+
+ /**
+ * @inheritDoc
+ */
+ public function moveInto($targetName, $sourcePath, INode $sourceNode) {
+ if (!($sourceNode instanceof CalendarObject)) {
+ return false;
+ }
+
+ try {
+ return $this->caldavBackend->moveCalendarObject($sourceNode->getCalendarId(), (int)$this->calendarInfo['id'], $sourceNode->getId(), $sourceNode->getPrincipalUri());
+ } catch (Exception $e) {
+ $this->logger->error('Could not move calendar object: ' . $e->getMessage(), ['exception' => $e]);
+ return false;
+ }
+ }
}