diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-13 20:56:25 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-14 12:10:45 +0100 |
commit | a91954907b51debaa9cabc4ccb89bfa6ebcc9c94 (patch) | |
tree | 591ac36c35ab6d6648dffd4647331fb67d66cbda /apps/dav/command | |
parent | 8f89e3520d74e1805dc46947742a17683ece6ca7 (diff) | |
download | nextcloud-server-a91954907b51debaa9cabc4ccb89bfa6ebcc9c94.tar.gz nextcloud-server-a91954907b51debaa9cabc4ccb89bfa6ebcc9c94.zip |
Start updating system addressbook
Diffstat (limited to 'apps/dav/command')
-rw-r--r-- | apps/dav/command/syncsystemaddressbook.php | 73 |
1 files changed, 7 insertions, 66 deletions
diff --git a/apps/dav/command/syncsystemaddressbook.php b/apps/dav/command/syncsystemaddressbook.php index 338529c1952..c7401107480 100644 --- a/apps/dav/command/syncsystemaddressbook.php +++ b/apps/dav/command/syncsystemaddressbook.php @@ -22,6 +22,7 @@ namespace OCA\DAV\Command; use OCA\DAV\CardDAV\CardDavBackend; use OCA\DAV\CardDAV\Converter; +use OCA\DAV\CardDAV\SyncService; use OCA\DAV\Connector\Sabre\Principal; use OCP\IConfig; use OCP\IDBConnection; @@ -39,28 +40,16 @@ use Symfony\Component\Console\Output\OutputInterface; class SyncSystemAddressBook extends Command { - /** @var IUserManager */ - protected $userManager; - - /** @var \OCP\IDBConnection */ - protected $dbConnection; - - /** @var IConfig */ - protected $config; - - /** @var CardDavBackend */ - private $backend; + /** @var SyncService */ + private $syncService; /** * @param IUserManager $userManager - * @param IDBConnection $dbConnection - * @param IConfig $config + * @param SyncService $syncService */ - function __construct(IUserManager $userManager, IDBConnection $dbConnection, IConfig $config) { + function __construct(SyncService $syncService) { parent::__construct(); - $this->userManager = $userManager; - $this->dbConnection = $dbConnection; - $this->config = $config; + $this->syncService = $syncService; } protected function configure() { @@ -74,63 +63,15 @@ class SyncSystemAddressBook extends Command { * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { - $principalBackend = new Principal( - $this->userManager - ); - - $this->backend = new CardDavBackend($this->dbConnection, $principalBackend); - - // ensure system addressbook exists - $systemAddressBook = $this->ensureSystemAddressBookExists(); - $converter = new Converter(); $output->writeln('Syncing users ...'); $progress = new ProgressBar($output); $progress->start(); - $this->userManager->callForAllUsers(function($user) use ($systemAddressBook, $converter, $progress) { - /** @var IUser $user */ - $name = $user->getBackendClassName(); - $userId = $user->getUID(); - - $cardId = "$name:$userId.vcf"; - $card = $this->backend->getCard($systemAddressBook['id'], $cardId); - if ($card === false) { - $vCard = $converter->createCardFromUser($user); - $this->backend->createCard($systemAddressBook['id'], $cardId, $vCard->serialize()); - } else { - $vCard = Reader::read($card['carddata']); - if ($converter->updateCard($vCard, $user)) { - $this->backend->updateCard($systemAddressBook['id'], $cardId, $vCard->serialize()); - } - } + $this->syncService->syncInstance(function() use ($progress) { $progress->advance(); }); - // remove no longer existing - $allCards = $this->backend->getCards($systemAddressBook['id']); - foreach($allCards as $card) { - $vCard = Reader::read($card['carddata']); - $uid = $vCard->UID->getValue(); - // load backend and see if user exists - if (!$this->userManager->userExists($uid)) { - $this->backend->deleteCard($systemAddressBook['id'], $card['uri']); - } - } - $progress->finish(); $output->writeln(''); } - - protected function ensureSystemAddressBookExists() { - $book = $this->backend->getAddressBooksByUri('system'); - if (!is_null($book)) { - return $book; - } - $systemPrincipal = "principals/system/system"; - $this->backend->createAddressBook($systemPrincipal, 'system', [ - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' - ]); - - return $this->backend->getAddressBooksByUri('system'); - } } |