fix(dav): Fix atomic addressbook update

Sabre executes the proppatch callback *after* calling updateAddressbook
and not synchronously. That means the code inside the callback was run
outside a database transaction. This moves the atomic helper into the
callback to create the expected transaction span.

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
pull/43903/head
Christoph Wurst 9 months ago
parent 7cc20468f1
commit 09031211da
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8
  1. 42
      apps/dav/lib/CardDAV/CardDavBackend.php

@ -331,24 +331,24 @@ class CardDavBackend implements BackendInterface, SyncSupport {
* @return void
*/
public function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch) {
$this->atomic(function () use ($addressBookId, $propPatch) {
$supportedProperties = [
'{DAV:}displayname',
'{' . Plugin::NS_CARDDAV . '}addressbook-description',
];
$supportedProperties = [
'{DAV:}displayname',
'{' . Plugin::NS_CARDDAV . '}addressbook-description',
];
$propPatch->handle($supportedProperties, function ($mutations) use ($addressBookId) {
$updates = [];
foreach ($mutations as $property => $newValue) {
switch ($property) {
case '{DAV:}displayname':
$updates['displayname'] = $newValue;
break;
case '{' . Plugin::NS_CARDDAV . '}addressbook-description':
$updates['description'] = $newValue;
break;
}
$propPatch->handle($supportedProperties, function ($mutations) use ($addressBookId) {
$updates = [];
foreach ($mutations as $property => $newValue) {
switch ($property) {
case '{DAV:}displayname':
$updates['displayname'] = $newValue;
break;
case '{' . Plugin::NS_CARDDAV . '}addressbook-description':
$updates['description'] = $newValue;
break;
}
}
[$addressBookRow, $shares] = $this->atomic(function () use ($addressBookId, $updates) {
$query = $this->db->getQueryBuilder();
$query->update('addressbooks');
@ -362,11 +362,13 @@ class CardDavBackend implements BackendInterface, SyncSupport {
$addressBookRow = $this->getAddressBookById((int)$addressBookId);
$shares = $this->getShares((int)$addressBookId);
$this->dispatcher->dispatchTyped(new AddressBookUpdatedEvent((int)$addressBookId, $addressBookRow, $shares, $mutations));
return [$addressBookRow, $shares];
}, $this->db);
return true;
});
}, $this->db);
$this->dispatcher->dispatchTyped(new AddressBookUpdatedEvent((int)$addressBookId, $addressBookRow, $shares, $mutations));
return true;
});
}
/**

Loading…
Cancel
Save