/** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $principalBackend = new Principal($this->config, $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()); } } $progress->advance(); }); $progress->finish(); $output->writeln(''); }
/** * @dataProvider providesUsersForUpdateOfRemovedElement */ public function testUpdateOfRemovedElement($expectedVCard, $displayName = null, $eMailAddress = null, $cloudId = null) { $user = $this->getUserMock($displayName, $eMailAddress, $cloudId); $converter = new Converter(); $vCard = $converter->createCardFromUser($user); $user1 = $this->getMockBuilder('OCP\\IUser')->disableOriginalConstructor()->getMock(); $user1->method('getUID')->willReturn('12345'); $user1->method('getDisplayName')->willReturn(null); $user1->method('getEMailAddress')->willReturn(null); $user1->method('getCloudId')->willReturn(null); $user1->method('getAvatarImage')->willReturn(null); $updated = $converter->updateCard($vCard, $user1); $this->assertTrue($updated); $cardData = $vCard->serialize(); $this->assertEquals($expectedVCard, $cardData); }
/** * @param IUser $user */ public function updateUser($user) { $systemAddressBook = $this->getLocalSystemAddressBook(); $addressBookId = $systemAddressBook['id']; $converter = new Converter(); $name = $user->getBackendClassName(); $userId = $user->getUID(); $cardId = "{$name}:{$userId}.vcf"; $card = $this->backend->getCard($addressBookId, $cardId); if ($card === false) { $vCard = $converter->createCardFromUser($user); $this->backend->createCard($addressBookId, $cardId, $vCard->serialize()); } else { $vCard = Reader::read($card['carddata']); if ($converter->updateCard($vCard, $user)) { $this->backend->updateCard($addressBookId, $cardId, $vCard->serialize()); } } }