|
|
|
@ -75,6 +75,7 @@ class SyncService { |
|
|
|
/** |
|
|
|
* @param string $url |
|
|
|
* @param string $userName |
|
|
|
* @param string $addressBookUrl |
|
|
|
* @param string $sharedSecret |
|
|
|
* @param string $syncToken |
|
|
|
* @param int $targetBookId |
|
|
|
@ -83,14 +84,14 @@ class SyncService { |
|
|
|
* @return string |
|
|
|
* @throws \Exception |
|
|
|
*/ |
|
|
|
public function syncRemoteAddressBook($url, $userName, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) { |
|
|
|
public function syncRemoteAddressBook($url, $userName, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) { |
|
|
|
// 1. create addressbook
|
|
|
|
$book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookId, $targetProperties); |
|
|
|
$addressBookId = $book['id']; |
|
|
|
|
|
|
|
// 2. query changes
|
|
|
|
try { |
|
|
|
$response = $this->requestSyncReport($url, $userName, $sharedSecret, $syncToken); |
|
|
|
$response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken); |
|
|
|
} catch (ClientHttpException $ex) { |
|
|
|
if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
|
|
|
// remote server revoked access to the address book, remove it
|
|
|
|
@ -105,7 +106,7 @@ class SyncService { |
|
|
|
foreach ($response['response'] as $resource => $status) { |
|
|
|
$cardUri = basename($resource); |
|
|
|
if (isset($status[200])) { |
|
|
|
$vCard = $this->download($url, $sharedSecret, $resource); |
|
|
|
$vCard = $this->download($url, $userName, $sharedSecret, $resource); |
|
|
|
$existingCard = $this->backend->getCard($addressBookId, $cardUri); |
|
|
|
if ($existingCard === false) { |
|
|
|
$this->backend->createCard($addressBookId, $cardUri, $vCard['body']); |
|
|
|
@ -162,6 +163,7 @@ class SyncService { |
|
|
|
/** |
|
|
|
* @param string $url |
|
|
|
* @param string $userName |
|
|
|
* @param string $addressBookUrl |
|
|
|
* @param string $sharedSecret |
|
|
|
* @return Client |
|
|
|
*/ |
|
|
|
@ -185,31 +187,32 @@ class SyncService { |
|
|
|
/** |
|
|
|
* @param string $url |
|
|
|
* @param string $userName |
|
|
|
* @param string $addressBookUrl |
|
|
|
* @param string $sharedSecret |
|
|
|
* @param string $syncToken |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
protected function requestSyncReport($url, $userName, $sharedSecret, $syncToken) { |
|
|
|
$client = $this->getClient($url, $userName, $sharedSecret); |
|
|
|
protected function requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken) { |
|
|
|
$client = $this->getClient($url, $userName, $sharedSecret); |
|
|
|
|
|
|
|
$addressBookUrl = "remote.php/dav/addressbooks/system/system/system"; |
|
|
|
$body = $this->buildSyncCollectionRequestBody($syncToken); |
|
|
|
$body = $this->buildSyncCollectionRequestBody($syncToken); |
|
|
|
|
|
|
|
$response = $client->request('REPORT', $addressBookUrl, $body, [ |
|
|
|
'Content-Type' => 'application/xml' |
|
|
|
]); |
|
|
|
$response = $client->request('REPORT', $addressBookUrl, $body, [ |
|
|
|
'Content-Type' => 'application/xml' |
|
|
|
]); |
|
|
|
|
|
|
|
return $this->parseMultiStatus($response['body']); |
|
|
|
} |
|
|
|
return $this->parseMultiStatus($response['body']); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param string $url |
|
|
|
* @param string $userName |
|
|
|
* @param string $sharedSecret |
|
|
|
* @param string $resourcePath |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
protected function download($url, $sharedSecret, $resourcePath) { |
|
|
|
$client = $this->getClient($url, 'system', $sharedSecret); |
|
|
|
protected function download($url, $userName, $sharedSecret, $resourcePath) { |
|
|
|
$client = $this->getClient($url, $userName, $sharedSecret); |
|
|
|
return $client->request('GET', $resourcePath); |
|
|
|
} |
|
|
|
|
|
|
|
|