Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -1400,37 +1400,40 @@ public function updateCalendarObject($calendarId, $objectUri, $calendarData, $ca
/**
* 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;
Expand Down
9 changes: 7 additions & 2 deletions apps/dav/lib/CalDAV/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,14 @@ 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->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;
Expand Down
Loading