protected function execute(InputInterface $input, OutputInterface $output) { $logins = $input->getOption('login'); $skipExisting = $input->getOption('skip-existing'); if (empty($logins)) { $logins = $this->ldapUsers->getAllUserLogins(); } $count = 0; $failed = array(); foreach ($logins as $login) { if ($skipExisting && $this->userExistsInPiwik($login)) { $output->write("Skipping '{$login}', already exists in Piwik..."); continue; } $output->write("Synchronizing '{$login}'... "); try { $this->loginLdapAPI->synchronizeUser($login); ++$count; $output->writeln("<info>success!</info>"); } catch (Exception $ex) { $failed[] = array('login' => $login, 'reason' => $ex->getMessage()); $output->writeln("<error>failed!</error>"); } } $this->writeSuccessMessage($output, array("Synchronized {$count} users!")); if (!empty($failed)) { $output->writeln("<info>Could not synchronize the following users in LDAP:</info>"); foreach ($failed as $missingLogin) { $output->writeln($missingLogin['login'] . "\t\t<comment>{$missingLogin['reason']}</comment>"); } } return count($failed); }
public function test_synchronizeUser_Succeeds_WhenLdapUserExistsAndIsValid() { $this->api->synchronizeUser(self::TEST_LOGIN); $this->assertStarkSynchronized(); }