Exemplo n.º 1
0
 public function updateRepository(Repository $repository)
 {
     // If the owner has not a token, ignore
     if ($repository->getOwner()->getToken() == null) {
         return;
     }
     // Connecting with Blih
     $blih = new Blih($repository->getOwner()->getLogin());
     $blih->setToken($repository->getOwner()->getToken());
     // Getting the repository ACLs
     $blihRepositoryACLs = $blih->repository($repository->getName())->acl()->get()->body;
     if (isset($blihRepositoryACLs->error)) {
         return;
     }
     $repositoryACLs = $repository->getAcls();
     // Removing the users removed
     $repositoryACLs->forAll(function ($key, RepositoryACL $repositoryACL) use($blihRepositoryACLs) {
         if (!array_key_exists($repositoryACL->getUser()->getLogin(), $blihRepositoryACLs)) {
             $this->entityManager->remove($repositoryACL);
         }
         return true;
     });
     // Updating or creating the ACLs for the users already set
     foreach ($blihRepositoryACLs as $login => $acl) {
         $user = $this->epitechUserRetriever->retrieve($login);
         $repositoryACL = $this->retrieveOrCreateRepositoryACL($user, $repository);
         $repositoryACL->setFromACLString($acl);
         $this->entityManager->persist($user);
         $this->entityManager->persist($repositoryACL);
     }
     $this->entityManager->flush();
 }