Completed
Pull Request — master (#3770)
by Thomas
25:54
created
apps/dav/lib/CardDAV/CardDavBackend.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 			->from('addressbooks')
115 115
 			->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));
116 116
 
117
-		return (int)$query->execute()->fetchColumn();
117
+		return (int) $query->execute()->fetchColumn();
118 118
 	}
119 119
 
120 120
 	/**
@@ -145,22 +145,22 @@  discard block
 block discarded – undo
145 145
 		$addressBooks = [];
146 146
 
147 147
 		$result = $query->execute();
148
-		while($row = $result->fetch()) {
148
+		while ($row = $result->fetch()) {
149 149
 			$addressBooks[$row['id']] = [
150 150
 				'id'  => $row['id'],
151 151
 				'uri' => $row['uri'],
152 152
 				'principaluri' => $this->convertPrincipal($row['principaluri'], false),
153 153
 				'{DAV:}displayname' => $row['displayname'],
154
-				'{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'],
154
+				'{'.Plugin::NS_CARDDAV.'}addressbook-description' => $row['description'],
155 155
 				'{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
156
-				'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
156
+				'{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0',
157 157
 			];
158 158
 		}
159 159
 		$result->closeCursor();
160 160
 
161 161
 		// query for shared calendars
162 162
 		$principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true);
163
-		$principals[]= $principalUri;
163
+		$principals[] = $principalUri;
164 164
 
165 165
 		$query = $this->db->getQueryBuilder();
166 166
 		$result = $query->select(['a.id', 'a.uri', 'a.displayname', 'a.principaluri', 'a.description', 'a.synctoken', 's.access'])
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
 			->setParameter('principaluri', $principals, IQueryBuilder::PARAM_STR_ARRAY)
173 173
 			->execute();
174 174
 
175
-		$readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only';
176
-		while($row = $result->fetch()) {
175
+		$readOnlyPropertyName = '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only';
176
+		while ($row = $result->fetch()) {
177 177
 			$readOnly = (int) $row['access'] === Backend::ACCESS_READ;
178 178
 			if (isset($addressBooks[$row['id']])) {
179 179
 				if ($readOnly) {
@@ -188,18 +188,18 @@  discard block
 block discarded – undo
188 188
 			}
189 189
 
190 190
 			list(, $name) = URLUtil::splitPath($row['principaluri']);
191
-			$uri = $row['uri'] . '_shared_by_' . $name;
192
-			$displayName = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')';
191
+			$uri = $row['uri'].'_shared_by_'.$name;
192
+			$displayName = $row['displayname'].' ('.$this->getUserDisplayName($name).')';
193 193
 
194 194
 			$addressBooks[$row['id']] = [
195 195
 				'id'  => $row['id'],
196 196
 				'uri' => $uri,
197 197
 				'principaluri' => $principalUriOriginal,
198 198
 				'{DAV:}displayname' => $displayName,
199
-				'{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'],
199
+				'{'.Plugin::NS_CARDDAV.'}addressbook-description' => $row['description'],
200 200
 				'{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
201
-				'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
202
-				'{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'],
201
+				'{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0',
202
+				'{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $row['principaluri'],
203 203
 				$readOnlyPropertyName => $readOnly,
204 204
 			];
205 205
 		}
@@ -219,15 +219,15 @@  discard block
 block discarded – undo
219 219
 		$addressBooks = [];
220 220
 
221 221
 		$result = $query->execute();
222
-		while($row = $result->fetch()) {
222
+		while ($row = $result->fetch()) {
223 223
 			$addressBooks[$row['id']] = [
224 224
 				'id'  => $row['id'],
225 225
 				'uri' => $row['uri'],
226 226
 				'principaluri' => $this->convertPrincipal($row['principaluri'], false),
227 227
 				'{DAV:}displayname' => $row['displayname'],
228
-				'{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'],
228
+				'{'.Plugin::NS_CARDDAV.'}addressbook-description' => $row['description'],
229 229
 				'{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
230
-				'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
230
+				'{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0',
231 231
 			];
232 232
 		}
233 233
 		$result->closeCursor();
@@ -270,9 +270,9 @@  discard block
 block discarded – undo
270 270
 			'uri' => $row['uri'],
271 271
 			'principaluri' => $row['principaluri'],
272 272
 			'{DAV:}displayname' => $row['displayname'],
273
-			'{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'],
273
+			'{'.Plugin::NS_CARDDAV.'}addressbook-description' => $row['description'],
274 274
 			'{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
275
-			'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
275
+			'{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0',
276 276
 		];
277 277
 	}
278 278
 
@@ -300,9 +300,9 @@  discard block
 block discarded – undo
300 300
 				'uri' => $row['uri'],
301 301
 				'principaluri' => $row['principaluri'],
302 302
 				'{DAV:}displayname' => $row['displayname'],
303
-				'{' . Plugin::NS_CARDDAV . '}addressbook-description' => $row['description'],
303
+				'{'.Plugin::NS_CARDDAV.'}addressbook-description' => $row['description'],
304 304
 				'{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
305
-				'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
305
+				'{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0',
306 306
 			];
307 307
 	}
308 308
 
@@ -325,19 +325,19 @@  discard block
 block discarded – undo
325 325
 	function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch) {
326 326
 		$supportedProperties = [
327 327
 			'{DAV:}displayname',
328
-			'{' . Plugin::NS_CARDDAV . '}addressbook-description',
328
+			'{'.Plugin::NS_CARDDAV.'}addressbook-description',
329 329
 		];
330 330
 
331 331
 		$propPatch->handle($supportedProperties, function($mutations) use ($addressBookId) {
332 332
 
333 333
 			$updates = [];
334
-			foreach($mutations as $property=>$newValue) {
334
+			foreach ($mutations as $property=>$newValue) {
335 335
 
336
-				switch($property) {
336
+				switch ($property) {
337 337
 					case '{DAV:}displayname' :
338 338
 						$updates['displayname'] = $newValue;
339 339
 						break;
340
-					case '{' . Plugin::NS_CARDDAV . '}addressbook-description' :
340
+					case '{'.Plugin::NS_CARDDAV.'}addressbook-description' :
341 341
 						$updates['description'] = $newValue;
342 342
 						break;
343 343
 				}
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 			$query = $this->db->getQueryBuilder();
346 346
 			$query->update('addressbooks');
347 347
 
348
-			foreach($updates as $key=>$value) {
348
+			foreach ($updates as $key=>$value) {
349 349
 				$query->set($key, $query->createNamedParameter($value));
350 350
 			}
351 351
 			$query->where($query->expr()->eq('id', $query->createNamedParameter($addressBookId)))
@@ -376,24 +376,24 @@  discard block
 block discarded – undo
376 376
 			'synctoken' => 1
377 377
 		];
378 378
 
379
-		foreach($properties as $property=>$newValue) {
379
+		foreach ($properties as $property=>$newValue) {
380 380
 
381
-			switch($property) {
381
+			switch ($property) {
382 382
 				case '{DAV:}displayname' :
383 383
 					$values['displayname'] = $newValue;
384 384
 					break;
385
-				case '{' . Plugin::NS_CARDDAV . '}addressbook-description' :
385
+				case '{'.Plugin::NS_CARDDAV.'}addressbook-description' :
386 386
 					$values['description'] = $newValue;
387 387
 					break;
388 388
 				default :
389
-					throw new BadRequest('Unknown property: ' . $property);
389
+					throw new BadRequest('Unknown property: '.$property);
390 390
 			}
391 391
 
392 392
 		}
393 393
 
394 394
 		// Fallback to make sure the displayname is set. Some clients may refuse
395 395
 		// to work with addressbooks not having a displayname.
396
-		if(is_null($values['displayname'])) {
396
+		if (is_null($values['displayname'])) {
397 397
 			$values['displayname'] = $url;
398 398
 		}
399 399
 
@@ -471,8 +471,8 @@  discard block
 block discarded – undo
471 471
 		$cards = [];
472 472
 
473 473
 		$result = $query->execute();
474
-		while($row = $result->fetch()) {
475
-			$row['etag'] = '"' . $row['etag'] . '"';
474
+		while ($row = $result->fetch()) {
475
+			$row['etag'] = '"'.$row['etag'].'"';
476 476
 			$row['carddata'] = $this->readBlob($row['carddata']);
477 477
 			$cards[] = $row;
478 478
 		}
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
 		if (!$row) {
507 507
 			return false;
508 508
 		}
509
-		$row['etag'] = '"' . $row['etag'] . '"';
509
+		$row['etag'] = '"'.$row['etag'].'"';
510 510
 		$row['carddata'] = $this->readBlob($row['carddata']);
511 511
 
512 512
 		return $row;
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
 			$result = $query->execute();
544 544
 
545 545
 			while ($row = $result->fetch()) {
546
-				$row['etag'] = '"' . $row['etag'] . '"';
546
+				$row['etag'] = '"'.$row['etag'].'"';
547 547
 				$row['carddata'] = $this->readBlob($row['carddata']);
548 548
 				$cards[] = $row;
549 549
 			}
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
 					'cardData' => $cardData]));
604 604
 		}
605 605
 
606
-		return '"' . $etag . '"';
606
+		return '"'.$etag.'"';
607 607
 	}
608 608
 
609 609
 	/**
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
 					'cardData' => $cardData]));
656 656
 		}
657 657
 
658
-		return '"' . $etag . '"';
658
+		return '"'.$etag.'"';
659 659
 	}
660 660
 
661 661
 	/**
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
 	function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, $limit = null) {
756 756
 		// Current synctoken
757 757
 		$stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*addressbooks` WHERE `id` = ?');
758
-		$stmt->execute([ $addressBookId ]);
758
+		$stmt->execute([$addressBookId]);
759 759
 		$currentToken = $stmt->fetchColumn(0);
760 760
 
761 761
 		if (is_null($currentToken)) return null;
@@ -770,8 +770,8 @@  discard block
 block discarded – undo
770 770
 		if ($syncToken) {
771 771
 
772 772
 			$query = "SELECT `uri`, `operation` FROM `*PREFIX*addressbookchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `addressbookid` = ? ORDER BY `synctoken`";
773
-			if ($limit>0) {
774
-				$query .= " `LIMIT` " . (int)$limit;
773
+			if ($limit > 0) {
774
+				$query .= " `LIMIT` ".(int) $limit;
775 775
 			}
776 776
 
777 777
 			// Fetching all changes
@@ -782,15 +782,15 @@  discard block
 block discarded – undo
782 782
 
783 783
 			// This loop ensures that any duplicates are overwritten, only the
784 784
 			// last change on a node is relevant.
785
-			while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
785
+			while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
786 786
 
787 787
 				$changes[$row['uri']] = $row['operation'];
788 788
 
789 789
 			}
790 790
 
791
-			foreach($changes as $uri => $operation) {
791
+			foreach ($changes as $uri => $operation) {
792 792
 
793
-				switch($operation) {
793
+				switch ($operation) {
794 794
 					case 1:
795 795
 						$result['added'][] = $uri;
796 796
 						break;
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
 		$query = $this->db->getQueryBuilder();
867 867
 		$query2 = $this->db->getQueryBuilder();
868 868
 		$query2->selectDistinct('cp.cardid')->from($this->dbCardsPropertiesTable, 'cp');
869
-		$query2->andWhere($query2->expr()->ilike('cp.value', $query->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%')));
869
+		$query2->andWhere($query2->expr()->ilike('cp.value', $query->createNamedParameter('%'.$this->db->escapeLikeParameter($pattern).'%')));
870 870
 		foreach ($searchProperties as $property) {
871 871
 				$query2->expr()->orX($query2->expr()->eq('cp.name', $query->createNamedParameter($property)));
872 872
 		}
@@ -922,7 +922,7 @@  discard block
 block discarded – undo
922 922
 		$result->closeCursor();
923 923
 
924 924
 		if (!isset($uri['uri'])) {
925
-			throw new \InvalidArgumentException('Card does not exists: ' . $id);
925
+			throw new \InvalidArgumentException('Card does not exists: '.$id);
926 926
 		}
927 927
 
928 928
 		return $uri['uri'];
@@ -994,11 +994,11 @@  discard block
 block discarded – undo
994 994
 			);
995 995
 
996 996
 		foreach ($vCard->children() as $property) {
997
-			if(!in_array($property->name, self::$indexProperties)) {
997
+			if (!in_array($property->name, self::$indexProperties)) {
998 998
 				continue;
999 999
 			}
1000 1000
 			$preferred = 0;
1001
-			foreach($property->parameters as $parameter) {
1001
+			foreach ($property->parameters as $parameter) {
1002 1002
 				if ($parameter->name == 'TYPE' && strtoupper($parameter->getValue()) == 'PREF') {
1003 1003
 					$preferred = 1;
1004 1004
 					break;
@@ -1053,10 +1053,10 @@  discard block
 block discarded – undo
1053 1053
 		$result->closeCursor();
1054 1054
 
1055 1055
 		if (!isset($cardIds['id'])) {
1056
-			throw new \InvalidArgumentException('Card does not exists: ' . $uri);
1056
+			throw new \InvalidArgumentException('Card does not exists: '.$uri);
1057 1057
 		}
1058 1058
 
1059
-		return (int)$cardIds['id'];
1059
+		return (int) $cardIds['id'];
1060 1060
 	}
1061 1061
 
1062 1062
 	/**
Please login to merge, or discard this patch.