Skip to content

Commit 89b158d

Browse files
committed
refactor(dav): various modernizations of CardDAV SyncService
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
1 parent bd16299 commit 89b158d

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

apps/dav/lib/CardDAV/SyncService.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
*/
3131
namespace OCA\DAV\CardDAV;
3232

33-
use OC\Accounts\AccountManager;
3433
use OCP\AppFramework\Db\TTransactional;
3534
use OCP\AppFramework\Http;
3635
use OCP\IDBConnection;
@@ -42,6 +41,7 @@
4241
use Sabre\DAV\Xml\Service;
4342
use Sabre\HTTP\ClientHttpException;
4443
use Sabre\VObject\Reader;
44+
use Sabre\Xml\ParseException;
4545
use function is_null;
4646

4747
class SyncService {
@@ -181,6 +181,9 @@ protected function download(string $url, string $userName, string $sharedSecret,
181181
return $client->request('GET', $resourcePath);
182182
}
183183

184+
/**
185+
* @throws \DOMException
186+
*/
184187
private function buildSyncCollectionRequestBody(?string $syncToken): string {
185188
$dom = new \DOMDocument('1.0', 'UTF-8');
186189
$dom->formatOutput = true;
@@ -201,9 +204,9 @@ private function buildSyncCollectionRequestBody(?string $syncToken): string {
201204
/**
202205
* @param string $body
203206
* @return array
204-
* @throws \Sabre\Xml\ParseException
207+
* @throws ParseException
205208
*/
206-
private function parseMultiStatus($body) {
209+
private function parseMultiStatus(string $body): array {
207210
$xml = new Service();
208211

209212
/** @var MultiStatus $multiStatus */
@@ -217,9 +220,6 @@ private function parseMultiStatus($body) {
217220
return ['response' => $result, 'token' => $multiStatus->getSyncToken()];
218221
}
219222

220-
/**
221-
* @param IUser $user
222-
*/
223223
public function updateUser(IUser $user): void {
224224
$systemAddressBook = $this->getLocalSystemAddressBook();
225225
$addressBookId = $systemAddressBook['id'];
@@ -228,13 +228,12 @@ public function updateUser(IUser $user): void {
228228
if ($user->isEnabled()) {
229229
$this->atomic(function() use ($addressBookId, $cardId, $user) {
230230
$card = $this->backend->getCard($addressBookId, $cardId);
231+
$vCard = $this->converter->createCardFromUser($user);
231232
if ($card === false) {
232-
$vCard = $this->converter->createCardFromUser($user);
233233
if ($vCard !== null) {
234234
$this->backend->createCard($addressBookId, $cardId, $vCard->serialize(), false);
235235
}
236236
} else {
237-
$vCard = $this->converter->createCardFromUser($user);
238237
if (is_null($vCard)) {
239238
$this->backend->deleteCard($addressBookId, $cardId);
240239
} else {
@@ -247,21 +246,15 @@ public function updateUser(IUser $user): void {
247246
}
248247
}
249248

250-
/**
251-
* @param IUser|string $userOrCardId
252-
*/
253-
public function deleteUser($userOrCardId) {
249+
public function deleteUser(IUser|string $userOrCardId): void {
254250
$systemAddressBook = $this->getLocalSystemAddressBook();
255251
if ($userOrCardId instanceof IUser) {
256252
$userOrCardId = self::getCardUri($userOrCardId);
257253
}
258254
$this->backend->deleteCard($systemAddressBook['id'], $userOrCardId);
259255
}
260256

261-
/**
262-
* @return array|null
263-
*/
264-
public function getLocalSystemAddressBook() {
257+
public function getLocalSystemAddressBook(): ?array {
265258
if (is_null($this->localSystemAddressBook)) {
266259
$systemPrincipal = "principals/system/system";
267260
$this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [
@@ -272,7 +265,7 @@ public function getLocalSystemAddressBook() {
272265
return $this->localSystemAddressBook;
273266
}
274267

275-
public function syncInstance(\Closure $progressCallback = null) {
268+
public function syncInstance(\Closure $progressCallback = null): void {
276269
$systemAddressBook = $this->getLocalSystemAddressBook();
277270
$this->userManager->callForAllUsers(function ($user) use ($systemAddressBook, $progressCallback) {
278271
$this->updateUser($user);

0 commit comments

Comments
 (0)