Example #1
0
 public function postDeleteUser($params)
 {
     $uid = $params['uid'];
     if (isset($this->usersToDelete[$uid])) {
         $this->syncService->deleteUser($this->usersToDelete[$uid]);
     }
 }
 /**
  * @param \Closure $callback
  */
 public function syncThemAll(\Closure $callback)
 {
     $trustedServers = $this->dbHandler->getAllServer();
     foreach ($trustedServers as $trustedServer) {
         $url = $trustedServer['url'];
         $callback($url, null);
         $sharedSecret = $trustedServer['shared_secret'];
         $syncToken = $trustedServer['sync_token'];
         if (is_null($sharedSecret)) {
             continue;
         }
         $targetBookId = $trustedServer['url_hash'];
         $targetPrincipal = "principals/system/system";
         $targetBookProperties = ['{DAV:}displayname' => $url];
         try {
             $newToken = $this->syncService->syncRemoteAddressBook($url, 'system', $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties);
             if ($newToken !== $syncToken) {
                 $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken);
             }
         } catch (\Exception $ex) {
             if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
                 $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_ACCESS_REVOKED);
             }
             $callback($url, $ex);
         }
     }
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $progress = new ProgressBar($output);
     $progress->start();
     $trustedServers = $this->dbHandler->getAllServer();
     foreach ($trustedServers as $trustedServer) {
         $progress->advance();
         $url = $trustedServer['url'];
         $sharedSecret = $trustedServer['shared_secret'];
         $syncToken = $trustedServer['sync_token'];
         if (is_null($sharedSecret)) {
             continue;
         }
         $targetBookId = sha1($url);
         $targetPrincipal = "principals/system/system";
         $targetBookProperties = ['{DAV:}displayname' => $url];
         try {
             $newToken = $this->syncService->syncRemoteAddressBook($url, 'system', $sharedSecret, $syncToken, $targetPrincipal, $targetBookId, $targetBookProperties);
             if ($newToken !== $syncToken) {
                 $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken);
             }
         } catch (\Exception $ex) {
             $output->writeln("Error while syncing {$url} : " . $ex->getMessage());
         }
     }
     $progress->finish();
     $output->writeln('');
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Syncing users ...');
     $progress = new ProgressBar($output);
     $progress->start();
     $this->syncService->syncInstance(function () use($progress) {
         $progress->advance();
     });
     $progress->finish();
     $output->writeln('');
 }
Example #5
0
 public function testUpdateAndDeleteUser()
 {
     /** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject $backend */
     $backend = $this->getMockBuilder('OCA\\DAV\\CardDAV\\CardDAVBackend')->disableOriginalConstructor()->getMock();
     $backend->expects($this->once())->method('createCard');
     $backend->expects($this->once())->method('updateCard');
     $backend->expects($this->once())->method('deleteCard');
     $backend->method('getCard')->willReturnOnConsecutiveCalls(false, ['carddata' => "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Sabre//Sabre VObject 3.4.8//EN\r\nUID:test-user\r\nFN:test-user\r\nN:test-user;;;;\r\nEND:VCARD\r\n\r\n"]);
     /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject $userManager */
     $userManager = $this->getMockBuilder('OCP\\IUserManager')->disableOriginalConstructor()->getMock();
     /** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */
     $user = $this->getMockBuilder('OCP\\IUser')->disableOriginalConstructor()->getMock();
     $user->method('getBackendClassName')->willReturn('unittest');
     $user->method('getUID')->willReturn('test-user');
     $ss = new SyncService($backend, $userManager);
     $ss->updateUser($user);
     $user->method('getDisplayName')->willReturn('A test user for unit testing');
     $ss->updateUser($user);
     $ss->deleteUser($user);
 }
Example #6
0
 public function changeUser($params)
 {
     $user = $params['user'];
     $this->syncService->updateUser($user);
 }