Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/CardDAV/CardDavBackend.php')
-rw-r--r--apps/dav/lib/CardDAV/CardDavBackend.php61
1 files changed, 36 insertions, 25 deletions
diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php
index 1c1754ff752..f5ed9a548d1 100644
--- a/apps/dav/lib/CardDAV/CardDavBackend.php
+++ b/apps/dav/lib/CardDAV/CardDavBackend.php
@@ -648,23 +648,26 @@ class CardDavBackend implements BackendInterface, SyncSupport {
* @param mixed $addressBookId
* @param string $cardUri
* @param string $cardData
+ * @param bool $checkAlreadyExists
* @return string
*/
- public function createCard($addressBookId, $cardUri, $cardData) {
+ public function createCard($addressBookId, $cardUri, $cardData, bool $checkAlreadyExists = true) {
$etag = md5($cardData);
$uid = $this->getUID($cardData);
- $q = $this->db->getQueryBuilder();
- $q->select('uid')
- ->from($this->dbCardsTable)
- ->where($q->expr()->eq('addressbookid', $q->createNamedParameter($addressBookId)))
- ->andWhere($q->expr()->eq('uid', $q->createNamedParameter($uid)))
- ->setMaxResults(1);
- $result = $q->execute();
- $count = (bool)$result->fetchOne();
- $result->closeCursor();
- if ($count) {
- throw new \Sabre\DAV\Exception\BadRequest('VCard object with uid already exists in this addressbook collection.');
+ if ($checkAlreadyExists) {
+ $q = $this->db->getQueryBuilder();
+ $q->select('uid')
+ ->from($this->dbCardsTable)
+ ->where($q->expr()->eq('addressbookid', $q->createNamedParameter($addressBookId)))
+ ->andWhere($q->expr()->eq('uid', $q->createNamedParameter($uid)))
+ ->setMaxResults(1);
+ $result = $q->executeQuery();
+ $count = (bool)$result->fetchOne();
+ $result->closeCursor();
+ if ($count) {
+ throw new \Sabre\DAV\Exception\BadRequest('VCard object with uid already exists in this addressbook collection.');
+ }
}
$query = $this->db->getQueryBuilder();
@@ -1268,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();
}
}