Browse Source

Merge pull request #52228 from nextcloud/fix/issue-50748-calendar-object-move

fix(CalDAV): do not ignore move command object target uri
pull/52269/head
Christoph Wurst 7 months ago
committed by GitHub
parent
commit
535253e0d2
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 31
      apps/dav/lib/CalDAV/CalDavBackend.php
  2. 9
      apps/dav/lib/CalDAV/Calendar.php

31
apps/dav/lib/CalDAV/CalDavBackend.php

@ -1429,37 +1429,40 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
/**
* Moves a calendar object from calendar to calendar.
*
* @param int $sourceCalendarId
* @param string $sourcePrincipalUri
* @param int $sourceObjectId
* @param string $targetPrincipalUri
* @param int $targetCalendarId
* @param int $objectId
* @param string $oldPrincipalUri
* @param string $newPrincipalUri
* @param string $tragetObjectUri
* @param int $calendarType
* @return bool
* @throws Exception
*/
public function moveCalendarObject(int $sourceCalendarId, int $targetCalendarId, int $objectId, string $oldPrincipalUri, string $newPrincipalUri, int $calendarType = self::CALENDAR_TYPE_CALENDAR): bool {
public function moveCalendarObject(string $sourcePrincipalUri, int $sourceObjectId, string $targetPrincipalUri, int $targetCalendarId, string $tragetObjectUri, int $calendarType = self::CALENDAR_TYPE_CALENDAR): bool {
$this->cachedObjects = [];
return $this->atomic(function () use ($sourceCalendarId, $targetCalendarId, $objectId, $oldPrincipalUri, $newPrincipalUri, $calendarType) {
$object = $this->getCalendarObjectById($oldPrincipalUri, $objectId);
return $this->atomic(function () use ($sourcePrincipalUri, $sourceObjectId, $targetPrincipalUri, $targetCalendarId, $tragetObjectUri, $calendarType) {
$object = $this->getCalendarObjectById($sourcePrincipalUri, $sourceObjectId);
if (empty($object)) {
return false;
}
$sourceCalendarId = $object['calendarid'];
$sourceObjectUri = $object['uri'];
$query = $this->db->getQueryBuilder();
$query->update('calendarobjects')
->set('calendarid', $query->createNamedParameter($targetCalendarId, IQueryBuilder::PARAM_INT))
->where($query->expr()->eq('id', $query->createNamedParameter($objectId, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT))
->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT))
->set('uri', $query->createNamedParameter($tragetObjectUri, IQueryBuilder::PARAM_STR))
->where($query->expr()->eq('id', $query->createNamedParameter($sourceObjectId, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT))
->executeStatement();
$this->purgeProperties($sourceCalendarId, $objectId);
$this->updateProperties($targetCalendarId, $object['uri'], $object['calendardata'], $calendarType);
$this->purgeProperties($sourceCalendarId, $sourceObjectId);
$this->updateProperties($targetCalendarId, $tragetObjectUri, $object['calendardata'], $calendarType);
$this->addChanges($sourceCalendarId, [$object['uri']], 3, $calendarType);
$this->addChanges($targetCalendarId, [$object['uri']], 1, $calendarType);
$this->addChanges($sourceCalendarId, [$sourceObjectUri], 3, $calendarType);
$this->addChanges($targetCalendarId, [$tragetObjectUri], 1, $calendarType);
$object = $this->getCalendarObjectById($newPrincipalUri, $objectId);
$object = $this->getCalendarObjectById($targetPrincipalUri, $sourceObjectId);
// Calendar Object wasn't found - possibly because it was deleted in the meantime by a different client
if (empty($object)) {
return false;

9
apps/dav/lib/CalDAV/Calendar.php

@ -391,9 +391,14 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IRestorable, IShareable
if (!($sourceNode instanceof CalendarObject)) {
return false;
}
try {
return $this->caldavBackend->moveCalendarObject($sourceNode->getCalendarId(), (int)$this->calendarInfo['id'], $sourceNode->getId(), $sourceNode->getOwner(), $this->getOwner());
return $this->caldavBackend->moveCalendarObject(
$sourceNode->getOwner(),
$sourceNode->getId(),
$this->getOwner(),
$this->getResourceId(),
$targetName,
);
} catch (Exception $e) {
$this->logger->error('Could not move calendar object: ' . $e->getMessage(), ['exception' => $e]);
return false;

Loading…
Cancel
Save