Ejemplo n.º 1
0
 /**
  * @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('');
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider providesNames
  * @param $expected
  * @param $fullName
  */
 public function testNameSplitter($expected, $fullName)
 {
     $converter = new Converter();
     $r = $converter->splitFullName($fullName);
     $r = implode(';', $r);
     $this->assertEquals($expected, $r);
 }
Ejemplo n.º 3
0
 /**
  * @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());
         }
     }
 }