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_getAllUserLogins_ReturnsLdapEntities() { $mockLdapClient = $this->makeMockLdapClient($forSuccess = false); $usedFilter = null; $mockLdapClient->expects($this->any())->method('bind')->will($this->returnValue(true)); $mockLdapClient->expects($this->any())->method('fetchAll')->will($this->returnCallback(function ($baseDn, $filter, $bind) use(&$usedFilter) { $usedFilter = $filter; return array(array('uid' => LdapUsersTest::TEST_USER), array('uid' => LdapUsersTest::TEST_ADMIN_USER)); })); $this->ldapUsers->setLdapClientClass($mockLdapClient); $this->setSingleLdapServer(); $logins = $this->ldapUsers->getAllUserLogins(); $this->assertEquals(array(self::TEST_USER, self::TEST_ADMIN_USER), $logins); }