diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-02-03 21:41:17 +0100 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-05-12 21:02:53 +0200 |
commit | e71db404923f8c8b53e7968f8a10d3e7de0abe2a (patch) | |
tree | d4acfbb3f3ee7d6d3eccbcecb9f8511407ded03f /apps/dav | |
parent | eef973e85ba5e5cc322079ff85a599d42f1334e6 (diff) | |
download | nextcloud-server-e71db404923f8c8b53e7968f8a10d3e7de0abe2a.tar.gz nextcloud-server-e71db404923f8c8b53e7968f8a10d3e7de0abe2a.zip |
Wrap multiple inserts inside a transation
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/lib/CardDAV/CardDavBackend.php | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index ec1fef0b965..f5ed9a548d1 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -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(); } } |