summaryrefslogtreecommitdiff
path: root/lib/Kolab/CardDAV/ContactsBackend.php
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2013-09-04 14:28:46 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2013-09-04 14:28:46 (GMT)
commit1b3d45fd92e622efe66fabf111da1d79a8826798 (patch)
treec97fb96c3a8e111e77b3af461ac6256a885ab539 /lib/Kolab/CardDAV/ContactsBackend.php
parent7164ba811e5f711023a3c87841729b6ff44414b5 (diff)
downloadiRony-1b3d45fd92e622efe66fabf111da1d79a8826798.tar.gz
Accept events/vcards with URI doesn't match the objects's UID. Send a Location: header with the response (#2109)
Diffstat (limited to 'lib/Kolab/CardDAV/ContactsBackend.php')
-rw-r--r--lib/Kolab/CardDAV/ContactsBackend.php34
1 files changed, 20 insertions, 14 deletions
diff --git a/lib/Kolab/CardDAV/ContactsBackend.php b/lib/Kolab/CardDAV/ContactsBackend.php
index 17808c1..41e1ca3 100644
--- a/lib/Kolab/CardDAV/ContactsBackend.php
+++ b/lib/Kolab/CardDAV/ContactsBackend.php
@@ -344,26 +344,31 @@ class ContactsBackend extends CardDAV\Backend\AbstractBackend
$storage = $this->get_storage_folder($addressBookId);
$object = $this->parse_vcard($cardData, $uid);
- if ($object['uid'] == $uid) {
- $success = $storage->save($object, $object['_type']);
- if (!$success) {
- rcube::raise_error(array(
- 'code' => 600, 'type' => 'php',
- 'file' => __FILE__, 'line' => __LINE__,
- 'message' => "Error saving contact object to Kolab server"),
- true, false);
-
- throw new DAV\Exception('Error saving contact card to backend');
- }
+ if (empty($object) || empty($object['uid'])) {
+ throw new DAV\Exception('Parse error: not a valid VCard object');
}
- else {
+
+ // if URI doesn't match the content's UID, the object might already exist!
+ $cardUri = $object['uid'] . '.vcf';
+ if ($object['uid'] != $uid && $this->getCard($addressBookId, $cardUri)) {
+ Plugin::$redirect_basename = $cardUri;
+ return $this->updateCard($addressBookId, $cardUri, $cardData);
+ }
+
+ $success = $storage->save($object, $object['_type']);
+ if (!$success) {
rcube::raise_error(array(
'code' => 600, 'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
- 'message' => "Error creating contact object: UID doesn't match object URI"),
+ 'message' => "Error saving contact object to Kolab server"),
true, false);
- throw new DAV\Exception\NotFound("UID doesn't match object URI");
+ throw new DAV\Exception('Error saving contact card to backend');
+ }
+
+ // send Location: header if URI doesn't match object's UID (Bug #2109)
+ if ($object['uid'] != $uid) {
+ Plugin::$redirect_basename = $cardUri;
}
// return new Etag
@@ -445,6 +450,7 @@ class ContactsBackend extends CardDAV\Backend\AbstractBackend
'message' => "Error saving contact object to Kolab server"),
true, false);
+ Plugin::$redirect_basename = null;
throw new DAV\Exception('Error saving contact card to backend');
}