1
0

CardDavBackend.php 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arne Hamann <kontakt+github@arne.email>
  6. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * @author Bjoern Schiessle <bjoern@schiessle.org>
  8. * @author Björn Schießle <bjoern@schiessle.org>
  9. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  10. * @author Georg Ehrke <oc.list@georgehrke.com>
  11. * @author Joas Schilling <coding@schilljs.com>
  12. * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  13. * @author Julius Härtl <jus@bitgrid.net>
  14. * @author Lukas Reschke <lukas@statuscode.ch>
  15. * @author Morris Jobke <hey@morrisjobke.de>
  16. * @author Robin Appelman <robin@icewind.nl>
  17. * @author Roeland Jago Douma <roeland@famdouma.nl>
  18. * @author Stefan Weil <sw@weilnetz.de>
  19. * @author Thomas Citharel <nextcloud@tcit.fr>
  20. * @author Thomas Müller <thomas.mueller@tmit.eu>
  21. *
  22. * @license AGPL-3.0
  23. *
  24. * This code is free software: you can redistribute it and/or modify
  25. * it under the terms of the GNU Affero General Public License, version 3,
  26. * as published by the Free Software Foundation.
  27. *
  28. * This program is distributed in the hope that it will be useful,
  29. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. * GNU Affero General Public License for more details.
  32. *
  33. * You should have received a copy of the GNU Affero General Public License, version 3,
  34. * along with this program. If not, see <http://www.gnu.org/licenses/>
  35. *
  36. */
  37. namespace OCA\DAV\CardDAV;
  38. use OCA\DAV\Connector\Sabre\Principal;
  39. use OCA\DAV\DAV\Sharing\Backend;
  40. use OCA\DAV\DAV\Sharing\IShareable;
  41. use OCP\DB\QueryBuilder\IQueryBuilder;
  42. use OCP\IDBConnection;
  43. use OCP\IGroupManager;
  44. use OCP\IUser;
  45. use OCP\IUserManager;
  46. use PDO;
  47. use Sabre\CardDAV\Backend\BackendInterface;
  48. use Sabre\CardDAV\Backend\SyncSupport;
  49. use Sabre\CardDAV\Plugin;
  50. use Sabre\DAV\Exception\BadRequest;
  51. use Sabre\VObject\Component\VCard;
  52. use Sabre\VObject\Reader;
  53. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  54. use Symfony\Component\EventDispatcher\GenericEvent;
  55. class CardDavBackend implements BackendInterface, SyncSupport {
  56. public const PERSONAL_ADDRESSBOOK_URI = 'contacts';
  57. public const PERSONAL_ADDRESSBOOK_NAME = 'Contacts';
  58. /** @var Principal */
  59. private $principalBackend;
  60. /** @var string */
  61. private $dbCardsTable = 'cards';
  62. /** @var string */
  63. private $dbCardsPropertiesTable = 'cards_properties';
  64. /** @var IDBConnection */
  65. private $db;
  66. /** @var Backend */
  67. private $sharingBackend;
  68. /** @var array properties to index */
  69. public static $indexProperties = [
  70. 'BDAY', 'UID', 'N', 'FN', 'TITLE', 'ROLE', 'NOTE', 'NICKNAME',
  71. 'ORG', 'CATEGORIES', 'EMAIL', 'TEL', 'IMPP', 'ADR', 'URL', 'GEO', 'CLOUD'];
  72. /**
  73. * @var string[] Map of uid => display name
  74. */
  75. protected $userDisplayNames;
  76. /** @var IUserManager */
  77. private $userManager;
  78. /** @var EventDispatcherInterface */
  79. private $dispatcher;
  80. /**
  81. * CardDavBackend constructor.
  82. *
  83. * @param IDBConnection $db
  84. * @param Principal $principalBackend
  85. * @param IUserManager $userManager
  86. * @param IGroupManager $groupManager
  87. * @param EventDispatcherInterface $dispatcher
  88. */
  89. public function __construct(IDBConnection $db,
  90. Principal $principalBackend,
  91. IUserManager $userManager,
  92. IGroupManager $groupManager,
  93. EventDispatcherInterface $dispatcher) {
  94. $this->db = $db;
  95. $this->principalBackend = $principalBackend;
  96. $this->userManager = $userManager;
  97. $this->dispatcher = $dispatcher;
  98. $this->sharingBackend = new Backend($this->db, $this->userManager, $groupManager, $principalBackend, 'addressbook');
  99. }
  100. /**
  101. * Return the number of address books for a principal
  102. *
  103. * @param $principalUri
  104. * @return int
  105. */
  106. public function getAddressBooksForUserCount($principalUri) {
  107. $principalUri = $this->convertPrincipal($principalUri, true);
  108. $query = $this->db->getQueryBuilder();
  109. $query->select($query->func()->count('*'))
  110. ->from('addressbooks')
  111. ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));
  112. return (int)$query->execute()->fetchColumn();
  113. }
  114. /**
  115. * Returns the list of address books for a specific user.
  116. *
  117. * Every addressbook should have the following properties:
  118. * id - an arbitrary unique id
  119. * uri - the 'basename' part of the url
  120. * principaluri - Same as the passed parameter
  121. *
  122. * Any additional clark-notation property may be passed besides this. Some
  123. * common ones are :
  124. * {DAV:}displayname
  125. * {urn:ietf:params:xml:ns:carddav}addressbook-description
  126. * {http://calendarserver.org/ns/}getctag
  127. *
  128. * @param string $principalUri
  129. * @return array
  130. */
  131. public function getAddressBooksForUser($principalUri) {
  132. $principalUriOriginal = $principalUri;
  133. $principalUri = $this->convertPrincipal($principalUri, true);
  134. $query = $this->db->getQueryBuilder();
  135. $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken'])
  136. ->from('addressbooks')
  137. ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));
  138. $addressBooks = [];
  139. $result = $query->execute();
  140. while ($row = $result->fetch()) {
  141. $addressBooks[$row['id']] = [
  142. 'id' => $row['id'],
  143. 'uri' => $row['uri'],
  144. 'principaluri' => $this->convertPrincipal($row['principaluri'], false),
  145. '{DAV:}displayname' => $row['displayname'],
  146. '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'],
  147. '{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
  148. '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
  149. ];
  150. $this->addOwnerPrincipal($addressBooks[$row['id']]);
  151. }
  152. $result->closeCursor();
  153. // query for shared addressbooks
  154. $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true);
  155. $principals = array_merge($principals, $this->principalBackend->getCircleMembership($principalUriOriginal));
  156. $principals = array_map(function ($principal) {
  157. return urldecode($principal);
  158. }, $principals);
  159. $principals[]= $principalUri;
  160. $query = $this->db->getQueryBuilder();
  161. $result = $query->select(['a.id', 'a.uri', 'a.displayname', 'a.principaluri', 'a.description', 'a.synctoken', 's.access'])
  162. ->from('dav_shares', 's')
  163. ->join('s', 'addressbooks', 'a', $query->expr()->eq('s.resourceid', 'a.id'))
  164. ->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri')))
  165. ->andWhere($query->expr()->eq('s.type', $query->createParameter('type')))
  166. ->setParameter('type', 'addressbook')
  167. ->setParameter('principaluri', $principals, IQueryBuilder::PARAM_STR_ARRAY)
  168. ->execute();
  169. $readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only';
  170. while ($row = $result->fetch()) {
  171. if ($row['principaluri'] === $principalUri) {
  172. continue;
  173. }
  174. $readOnly = (int) $row['access'] === Backend::ACCESS_READ;
  175. if (isset($addressBooks[$row['id']])) {
  176. if ($readOnly) {
  177. // New share can not have more permissions then the old one.
  178. continue;
  179. }
  180. if (isset($addressBooks[$row['id']][$readOnlyPropertyName]) &&
  181. $addressBooks[$row['id']][$readOnlyPropertyName] === 0) {
  182. // Old share is already read-write, no more permissions can be gained
  183. continue;
  184. }
  185. }
  186. list(, $name) = \Sabre\Uri\split($row['principaluri']);
  187. $uri = $row['uri'] . '_shared_by_' . $name;
  188. $displayName = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')';
  189. $addressBooks[$row['id']] = [
  190. 'id' => $row['id'],
  191. 'uri' => $uri,
  192. 'principaluri' => $principalUriOriginal,
  193. '{DAV:}displayname' => $displayName,
  194. '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'],
  195. '{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
  196. '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
  197. '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'],
  198. $readOnlyPropertyName => $readOnly,
  199. ];
  200. $this->addOwnerPrincipal($addressBooks[$row['id']]);
  201. }
  202. $result->closeCursor();
  203. return array_values($addressBooks);
  204. }
  205. public function getUsersOwnAddressBooks($principalUri) {
  206. $principalUri = $this->convertPrincipal($principalUri, true);
  207. $query = $this->db->getQueryBuilder();
  208. $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken'])
  209. ->from('addressbooks')
  210. ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));
  211. $addressBooks = [];
  212. $result = $query->execute();
  213. while ($row = $result->fetch()) {
  214. $addressBooks[$row['id']] = [
  215. 'id' => $row['id'],
  216. 'uri' => $row['uri'],
  217. 'principaluri' => $this->convertPrincipal($row['principaluri'], false),
  218. '{DAV:}displayname' => $row['displayname'],
  219. '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'],
  220. '{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
  221. '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
  222. ];
  223. $this->addOwnerPrincipal($addressBooks[$row['id']]);
  224. }
  225. $result->closeCursor();
  226. return array_values($addressBooks);
  227. }
  228. private function getUserDisplayName($uid) {
  229. if (!isset($this->userDisplayNames[$uid])) {
  230. $user = $this->userManager->get($uid);
  231. if ($user instanceof IUser) {
  232. $this->userDisplayNames[$uid] = $user->getDisplayName();
  233. } else {
  234. $this->userDisplayNames[$uid] = $uid;
  235. }
  236. }
  237. return $this->userDisplayNames[$uid];
  238. }
  239. /**
  240. * @param int $addressBookId
  241. */
  242. public function getAddressBookById($addressBookId) {
  243. $query = $this->db->getQueryBuilder();
  244. $result = $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken'])
  245. ->from('addressbooks')
  246. ->where($query->expr()->eq('id', $query->createNamedParameter($addressBookId)))
  247. ->execute();
  248. $row = $result->fetch();
  249. $result->closeCursor();
  250. if ($row === false) {
  251. return null;
  252. }
  253. $addressBook = [
  254. 'id' => $row['id'],
  255. 'uri' => $row['uri'],
  256. 'principaluri' => $row['principaluri'],
  257. '{DAV:}displayname' => $row['displayname'],
  258. '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'],
  259. '{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
  260. '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
  261. ];
  262. $this->addOwnerPrincipal($addressBook);
  263. return $addressBook;
  264. }
  265. /**
  266. * @param $addressBookUri
  267. * @return array|null
  268. */
  269. public function getAddressBooksByUri($principal, $addressBookUri) {
  270. $query = $this->db->getQueryBuilder();
  271. $result = $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken'])
  272. ->from('addressbooks')
  273. ->where($query->expr()->eq('uri', $query->createNamedParameter($addressBookUri)))
  274. ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principal)))
  275. ->setMaxResults(1)
  276. ->execute();
  277. $row = $result->fetch();
  278. $result->closeCursor();
  279. if ($row === false) {
  280. return null;
  281. }
  282. $addressBook = [
  283. 'id' => $row['id'],
  284. 'uri' => $row['uri'],
  285. 'principaluri' => $row['principaluri'],
  286. '{DAV:}displayname' => $row['displayname'],
  287. '{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'],
  288. '{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
  289. '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
  290. ];
  291. $this->addOwnerPrincipal($addressBook);
  292. return $addressBook;
  293. }
  294. /**
  295. * Updates properties for an address book.
  296. *
  297. * The list of mutations is stored in a Sabre\DAV\PropPatch object.
  298. * To do the actual updates, you must tell this object which properties
  299. * you're going to process with the handle() method.
  300. *
  301. * Calling the handle method is like telling the PropPatch object "I
  302. * promise I can handle updating this property".
  303. *
  304. * Read the PropPatch documentation for more info and examples.
  305. *
  306. * @param string $addressBookId
  307. * @param \Sabre\DAV\PropPatch $propPatch
  308. * @return void
  309. */
  310. public function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch) {
  311. $supportedProperties = [
  312. '{DAV:}displayname',
  313. '{' . Plugin::NS_CARDDAV . '}addressbook-description',
  314. ];
  315. /**
  316. * @suppress SqlInjectionChecker
  317. */
  318. $propPatch->handle($supportedProperties, function ($mutations) use ($addressBookId) {
  319. $updates = [];
  320. foreach ($mutations as $property=>$newValue) {
  321. switch ($property) {
  322. case '{DAV:}displayname':
  323. $updates['displayname'] = $newValue;
  324. break;
  325. case '{' . Plugin::NS_CARDDAV . '}addressbook-description':
  326. $updates['description'] = $newValue;
  327. break;
  328. }
  329. }
  330. $query = $this->db->getQueryBuilder();
  331. $query->update('addressbooks');
  332. foreach ($updates as $key=>$value) {
  333. $query->set($key, $query->createNamedParameter($value));
  334. }
  335. $query->where($query->expr()->eq('id', $query->createNamedParameter($addressBookId)))
  336. ->execute();
  337. $this->addChange($addressBookId, "", 2);
  338. return true;
  339. });
  340. }
  341. /**
  342. * Creates a new address book
  343. *
  344. * @param string $principalUri
  345. * @param string $url Just the 'basename' of the url.
  346. * @param array $properties
  347. * @return int
  348. * @throws BadRequest
  349. */
  350. public function createAddressBook($principalUri, $url, array $properties) {
  351. $values = [
  352. 'displayname' => null,
  353. 'description' => null,
  354. 'principaluri' => $principalUri,
  355. 'uri' => $url,
  356. 'synctoken' => 1
  357. ];
  358. foreach ($properties as $property=>$newValue) {
  359. switch ($property) {
  360. case '{DAV:}displayname':
  361. $values['displayname'] = $newValue;
  362. break;
  363. case '{' . Plugin::NS_CARDDAV . '}addressbook-description':
  364. $values['description'] = $newValue;
  365. break;
  366. default:
  367. throw new BadRequest('Unknown property: ' . $property);
  368. }
  369. }
  370. // Fallback to make sure the displayname is set. Some clients may refuse
  371. // to work with addressbooks not having a displayname.
  372. if (is_null($values['displayname'])) {
  373. $values['displayname'] = $url;
  374. }
  375. $query = $this->db->getQueryBuilder();
  376. $query->insert('addressbooks')
  377. ->values([
  378. 'uri' => $query->createParameter('uri'),
  379. 'displayname' => $query->createParameter('displayname'),
  380. 'description' => $query->createParameter('description'),
  381. 'principaluri' => $query->createParameter('principaluri'),
  382. 'synctoken' => $query->createParameter('synctoken'),
  383. ])
  384. ->setParameters($values)
  385. ->execute();
  386. return $query->getLastInsertId();
  387. }
  388. /**
  389. * Deletes an entire addressbook and all its contents
  390. *
  391. * @param mixed $addressBookId
  392. * @return void
  393. */
  394. public function deleteAddressBook($addressBookId) {
  395. $query = $this->db->getQueryBuilder();
  396. $query->delete($this->dbCardsTable)
  397. ->where($query->expr()->eq('addressbookid', $query->createParameter('addressbookid')))
  398. ->setParameter('addressbookid', $addressBookId)
  399. ->execute();
  400. $query->delete('addressbookchanges')
  401. ->where($query->expr()->eq('addressbookid', $query->createParameter('addressbookid')))
  402. ->setParameter('addressbookid', $addressBookId)
  403. ->execute();
  404. $query->delete('addressbooks')
  405. ->where($query->expr()->eq('id', $query->createParameter('id')))
  406. ->setParameter('id', $addressBookId)
  407. ->execute();
  408. $this->sharingBackend->deleteAllShares($addressBookId);
  409. $query->delete($this->dbCardsPropertiesTable)
  410. ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)))
  411. ->execute();
  412. }
  413. /**
  414. * Returns all cards for a specific addressbook id.
  415. *
  416. * This method should return the following properties for each card:
  417. * * carddata - raw vcard data
  418. * * uri - Some unique url
  419. * * lastmodified - A unix timestamp
  420. *
  421. * It's recommended to also return the following properties:
  422. * * etag - A unique etag. This must change every time the card changes.
  423. * * size - The size of the card in bytes.
  424. *
  425. * If these last two properties are provided, less time will be spent
  426. * calculating them. If they are specified, you can also ommit carddata.
  427. * This may speed up certain requests, especially with large cards.
  428. *
  429. * @param mixed $addressBookId
  430. * @return array
  431. */
  432. public function getCards($addressBookId) {
  433. $query = $this->db->getQueryBuilder();
  434. $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid'])
  435. ->from($this->dbCardsTable)
  436. ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)));
  437. $cards = [];
  438. $result = $query->execute();
  439. while ($row = $result->fetch()) {
  440. $row['etag'] = '"' . $row['etag'] . '"';
  441. $modified = false;
  442. $row['carddata'] = $this->readBlob($row['carddata'], $modified);
  443. if ($modified) {
  444. $row['size'] = strlen($row['carddata']);
  445. }
  446. $cards[] = $row;
  447. }
  448. $result->closeCursor();
  449. return $cards;
  450. }
  451. /**
  452. * Returns a specific card.
  453. *
  454. * The same set of properties must be returned as with getCards. The only
  455. * exception is that 'carddata' is absolutely required.
  456. *
  457. * If the card does not exist, you must return false.
  458. *
  459. * @param mixed $addressBookId
  460. * @param string $cardUri
  461. * @return array
  462. */
  463. public function getCard($addressBookId, $cardUri) {
  464. $query = $this->db->getQueryBuilder();
  465. $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid'])
  466. ->from($this->dbCardsTable)
  467. ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)))
  468. ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($cardUri)))
  469. ->setMaxResults(1);
  470. $result = $query->execute();
  471. $row = $result->fetch();
  472. if (!$row) {
  473. return false;
  474. }
  475. $row['etag'] = '"' . $row['etag'] . '"';
  476. $modified = false;
  477. $row['carddata'] = $this->readBlob($row['carddata'], $modified);
  478. if ($modified) {
  479. $row['size'] = strlen($row['carddata']);
  480. }
  481. return $row;
  482. }
  483. /**
  484. * Returns a list of cards.
  485. *
  486. * This method should work identical to getCard, but instead return all the
  487. * cards in the list as an array.
  488. *
  489. * If the backend supports this, it may allow for some speed-ups.
  490. *
  491. * @param mixed $addressBookId
  492. * @param string[] $uris
  493. * @return array
  494. */
  495. public function getMultipleCards($addressBookId, array $uris) {
  496. if (empty($uris)) {
  497. return [];
  498. }
  499. $chunks = array_chunk($uris, 100);
  500. $cards = [];
  501. $query = $this->db->getQueryBuilder();
  502. $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid'])
  503. ->from($this->dbCardsTable)
  504. ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)))
  505. ->andWhere($query->expr()->in('uri', $query->createParameter('uri')));
  506. foreach ($chunks as $uris) {
  507. $query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY);
  508. $result = $query->execute();
  509. while ($row = $result->fetch()) {
  510. $row['etag'] = '"' . $row['etag'] . '"';
  511. $modified = false;
  512. $row['carddata'] = $this->readBlob($row['carddata'], $modified);
  513. if ($modified) {
  514. $row['size'] = strlen($row['carddata']);
  515. }
  516. $cards[] = $row;
  517. }
  518. $result->closeCursor();
  519. }
  520. return $cards;
  521. }
  522. /**
  523. * Creates a new card.
  524. *
  525. * The addressbook id will be passed as the first argument. This is the
  526. * same id as it is returned from the getAddressBooksForUser method.
  527. *
  528. * The cardUri is a base uri, and doesn't include the full path. The
  529. * cardData argument is the vcard body, and is passed as a string.
  530. *
  531. * It is possible to return an ETag from this method. This ETag is for the
  532. * newly created resource, and must be enclosed with double quotes (that
  533. * is, the string itself must contain the double quotes).
  534. *
  535. * You should only return the ETag if you store the carddata as-is. If a
  536. * subsequent GET request on the same card does not have the same body,
  537. * byte-by-byte and you did return an ETag here, clients tend to get
  538. * confused.
  539. *
  540. * If you don't return an ETag, you can just return null.
  541. *
  542. * @param mixed $addressBookId
  543. * @param string $cardUri
  544. * @param string $cardData
  545. * @return string
  546. */
  547. public function createCard($addressBookId, $cardUri, $cardData) {
  548. $etag = md5($cardData);
  549. $uid = $this->getUID($cardData);
  550. $q = $this->db->getQueryBuilder();
  551. $q->select('uid')
  552. ->from($this->dbCardsTable)
  553. ->where($q->expr()->eq('addressbookid', $q->createNamedParameter($addressBookId)))
  554. ->andWhere($q->expr()->eq('uid', $q->createNamedParameter($uid)))
  555. ->setMaxResults(1);
  556. $result = $q->execute();
  557. $count = (bool) $result->fetchColumn();
  558. $result->closeCursor();
  559. if ($count) {
  560. throw new \Sabre\DAV\Exception\BadRequest('VCard object with uid already exists in this addressbook collection.');
  561. }
  562. $query = $this->db->getQueryBuilder();
  563. $query->insert('cards')
  564. ->values([
  565. 'carddata' => $query->createNamedParameter($cardData, IQueryBuilder::PARAM_LOB),
  566. 'uri' => $query->createNamedParameter($cardUri),
  567. 'lastmodified' => $query->createNamedParameter(time()),
  568. 'addressbookid' => $query->createNamedParameter($addressBookId),
  569. 'size' => $query->createNamedParameter(strlen($cardData)),
  570. 'etag' => $query->createNamedParameter($etag),
  571. 'uid' => $query->createNamedParameter($uid),
  572. ])
  573. ->execute();
  574. $this->addChange($addressBookId, $cardUri, 1);
  575. $this->updateProperties($addressBookId, $cardUri, $cardData);
  576. $this->dispatcher->dispatch('\OCA\DAV\CardDAV\CardDavBackend::createCard',
  577. new GenericEvent(null, [
  578. 'addressBookId' => $addressBookId,
  579. 'cardUri' => $cardUri,
  580. 'cardData' => $cardData]));
  581. return '"' . $etag . '"';
  582. }
  583. /**
  584. * Updates a card.
  585. *
  586. * The addressbook id will be passed as the first argument. This is the
  587. * same id as it is returned from the getAddressBooksForUser method.
  588. *
  589. * The cardUri is a base uri, and doesn't include the full path. The
  590. * cardData argument is the vcard body, and is passed as a string.
  591. *
  592. * It is possible to return an ETag from this method. This ETag should
  593. * match that of the updated resource, and must be enclosed with double
  594. * quotes (that is: the string itself must contain the actual quotes).
  595. *
  596. * You should only return the ETag if you store the carddata as-is. If a
  597. * subsequent GET request on the same card does not have the same body,
  598. * byte-by-byte and you did return an ETag here, clients tend to get
  599. * confused.
  600. *
  601. * If you don't return an ETag, you can just return null.
  602. *
  603. * @param mixed $addressBookId
  604. * @param string $cardUri
  605. * @param string $cardData
  606. * @return string
  607. */
  608. public function updateCard($addressBookId, $cardUri, $cardData) {
  609. $uid = $this->getUID($cardData);
  610. $etag = md5($cardData);
  611. $query = $this->db->getQueryBuilder();
  612. $query->update($this->dbCardsTable)
  613. ->set('carddata', $query->createNamedParameter($cardData, IQueryBuilder::PARAM_LOB))
  614. ->set('lastmodified', $query->createNamedParameter(time()))
  615. ->set('size', $query->createNamedParameter(strlen($cardData)))
  616. ->set('etag', $query->createNamedParameter($etag))
  617. ->set('uid', $query->createNamedParameter($uid))
  618. ->where($query->expr()->eq('uri', $query->createNamedParameter($cardUri)))
  619. ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)))
  620. ->execute();
  621. $this->addChange($addressBookId, $cardUri, 2);
  622. $this->updateProperties($addressBookId, $cardUri, $cardData);
  623. $this->dispatcher->dispatch('\OCA\DAV\CardDAV\CardDavBackend::updateCard',
  624. new GenericEvent(null, [
  625. 'addressBookId' => $addressBookId,
  626. 'cardUri' => $cardUri,
  627. 'cardData' => $cardData]));
  628. return '"' . $etag . '"';
  629. }
  630. /**
  631. * Deletes a card
  632. *
  633. * @param mixed $addressBookId
  634. * @param string $cardUri
  635. * @return bool
  636. */
  637. public function deleteCard($addressBookId, $cardUri) {
  638. try {
  639. $cardId = $this->getCardId($addressBookId, $cardUri);
  640. } catch (\InvalidArgumentException $e) {
  641. $cardId = null;
  642. }
  643. $query = $this->db->getQueryBuilder();
  644. $ret = $query->delete($this->dbCardsTable)
  645. ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)))
  646. ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($cardUri)))
  647. ->execute();
  648. $this->addChange($addressBookId, $cardUri, 3);
  649. $this->dispatcher->dispatch('\OCA\DAV\CardDAV\CardDavBackend::deleteCard',
  650. new GenericEvent(null, [
  651. 'addressBookId' => $addressBookId,
  652. 'cardUri' => $cardUri]));
  653. if ($ret === 1) {
  654. if ($cardId !== null) {
  655. $this->purgeProperties($addressBookId, $cardId);
  656. }
  657. return true;
  658. }
  659. return false;
  660. }
  661. /**
  662. * The getChanges method returns all the changes that have happened, since
  663. * the specified syncToken in the specified address book.
  664. *
  665. * This function should return an array, such as the following:
  666. *
  667. * [
  668. * 'syncToken' => 'The current synctoken',
  669. * 'added' => [
  670. * 'new.txt',
  671. * ],
  672. * 'modified' => [
  673. * 'modified.txt',
  674. * ],
  675. * 'deleted' => [
  676. * 'foo.php.bak',
  677. * 'old.txt'
  678. * ]
  679. * ];
  680. *
  681. * The returned syncToken property should reflect the *current* syncToken
  682. * of the calendar, as reported in the {http://sabredav.org/ns}sync-token
  683. * property. This is needed here too, to ensure the operation is atomic.
  684. *
  685. * If the $syncToken argument is specified as null, this is an initial
  686. * sync, and all members should be reported.
  687. *
  688. * The modified property is an array of nodenames that have changed since
  689. * the last token.
  690. *
  691. * The deleted property is an array with nodenames, that have been deleted
  692. * from collection.
  693. *
  694. * The $syncLevel argument is basically the 'depth' of the report. If it's
  695. * 1, you only have to report changes that happened only directly in
  696. * immediate descendants. If it's 2, it should also include changes from
  697. * the nodes below the child collections. (grandchildren)
  698. *
  699. * The $limit argument allows a client to specify how many results should
  700. * be returned at most. If the limit is not specified, it should be treated
  701. * as infinite.
  702. *
  703. * If the limit (infinite or not) is higher than you're willing to return,
  704. * you should throw a Sabre\DAV\Exception\TooMuchMatches() exception.
  705. *
  706. * If the syncToken is expired (due to data cleanup) or unknown, you must
  707. * return null.
  708. *
  709. * The limit is 'suggestive'. You are free to ignore it.
  710. *
  711. * @param string $addressBookId
  712. * @param string $syncToken
  713. * @param int $syncLevel
  714. * @param int $limit
  715. * @return array
  716. */
  717. public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, $limit = null) {
  718. // Current synctoken
  719. $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*addressbooks` WHERE `id` = ?');
  720. $stmt->execute([ $addressBookId ]);
  721. $currentToken = $stmt->fetchColumn(0);
  722. if (is_null($currentToken)) {
  723. return null;
  724. }
  725. $result = [
  726. 'syncToken' => $currentToken,
  727. 'added' => [],
  728. 'modified' => [],
  729. 'deleted' => [],
  730. ];
  731. if ($syncToken) {
  732. $query = "SELECT `uri`, `operation` FROM `*PREFIX*addressbookchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `addressbookid` = ? ORDER BY `synctoken`";
  733. if ($limit>0) {
  734. $query .= " LIMIT " . (int)$limit;
  735. }
  736. // Fetching all changes
  737. $stmt = $this->db->prepare($query);
  738. $stmt->execute([$syncToken, $currentToken, $addressBookId]);
  739. $changes = [];
  740. // This loop ensures that any duplicates are overwritten, only the
  741. // last change on a node is relevant.
  742. while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
  743. $changes[$row['uri']] = $row['operation'];
  744. }
  745. foreach ($changes as $uri => $operation) {
  746. switch ($operation) {
  747. case 1:
  748. $result['added'][] = $uri;
  749. break;
  750. case 2:
  751. $result['modified'][] = $uri;
  752. break;
  753. case 3:
  754. $result['deleted'][] = $uri;
  755. break;
  756. }
  757. }
  758. } else {
  759. // No synctoken supplied, this is the initial sync.
  760. $query = "SELECT `uri` FROM `*PREFIX*cards` WHERE `addressbookid` = ?";
  761. $stmt = $this->db->prepare($query);
  762. $stmt->execute([$addressBookId]);
  763. $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN);
  764. }
  765. return $result;
  766. }
  767. /**
  768. * Adds a change record to the addressbookchanges table.
  769. *
  770. * @param mixed $addressBookId
  771. * @param string $objectUri
  772. * @param int $operation 1 = add, 2 = modify, 3 = delete
  773. * @return void
  774. */
  775. protected function addChange($addressBookId, $objectUri, $operation) {
  776. $sql = 'INSERT INTO `*PREFIX*addressbookchanges`(`uri`, `synctoken`, `addressbookid`, `operation`) SELECT ?, `synctoken`, ?, ? FROM `*PREFIX*addressbooks` WHERE `id` = ?';
  777. $stmt = $this->db->prepare($sql);
  778. $stmt->execute([
  779. $objectUri,
  780. $addressBookId,
  781. $operation,
  782. $addressBookId
  783. ]);
  784. $stmt = $this->db->prepare('UPDATE `*PREFIX*addressbooks` SET `synctoken` = `synctoken` + 1 WHERE `id` = ?');
  785. $stmt->execute([
  786. $addressBookId
  787. ]);
  788. }
  789. /**
  790. * @param resource|string $cardData
  791. * @param bool $modified
  792. * @return string
  793. */
  794. private function readBlob($cardData, &$modified=false) {
  795. if (is_resource($cardData)) {
  796. $cardData = stream_get_contents($cardData);
  797. }
  798. $cardDataArray = explode("\r\n", $cardData);
  799. $cardDataFiltered = [];
  800. $removingPhoto = false;
  801. foreach ($cardDataArray as $line) {
  802. if (strpos($line, 'PHOTO:data:') === 0
  803. && strpos($line, 'PHOTO:data:image/') !== 0) {
  804. // Filter out PHOTO data of non-images
  805. $removingPhoto = true;
  806. $modified = true;
  807. continue;
  808. }
  809. if ($removingPhoto) {
  810. if (strpos($line, ' ') === 0) {
  811. continue;
  812. }
  813. // No leading space means this is a new property
  814. $removingPhoto = false;
  815. }
  816. $cardDataFiltered[] = $line;
  817. }
  818. return implode("\r\n", $cardDataFiltered);
  819. }
  820. /**
  821. * @param IShareable $shareable
  822. * @param string[] $add
  823. * @param string[] $remove
  824. */
  825. public function updateShares(IShareable $shareable, $add, $remove) {
  826. $this->sharingBackend->updateShares($shareable, $add, $remove);
  827. }
  828. /**
  829. * search contact
  830. *
  831. * @param int $addressBookId
  832. * @param string $pattern which should match within the $searchProperties
  833. * @param array $searchProperties defines the properties within the query pattern should match
  834. * @param array $options = array() to define the search behavior
  835. * - 'escape_like_param' - If set to false wildcards _ and % are not escaped, otherwise they are
  836. * @return array an array of contacts which are arrays of key-value-pairs
  837. */
  838. public function search($addressBookId, $pattern, $searchProperties, $options = []) {
  839. $query = $this->db->getQueryBuilder();
  840. $query2 = $this->db->getQueryBuilder();
  841. $query2->selectDistinct('cp.cardid')->from($this->dbCardsPropertiesTable, 'cp');
  842. $query2->andWhere($query2->expr()->eq('cp.addressbookid', $query->createNamedParameter($addressBookId)));
  843. $or = $query2->expr()->orX();
  844. foreach ($searchProperties as $property) {
  845. $or->add($query2->expr()->eq('cp.name', $query->createNamedParameter($property)));
  846. }
  847. $query2->andWhere($or);
  848. // No need for like when the pattern is empty
  849. if ('' !== $pattern) {
  850. if (\array_key_exists('escape_like_param', $options) && $options['escape_like_param'] === false) {
  851. $query2->andWhere($query2->expr()->ilike('cp.value', $query->createNamedParameter($pattern)));
  852. } else {
  853. $query2->andWhere($query2->expr()->ilike('cp.value', $query->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%')));
  854. }
  855. }
  856. // // FIXME Broken on MySQL: SQLSTATE[42000]: Syntax error or access violation: 1235 This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
  857. // // FIXME Should use 2 queries instead
  858. // if (isset($options['limit'])) {
  859. // $query2->setMaxResults($options['limit']);
  860. // }
  861. // if (isset($options['offset'])) {
  862. // $query2->setFirstResult($options['offset']);
  863. // }
  864. $query->select('c.carddata', 'c.uri')->from($this->dbCardsTable, 'c')
  865. ->where($query->expr()->in('c.id', $query->createFunction($query2->getSQL())));
  866. $result = $query->execute();
  867. $cards = $result->fetchAll();
  868. $result->closeCursor();
  869. return array_map(function ($array) {
  870. $modified = false;
  871. $array['carddata'] = $this->readBlob($array['carddata'], $modified);
  872. if ($modified) {
  873. $array['size'] = strlen($array['carddata']);
  874. }
  875. return $array;
  876. }, $cards);
  877. }
  878. /**
  879. * @param int $bookId
  880. * @param string $name
  881. * @return array
  882. */
  883. public function collectCardProperties($bookId, $name) {
  884. $query = $this->db->getQueryBuilder();
  885. $result = $query->selectDistinct('value')
  886. ->from($this->dbCardsPropertiesTable)
  887. ->where($query->expr()->eq('name', $query->createNamedParameter($name)))
  888. ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($bookId)))
  889. ->execute();
  890. $all = $result->fetchAll(PDO::FETCH_COLUMN);
  891. $result->closeCursor();
  892. return $all;
  893. }
  894. /**
  895. * get URI from a given contact
  896. *
  897. * @param int $id
  898. * @return string
  899. */
  900. public function getCardUri($id) {
  901. $query = $this->db->getQueryBuilder();
  902. $query->select('uri')->from($this->dbCardsTable)
  903. ->where($query->expr()->eq('id', $query->createParameter('id')))
  904. ->setParameter('id', $id);
  905. $result = $query->execute();
  906. $uri = $result->fetch();
  907. $result->closeCursor();
  908. if (!isset($uri['uri'])) {
  909. throw new \InvalidArgumentException('Card does not exists: ' . $id);
  910. }
  911. return $uri['uri'];
  912. }
  913. /**
  914. * return contact with the given URI
  915. *
  916. * @param int $addressBookId
  917. * @param string $uri
  918. * @returns array
  919. */
  920. public function getContact($addressBookId, $uri) {
  921. $result = [];
  922. $query = $this->db->getQueryBuilder();
  923. $query->select('*')->from($this->dbCardsTable)
  924. ->where($query->expr()->eq('uri', $query->createNamedParameter($uri)))
  925. ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)));
  926. $queryResult = $query->execute();
  927. $contact = $queryResult->fetch();
  928. $queryResult->closeCursor();
  929. if (is_array($contact)) {
  930. $modified = false;
  931. $contact['etag'] = '"' . $contact['etag'] . '"';
  932. $contact['carddata'] = $this->readBlob($contact['carddata'], $modified);
  933. if ($modified) {
  934. $contact['size'] = strlen($contact['carddata']);
  935. }
  936. $result = $contact;
  937. }
  938. return $result;
  939. }
  940. /**
  941. * Returns the list of people whom this address book is shared with.
  942. *
  943. * Every element in this array should have the following properties:
  944. * * href - Often a mailto: address
  945. * * commonName - Optional, for example a first + last name
  946. * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
  947. * * readOnly - boolean
  948. * * summary - Optional, a description for the share
  949. *
  950. * @return array
  951. */
  952. public function getShares($addressBookId) {
  953. return $this->sharingBackend->getShares($addressBookId);
  954. }
  955. /**
  956. * update properties table
  957. *
  958. * @param int $addressBookId
  959. * @param string $cardUri
  960. * @param string $vCardSerialized
  961. */
  962. protected function updateProperties($addressBookId, $cardUri, $vCardSerialized) {
  963. $cardId = $this->getCardId($addressBookId, $cardUri);
  964. $vCard = $this->readCard($vCardSerialized);
  965. $this->purgeProperties($addressBookId, $cardId);
  966. $query = $this->db->getQueryBuilder();
  967. $query->insert($this->dbCardsPropertiesTable)
  968. ->values(
  969. [
  970. 'addressbookid' => $query->createNamedParameter($addressBookId),
  971. 'cardid' => $query->createNamedParameter($cardId),
  972. 'name' => $query->createParameter('name'),
  973. 'value' => $query->createParameter('value'),
  974. 'preferred' => $query->createParameter('preferred')
  975. ]
  976. );
  977. foreach ($vCard->children() as $property) {
  978. if (!in_array($property->name, self::$indexProperties)) {
  979. continue;
  980. }
  981. $preferred = 0;
  982. foreach ($property->parameters as $parameter) {
  983. if ($parameter->name === 'TYPE' && strtoupper($parameter->getValue()) === 'PREF') {
  984. $preferred = 1;
  985. break;
  986. }
  987. }
  988. $query->setParameter('name', $property->name);
  989. $query->setParameter('value', mb_substr($property->getValue(), 0, 254));
  990. $query->setParameter('preferred', $preferred);
  991. $query->execute();
  992. }
  993. }
  994. /**
  995. * read vCard data into a vCard object
  996. *
  997. * @param string $cardData
  998. * @return VCard
  999. */
  1000. protected function readCard($cardData) {
  1001. return Reader::read($cardData);
  1002. }
  1003. /**
  1004. * delete all properties from a given card
  1005. *
  1006. * @param int $addressBookId
  1007. * @param int $cardId
  1008. */
  1009. protected function purgeProperties($addressBookId, $cardId) {
  1010. $query = $this->db->getQueryBuilder();
  1011. $query->delete($this->dbCardsPropertiesTable)
  1012. ->where($query->expr()->eq('cardid', $query->createNamedParameter($cardId)))
  1013. ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)));
  1014. $query->execute();
  1015. }
  1016. /**
  1017. * get ID from a given contact
  1018. *
  1019. * @param int $addressBookId
  1020. * @param string $uri
  1021. * @return int
  1022. */
  1023. protected function getCardId($addressBookId, $uri) {
  1024. $query = $this->db->getQueryBuilder();
  1025. $query->select('id')->from($this->dbCardsTable)
  1026. ->where($query->expr()->eq('uri', $query->createNamedParameter($uri)))
  1027. ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)));
  1028. $result = $query->execute();
  1029. $cardIds = $result->fetch();
  1030. $result->closeCursor();
  1031. if (!isset($cardIds['id'])) {
  1032. throw new \InvalidArgumentException('Card does not exists: ' . $uri);
  1033. }
  1034. return (int)$cardIds['id'];
  1035. }
  1036. /**
  1037. * For shared address books the sharee is set in the ACL of the address book
  1038. * @param $addressBookId
  1039. * @param $acl
  1040. * @return array
  1041. */
  1042. public function applyShareAcl($addressBookId, $acl) {
  1043. return $this->sharingBackend->applyShareAcl($addressBookId, $acl);
  1044. }
  1045. private function convertPrincipal($principalUri, $toV2) {
  1046. if ($this->principalBackend->getPrincipalPrefix() === 'principals') {
  1047. list(, $name) = \Sabre\Uri\split($principalUri);
  1048. if ($toV2 === true) {
  1049. return "principals/users/$name";
  1050. }
  1051. return "principals/$name";
  1052. }
  1053. return $principalUri;
  1054. }
  1055. private function addOwnerPrincipal(&$addressbookInfo) {
  1056. $ownerPrincipalKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal';
  1057. $displaynameKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname';
  1058. if (isset($addressbookInfo[$ownerPrincipalKey])) {
  1059. $uri = $addressbookInfo[$ownerPrincipalKey];
  1060. } else {
  1061. $uri = $addressbookInfo['principaluri'];
  1062. }
  1063. $principalInformation = $this->principalBackend->getPrincipalByPath($uri);
  1064. if (isset($principalInformation['{DAV:}displayname'])) {
  1065. $addressbookInfo[$displaynameKey] = $principalInformation['{DAV:}displayname'];
  1066. }
  1067. }
  1068. /**
  1069. * Extract UID from vcard
  1070. *
  1071. * @param string $cardData the vcard raw data
  1072. * @return string the uid
  1073. * @throws BadRequest if no UID is available
  1074. */
  1075. private function getUID($cardData) {
  1076. if ($cardData != '') {
  1077. $vCard = Reader::read($cardData);
  1078. if ($vCard->UID) {
  1079. $uid = $vCard->UID->getValue();
  1080. return $uid;
  1081. }
  1082. // should already be handled, but just in case
  1083. throw new BadRequest('vCards on CardDAV servers MUST have a UID property');
  1084. }
  1085. // should already be handled, but just in case
  1086. throw new BadRequest('vCard can not be empty');
  1087. }
  1088. }