Example #1
0
 /**
  * @covers Ilios\CoreBundle\Service\Directory::findByCampusId
  */
 public function testFindByCampusId()
 {
     $ldapManager = m::mock('Ilios\\CoreBundle\\Service\\LdapManager');
     $obj = new Directory($ldapManager, 'campusId');
     $ldapManager->shouldReceive('search')->with('(campusId=1234)')->andReturn(array(1));
     $result = $obj->findByCampusId(1234);
     $this->assertSame($result, 1);
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $campusId = $input->getArgument('campusId');
     $user = $this->userManager->findOneBy(['campusId' => $campusId]);
     if ($user) {
         throw new \Exception('User #' . $user->getId() . " with campus id {$campusId} already exists.");
     }
     $schoolId = $input->getArgument('schoolId');
     $school = $this->schoolManager->findOneBy(['id' => $schoolId]);
     if (!$school) {
         throw new \Exception("School with id {$schoolId} could not be found.");
     }
     $userRecord = $this->directory->findByCampusId($campusId);
     if (!$userRecord) {
         $output->writeln("<error>Unable to find campus ID {$campusId} in the directory.</error>");
         return;
     }
     $table = new Table($output);
     $table->setHeaders(array('Campus ID', 'First', 'Last', 'Email', 'Username', 'Phone Number'))->setRows(array([$userRecord['campusId'], $userRecord['firstName'], $userRecord['lastName'], $userRecord['email'], $userRecord['username'], $userRecord['telephoneNumber']]));
     $table->render();
     $helper = $this->getHelper('question');
     $output->writeln('');
     $question = new ConfirmationQuestion("<question>Do you wish to add this user to Ilios?</question>\n", true);
     if ($helper->ask($input, $output, $question)) {
         $user = $this->userManager->create();
         $user->setFirstName($userRecord['firstName']);
         $user->setLastName($userRecord['lastName']);
         $user->setEmail($userRecord['email']);
         $user->setCampusId($userRecord['campusId']);
         $user->setAddedViaIlios(true);
         $user->setEnabled(true);
         $user->setSchool($school);
         $user->setUserSyncIgnore(false);
         $this->userManager->update($user);
         $authentication = $this->authenticationManager->create();
         $authentication->setUser($user);
         $authentication->setUsername($userRecord['username']);
         $this->authenticationManager->update($authentication);
         $output->writeln('<info>Success! New user #' . $user->getId() . ' ' . $user->getFirstAndLastName() . ' created.</info>');
     } else {
         $output->writeln('<comment>Canceled.</comment>');
     }
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $userId = $input->getArgument('userId');
     $user = $this->userManager->findOneBy(['id' => $userId]);
     if (!$user) {
         throw new \Exception("No user with id #{$userId} was found.");
     }
     $userRecord = $this->directory->findByCampusId($user->getCampusId());
     if (!$userRecord) {
         $output->writeln('<error>Unable to find ' . $user->getCampusId() . ' in the directory.');
         return;
     }
     $table = new Table($output);
     $table->setHeaders(array('Record', 'Campus ID', 'First', 'Last', 'Email', 'Phone Number'))->setRows(array(['Ilios User', $user->getCampusId(), $user->getFirstName(), $user->getLastName(), $user->getEmail(), $user->getPhone()], ['Directory User', $userRecord['campusId'], $userRecord['firstName'], $userRecord['lastName'], $userRecord['email'], $userRecord['telephoneNumber']]));
     $table->render();
     $helper = $this->getHelper('question');
     $output->writeln('');
     $question = new ConfirmationQuestion('<question>Do you wish to update this Ilios User with the data ' . 'from the Directory User? </question>' . "\n", true);
     if ($helper->ask($input, $output, $question)) {
         $user->setFirstName($userRecord['firstName']);
         $user->setLastName($userRecord['lastName']);
         $user->setEmail($userRecord['email']);
         $user->setPhone($userRecord['telephoneNumber']);
         $authentication = $user->getAuthentication();
         if (!$authentication) {
             $authentication = $this->authenticationManager->create();
             $authentication->setUser($user);
         }
         $authentication->setUsername($userRecord['username']);
         $this->authenticationManager->update($authentication, false);
         $this->userManager->update($user);
         $output->writeln('<info>User updated successfully!</info>');
     } else {
         $output->writeln('<comment>Update canceled.</comment>');
     }
 }