aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/command
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-11-30 16:59:41 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-12-02 09:14:41 +0100
commit906777dc9c8e0d9075e6a8d8c7f6eeb7c07e5256 (patch)
tree0bc7e586fb59dfe9a9439a5bfdcaf6f670cb106e /apps/dav/command
parent1e8ad65288097a65cb53ba2c44284dc22e0f9b46 (diff)
downloadnextcloud-server-906777dc9c8e0d9075e6a8d8c7f6eeb7c07e5256.tar.gz
nextcloud-server-906777dc9c8e0d9075e6a8d8c7f6eeb7c07e5256.zip
Add converter to generate/update a vcard from a given user
Diffstat (limited to 'apps/dav/command')
-rw-r--r--apps/dav/command/syncsystemaddressbook.php27
1 files changed, 4 insertions, 23 deletions
diff --git a/apps/dav/command/syncsystemaddressbook.php b/apps/dav/command/syncsystemaddressbook.php
index 74d8295e77b..288616d065b 100644
--- a/apps/dav/command/syncsystemaddressbook.php
+++ b/apps/dav/command/syncsystemaddressbook.php
@@ -3,6 +3,7 @@
namespace OCA\DAV\Command;
use OCA\DAV\CardDAV\CardDavBackend;
+use OCA\DAV\CardDAV\Converter;
use OCA\DAV\Connector\Sabre\Principal;
use OCP\IConfig;
use OCP\IDBConnection;
@@ -63,6 +64,7 @@ class SyncSystemAddressBook extends Command {
// ensure system addressbook exists
$systemAddressBook = $this->ensureSystemAddressBookExists();
+ $converter = new Converter();
$output->writeln('Syncing users ...');
$progress = new ProgressBar($output);
@@ -74,36 +76,15 @@ class SyncSystemAddressBook extends Command {
$user = $this->userManager->get($user);
$name = $user->getBackendClassName();
$userId = $user->getUID();
- $displayName = $user->getDisplayName();
- $emailAddress = $user->getEMailAddress();
- $cloudId = $user->getCloudId();
- $image = $user->getAvatarImage(-1);
$cardId = "$name:$userId.vcf";
$card = $this->backend->getCard($systemAddressBook['id'], $cardId);
if ($card === false) {
- $vCard = new VCard();
- $vCard->add(new Text($vCard, 'UID', $userId));
- $vCard->add(new Text($vCard, 'FN', $displayName));
- $vCard->add(new Text($vCard, 'EMAIL', $emailAddress));
- $vCard->add(new Text($vCard, 'CLOUD', $cloudId));
- if ($image) {
- $vCard->add('PHOTO', $image->data(), ['ENCODING' => 'b', 'TYPE' => $image->mimeType()]);
- }
- $vCard->validate();
+ $vCard = $converter->createCardFromUser($user);
$this->backend->createCard($systemAddressBook['id'], $cardId, $vCard->serialize());
} else {
- $updated = false;
$vCard = Reader::read($card['carddata']);
- if($vCard->FN !== $displayName) {
- $vCard->FN = new Text($vCard, 'FN', $displayName);
- $updated = true;
- }
- if($vCard->EMail !== $emailAddress) {
- $vCard->FN = new Text($vCard, 'EMAIL', $emailAddress);
- $updated = true;
- }
- if ($updated) {
+ if ($converter->updateCard($vCard, $user)) {
$this->backend->updateCard($systemAddressBook['id'], $cardId, $vCard->serialize());
}
}