]> source.dussan.org Git - nextcloud-server.git/commitdiff
Wrap multiple inserts inside a transation 30863/head
authorCarl Schwan <carl@carlschwan.eu>
Thu, 3 Feb 2022 20:41:17 +0000 (21:41 +0100)
committerCarl Schwan <carl@carlschwan.eu>
Thu, 12 May 2022 19:02:53 +0000 (21:02 +0200)
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
apps/dav/lib/CardDAV/CardDavBackend.php

index ec1fef0b965cb753f4b39b6917e5eb67882846ed..f5ed9a548d16574b3e61564b13218b0b094e3ccf 100644 (file)
@@ -1271,21 +1271,29 @@ class CardDavBackend implements BackendInterface, SyncSupport {
                                ]
                        );
 
-               foreach ($vCard->children() as $property) {
-                       if (!in_array($property->name, self::$indexProperties)) {
-                               continue;
-                       }
-                       $preferred = 0;
-                       foreach ($property->parameters as $parameter) {
-                               if ($parameter->name === 'TYPE' && strtoupper($parameter->getValue()) === 'PREF') {
-                                       $preferred = 1;
-                                       break;
+
+               $this->db->beginTransaction();
+
+               try {
+                       foreach ($vCard->children() as $property) {
+                               if (!in_array($property->name, self::$indexProperties)) {
+                                       continue;
+                               }
+                               $preferred = 0;
+                               foreach ($property->parameters as $parameter) {
+                                       if ($parameter->name === 'TYPE' && strtoupper($parameter->getValue()) === 'PREF') {
+                                               $preferred = 1;
+                                               break;
+                                       }
                                }
+                               $query->setParameter('name', $property->name);
+                               $query->setParameter('value', mb_strcut($property->getValue(), 0, 254));
+                               $query->setParameter('preferred', $preferred);
+                               $query->execute();
                        }
-                       $query->setParameter('name', $property->name);
-                       $query->setParameter('value', mb_strcut($property->getValue(), 0, 254));
-                       $query->setParameter('preferred', $preferred);
-                       $query->execute();
+                       $this->db->commit();
+               } catch (\Exception $e) {
+                       $this->db->rollBack();
                }
        }