diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2022-10-04 12:49:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-04 12:49:47 +0200 |
commit | b57115df3ff0c7ffc23ed5844225df2d21e4ee5b (patch) | |
tree | ee71a61826b2cecd332ca360f9e44806c385d72c | |
parent | a87a8d78af68130b94d9bdbc41926a786d58a890 (diff) | |
parent | 19b7dad3dcba31e6c32bc55b00d13c5b224bda6c (diff) | |
download | nextcloud-server-b57115df3ff0c7ffc23ed5844225df2d21e4ee5b.tar.gz nextcloud-server-b57115df3ff0c7ffc23ed5844225df2d21e4ee5b.zip |
Merge pull request #34412 from nextcloud/fix/create-address-book-write-read-transactional
Wrap address book creation causal read in a transaction
-rw-r--r-- | apps/dav/lib/CardDAV/CardDavBackend.php | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index b4fdcf922dc..5d8ee3b9d56 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -45,6 +45,7 @@ use OCA\DAV\Events\AddressBookUpdatedEvent; use OCA\DAV\Events\CardCreatedEvent; use OCA\DAV\Events\CardDeletedEvent; use OCA\DAV\Events\CardUpdatedEvent; +use OCP\AppFramework\Db\TTransactional; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\EventDispatcher\IEventDispatcher; use OCP\IDBConnection; @@ -60,6 +61,9 @@ use Sabre\VObject\Component\VCard; use Sabre\VObject\Reader; class CardDavBackend implements BackendInterface, SyncSupport { + + use TTransactional; + public const PERSONAL_ADDRESSBOOK_URI = 'contacts'; public const PERSONAL_ADDRESSBOOK_NAME = 'Contacts'; @@ -420,20 +424,26 @@ class CardDavBackend implements BackendInterface, SyncSupport { $values['displayname'] = $url; } - $query = $this->db->getQueryBuilder(); - $query->insert('addressbooks') - ->values([ - 'uri' => $query->createParameter('uri'), - 'displayname' => $query->createParameter('displayname'), - 'description' => $query->createParameter('description'), - 'principaluri' => $query->createParameter('principaluri'), - 'synctoken' => $query->createParameter('synctoken'), - ]) - ->setParameters($values) - ->execute(); + [$addressBookId, $addressBookRow] = $this->atomic(function() use ($values) { + $query = $this->db->getQueryBuilder(); + $query->insert('addressbooks') + ->values([ + 'uri' => $query->createParameter('uri'), + 'displayname' => $query->createParameter('displayname'), + 'description' => $query->createParameter('description'), + 'principaluri' => $query->createParameter('principaluri'), + 'synctoken' => $query->createParameter('synctoken'), + ]) + ->setParameters($values) + ->execute(); + + $addressBookId = $query->getLastInsertId(); + return [ + $addressBookId, + $this->getAddressBookById($addressBookId), + ]; + }, $this->db); - $addressBookId = $query->getLastInsertId(); - $addressBookRow = $this->getAddressBookById($addressBookId); $this->dispatcher->dispatchTyped(new AddressBookCreatedEvent($addressBookId, $addressBookRow)); return $addressBookId; |