Skip to content

Commit

Permalink
Wrap multiple inserts inside a transation
Browse files Browse the repository at this point in the history
Signed-off-by: Carl Schwan <[email protected]>
  • Loading branch information
CarlSchwan committed Mar 10, 2022
1 parent 6ae91d6 commit 830122d
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -1268,21 +1268,29 @@ protected function updateProperties($addressBookId, $cardUri, $vCardSerialized)
]
);

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

Expand Down

0 comments on commit 830122d

Please sign in to comment.