Skip to content

Commit

Permalink
Merge pull request #43903 from nextcloud/fix/dav/dirty-address-book-u…
Browse files Browse the repository at this point in the history
…pdate

fix(dav): Fix atomic addressbook update
  • Loading branch information
skjnldsv authored Mar 5, 2024
2 parents 0d4e648 + 0903121 commit 65a0583
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,24 +331,24 @@ public function getAddressBooksByUri(string $principal, string $addressBookUri):
* @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');

Expand All @@ -362,11 +362,13 @@ public function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatc

$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;
});
}

/**
Expand Down

0 comments on commit 65a0583

Please sign in to comment.