diff options
author | Thomas Citharel <tcit@tcit.fr> | 2023-02-10 12:17:27 +0100 |
---|---|---|
committer | Simon L. (Rebase PR Action) <szaimen@e.mail.de> | 2023-04-17 16:08:44 +0000 |
commit | c9a3129cb4e33efab6b65af37a2e7de117153788 (patch) | |
tree | ada6e45180a7f16b2f50e5fde77d67532b9b4c3e /apps/dav/lib/DAV/Sharing | |
parent | b9520661406bc514ac16f11aeb85b1980d62f581 (diff) | |
download | nextcloud-server-c9a3129cb4e33efab6b65af37a2e7de117153788.tar.gz nextcloud-server-c9a3129cb4e33efab6b65af37a2e7de117153788.zip |
fix(CalDAV/CardDAV): put every method from Cal/CardDAV backends that does multiple DB calls in transactions
In a lot of methods we're doing read-after-writes (for instance calling
updateProperties after touching calendar objects).
There's also a lot of deleting methods that do stuff sequentially which
could cause trouble.
This should avoid this kind of issues.
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'apps/dav/lib/DAV/Sharing')
-rw-r--r-- | apps/dav/lib/DAV/Sharing/Backend.php | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/apps/dav/lib/DAV/Sharing/Backend.php b/apps/dav/lib/DAV/Sharing/Backend.php index 7ba5ffd2700..813f99dcbbd 100644 --- a/apps/dav/lib/DAV/Sharing/Backend.php +++ b/apps/dav/lib/DAV/Sharing/Backend.php @@ -29,12 +29,15 @@ namespace OCA\DAV\DAV\Sharing; use OCA\DAV\Connector\Sabre\Principal; +use OCP\AppFramework\Db\TTransactional; use OCP\IDBConnection; use OCP\IGroupManager; use OCP\IUserManager; use OCP\DB\QueryBuilder\IQueryBuilder; class Backend { + use TTransactional; + private IDBConnection $db; private IUserManager $userManager; private IGroupManager $groupManager; @@ -58,18 +61,20 @@ class Backend { * @param list<string> $remove */ public function updateShares(IShareable $shareable, array $add, array $remove): void { - foreach ($add as $element) { - $principal = $this->principalBackend->findByUri($element['href'], ''); - if ($principal !== '') { - $this->shareWith($shareable, $element); + $this->atomic(function () use ($shareable, $add, $remove) { + foreach ($add as $element) { + $principal = $this->principalBackend->findByUri($element['href'], ''); + if ($principal !== '') { + $this->shareWith($shareable, $element); + } } - } - foreach ($remove as $element) { - $principal = $this->principalBackend->findByUri($element, ''); - if ($principal !== '') { - $this->unshare($shareable, $element); + foreach ($remove as $element) { + $principal = $this->principalBackend->findByUri($element, ''); + if ($principal !== '') { + $this->unshare($shareable, $element); + } } - } + }, $this->db); } /** |