예제 #1
0
 public function checkIntegrity()
 {
     $this->log('Checking roles integrity for resources... This may take a while.');
     $workspaceManager = $this->container->get('claroline.manager.workspace_manager');
     $workspaces = $this->om->getRepository('Claroline\\CoreBundle\\Entity\\Workspace\\Workspace')->findAll();
     $this->om->startFlushSuite();
     $i = 0;
     foreach ($workspaces as $workspace) {
         $this->log('Checking ' . $workspace->getCode() . '...');
         $roles = $workspace->getRoles();
         $root = $this->container->get('claroline.manager.resource_manager')->getWorkspaceRoot($workspace);
         $collaboratorRole = $this->roleManager->getCollaboratorRole($workspace);
         if ($root && $collaboratorRole) {
             $collaboratorFound = false;
             foreach ($root->getRights() as $right) {
                 if ($right->getRole()->getName() == $this->roleManager->getCollaboratorRole($workspace)->getName()) {
                     $collaboratorFound = true;
                 }
             }
             if (!$collaboratorFound) {
                 $this->log('Adding missing right on root for ' . $workspace->getCode() . '.', LogLevel::DEBUG);
                 $collaboratorRole = $this->roleManager->getCollaboratorRole($workspace);
                 $this->editPerms(5, $collaboratorRole, $root, true, array(), true);
                 $i++;
                 if ($i % 3 === 0) {
                     $this->log('flushing...');
                     $this->om->forceFlush();
                     $this->om->clear();
                 }
             }
         }
     }
     $this->om->endFlushSuite();
 }
예제 #2
0
 /**
  * @param \Claroline\CoreBundle\Entity\Workspace\Workspace $workspace
  * @param \Claroline\CoreBundle\Entity\User                $user
  *
  * @return \Claroline\CoreBundle\Entity\User
  */
 public function addUserAction(Workspace $workspace, User $user)
 {
     $role = $this->roleManager->getCollaboratorRole($workspace);
     $userRoles = $this->roleManager->getWorkspaceRolesForUser($user, $workspace);
     if (count($userRoles) === 0) {
         $this->roleManager->associateRole($user, $role);
         $this->dispatcher->dispatch('claroline_workspace_register_user', 'WorkspaceAddUser', [$role, $user]);
     }
     $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
     $this->container->get('security.context')->setToken($token);
     return $user;
 }