Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dav): Fix atomic calendar/subscription updates #43904

Merged
merged 1 commit into from
Mar 5, 2024
Merged
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
13 changes: 8 additions & 5 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -848,11 +848,10 @@
* @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) {

Check notice

Code scanning / Psalm

MissingClosureParamType Note

Parameter $mutations has no provided type
$newValues = [];
foreach ($mutations as $propertyName => $propertyValue) {
switch ($propertyName) {
Expand All @@ -866,6 +865,7 @@
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 @@

$calendarData = $this->getCalendarById($calendarId);
$shares = $this->getShares($calendarId);
return [$calendarData, $shares];
}, $this->db);

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

Check notice

Code scanning / Psalm

PossiblyNullArgument Note

Argument 2 of OCA\DAV\Events\CalendarUpdatedEvent::__construct cannot be null, possibly null value provided
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking this is correct. \OCA\DAV\CalDAV\CalDavBackend::getCalendarById returns array|null. But this was used without a null check before. Now the data is just wrapped/returned by the closure. Psalm reports here because the diff make the code appear "new".
I'd leave it as is.


return true;
});
}, $this->db);
}

/**
Expand Down Expand Up @@ -2570,11 +2572,10 @@
* @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) {

Check notice

Code scanning / Psalm

MissingClosureParamType Note

Parameter $mutations has no provided type
$newValues = [];

foreach ($mutations as $propertyName => $propertyValue) {
Expand All @@ -2586,6 +2587,7 @@
}
}

$subscriptionRow = $this->atomic(function () use ($subscriptionId, $newValues) {

Check notice

Code scanning / Psalm

MissingClosureReturnType Note

Closure does not have a return type, expecting mixed
$query = $this->db->getQueryBuilder();
$query->update('calendarsubscriptions')
->set('lastmodified', $query->createNamedParameter(time()));
Expand All @@ -2595,12 +2597,13 @@
$query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId)))
->executeStatement();

$subscriptionRow = $this->getSubscriptionById($subscriptionId);
return $this->getSubscriptionById($subscriptionId);
}, $this->db);

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

return true;
});
}, $this->db);
}

/**
Expand Down
Loading