Skip to content

Commit

Permalink
Merge pull request #43904 from nextcloud/fix/dav/dirty-caldav-updates
Browse files Browse the repository at this point in the history
fix(dav): Fix atomic calendar/subscription updates
  • Loading branch information
st3iny authored Mar 5, 2024
2 parents e072035 + a2fcf50 commit 00e0fa4
Showing 1 changed file with 43 additions and 40 deletions.
83 changes: 43 additions & 40 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -848,24 +848,24 @@ public function createCalendar($principalUri, $calendarUri, array $properties) {
* @return void
*/
public function updateCalendar($calendarId, PropPatch $propPatch) {
$this->atomic(function () use ($calendarId, $propPatch) {
$supportedProperties = array_keys($this->propertyMap);
$supportedProperties[] = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp';

$propPatch->handle($supportedProperties, function ($mutations) use ($calendarId) {
$newValues = [];
foreach ($mutations as $propertyName => $propertyValue) {
switch ($propertyName) {
case '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp':
$fieldName = 'transparent';
$newValues[$fieldName] = (int) ($propertyValue->getValue() === 'transparent');
break;
default:
$fieldName = $this->propertyMap[$propertyName][0];
$newValues[$fieldName] = $propertyValue;
break;
}
$supportedProperties = array_keys($this->propertyMap);
$supportedProperties[] = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp';

$propPatch->handle($supportedProperties, function ($mutations) use ($calendarId) {
$newValues = [];
foreach ($mutations as $propertyName => $propertyValue) {
switch ($propertyName) {
case '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp':
$fieldName = 'transparent';
$newValues[$fieldName] = (int) ($propertyValue->getValue() === 'transparent');
break;
default:
$fieldName = $this->propertyMap[$propertyName][0];
$newValues[$fieldName] = $propertyValue;
break;
}
}
[$calendarData, $shares] = $this->atomic(function () use ($calendarId, $newValues) {
$query = $this->db->getQueryBuilder();
$query->update('calendars');
foreach ($newValues as $fieldName => $value) {
Expand All @@ -878,11 +878,13 @@ public function updateCalendar($calendarId, PropPatch $propPatch) {

$calendarData = $this->getCalendarById($calendarId);
$shares = $this->getShares($calendarId);
$this->dispatcher->dispatchTyped(new CalendarUpdatedEvent($calendarId, $calendarData, $shares, $mutations));
return [$calendarData, $shares];
}, $this->db);

return true;
});
}, $this->db);
$this->dispatcher->dispatchTyped(new CalendarUpdatedEvent($calendarId, $calendarData, $shares, $mutations));

return true;
});
}

/**
Expand Down Expand Up @@ -2570,22 +2572,22 @@ public function createSubscription($principalUri, $uri, array $properties) {
* @return void
*/
public function updateSubscription($subscriptionId, PropPatch $propPatch) {
$this->atomic(function () use ($subscriptionId, $propPatch) {
$supportedProperties = array_keys($this->subscriptionPropertyMap);
$supportedProperties[] = '{http://calendarserver.org/ns/}source';

$propPatch->handle($supportedProperties, function ($mutations) use ($subscriptionId) {
$newValues = [];

foreach ($mutations as $propertyName => $propertyValue) {
if ($propertyName === '{http://calendarserver.org/ns/}source') {
$newValues['source'] = $propertyValue->getHref();
} else {
$fieldName = $this->subscriptionPropertyMap[$propertyName][0];
$newValues[$fieldName] = $propertyValue;
}
$supportedProperties = array_keys($this->subscriptionPropertyMap);
$supportedProperties[] = '{http://calendarserver.org/ns/}source';

$propPatch->handle($supportedProperties, function ($mutations) use ($subscriptionId) {
$newValues = [];

foreach ($mutations as $propertyName => $propertyValue) {
if ($propertyName === '{http://calendarserver.org/ns/}source') {
$newValues['source'] = $propertyValue->getHref();
} else {
$fieldName = $this->subscriptionPropertyMap[$propertyName][0];
$newValues[$fieldName] = $propertyValue;
}
}

$subscriptionRow = $this->atomic(function () use ($subscriptionId, $newValues) {
$query = $this->db->getQueryBuilder();
$query->update('calendarsubscriptions')
->set('lastmodified', $query->createNamedParameter(time()));
Expand All @@ -2595,12 +2597,13 @@ public function updateSubscription($subscriptionId, PropPatch $propPatch) {
$query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId)))
->executeStatement();

$subscriptionRow = $this->getSubscriptionById($subscriptionId);
$this->dispatcher->dispatchTyped(new SubscriptionUpdatedEvent((int)$subscriptionId, $subscriptionRow, [], $mutations));
return $this->getSubscriptionById($subscriptionId);
}, $this->db);

return true;
});
}, $this->db);
$this->dispatcher->dispatchTyped(new SubscriptionUpdatedEvent((int)$subscriptionId, $subscriptionRow, [], $mutations));

return true;
});
}

/**
Expand Down

0 comments on commit 00e0fa4

Please sign in to comment.