mirror of
https://github.com/nextcloud/server.git
synced 2025-10-26 19:21:34 +00:00
smaller fixes: coding style, PHPdoc, typos and few for DI
This commit is contained in:
parent
61ed363f82
commit
e724b78694
@ -20,7 +20,8 @@ $uBackend = new User_Proxy(
|
||||
new LDAP()
|
||||
);
|
||||
$deletedUsersIndex = new DeletedUsersIndex(
|
||||
\OC::$server->getConfig(), $dbConnection, $userMapping);
|
||||
\OC::$server->getConfig(), $dbConnection, $userMapping
|
||||
);
|
||||
|
||||
$application->add(new OCA\user_ldap\Command\ShowConfig());
|
||||
$application->add(new OCA\user_ldap\Command\SetConfig());
|
||||
@ -28,6 +29,7 @@ $application->add(new OCA\user_ldap\Command\TestConfig());
|
||||
$application->add(new OCA\user_ldap\Command\CreateEmptyConfig());
|
||||
$application->add(new OCA\user_ldap\Command\DeleteConfig());
|
||||
$application->add(new OCA\user_ldap\Command\Search());
|
||||
$application->add(new OCA\user_ldap\Command\ShowRemnants($userMapping));
|
||||
$application->add(new OCA\user_ldap\Command\ShowRemnants($deletedUsersIndex));
|
||||
$application->add(new OCA\user_ldap\Command\CheckUser(
|
||||
$uBackend, $helper, $deletedUsersIndex, $userMapping));
|
||||
$uBackend, $helper, $deletedUsersIndex, $userMapping)
|
||||
);
|
||||
|
||||
@ -17,7 +17,8 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
use OCA\user_ldap\lib\user\User;
|
||||
use OCA\User_LDAP\lib\user\Manager;
|
||||
use OCA\User_LDAP\lib\User\DeletedUsersIndex;
|
||||
use OCA\user_ldap\lib\Helper;
|
||||
use OCA\User_LDAP\Mapping\UserMapping;
|
||||
use OCA\user_ldap\lib\Helper as LDAPHelper;
|
||||
use OCA\user_ldap\User_Proxy;
|
||||
|
||||
class CheckUser extends Command {
|
||||
@ -35,10 +36,11 @@ class CheckUser extends Command {
|
||||
|
||||
/**
|
||||
* @param OCA\user_ldap\User_Proxy $uBackend
|
||||
* @param OCA\User_LDAP\lib\Helper $helper
|
||||
* @param OCP\IConfig $config
|
||||
* @param OCA\user_ldap\lib\Helper $helper
|
||||
* @param OCA\User_LDAP\lib\User\DeletedUsersIndex $dui
|
||||
* @param OCA\User_LDAP\Mapping\UserMapping $mapping
|
||||
*/
|
||||
public function __construct(User_Proxy $uBackend, Helper $helper, DeletedUsersIndex $dui, UserMapping $mapping) {
|
||||
public function __construct(User_Proxy $uBackend, LDAPHelper $helper, DeletedUsersIndex $dui, UserMapping $mapping) {
|
||||
$this->backend = $uBackend;
|
||||
$this->helper = $helper;
|
||||
$this->dui = $dui;
|
||||
@ -100,13 +102,13 @@ class CheckUser extends Command {
|
||||
}
|
||||
|
||||
/**
|
||||
* checks whether the setup allows reliable checking of LDAP user existance
|
||||
* checks whether the setup allows reliable checking of LDAP user existence
|
||||
* @throws \Exception
|
||||
* @return bool
|
||||
* @return true
|
||||
*/
|
||||
protected function isAllowed($force) {
|
||||
if($this->helper->haveDisabledConfigurations() && !$force) {
|
||||
throw new \Exception('Cannot check user existance, because '
|
||||
throw new \Exception('Cannot check user existence, because '
|
||||
. 'disabled LDAP configurations are present.');
|
||||
}
|
||||
|
||||
|
||||
@ -19,16 +19,14 @@ use OCA\User_LDAP\lib\Connection;
|
||||
use OCA\User_LDAP\Mapping\UserMapping;
|
||||
|
||||
class ShowRemnants extends Command {
|
||||
/** @var OCA\User_LDAP\Mapping\UserMapping */
|
||||
protected $mapping;
|
||||
/** @var use OCA\User_LDAP\lib\User\DeletedUsersIndex; */
|
||||
protected $dui;
|
||||
|
||||
/**
|
||||
* @param OCA\user_ldap\User_Proxy $uBackend
|
||||
* @param OCA\User_LDAP\lib\Helper $helper
|
||||
* @param OCP\IConfig $config
|
||||
* @param OCA\user_ldap\lib\user\DeletedUsersIndex $dui
|
||||
*/
|
||||
public function __construct(UserMapping $mapper) {
|
||||
$this->mapper = $mapper;
|
||||
public function __construct(DeletedUsersIndex $dui) {
|
||||
$this->dui = $dui;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
@ -39,20 +37,19 @@ class ShowRemnants extends Command {
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* executes the command, i.e. creeates and outputs a table of LDAP users marked as deleted
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output) {
|
||||
$dui = new DeletedUsersIndex(
|
||||
\OC::$server->getConfig(),
|
||||
\OC::$server->getDatabaseConnection(),
|
||||
$this->mapper
|
||||
);
|
||||
|
||||
/** @var \Symfony\Component\Console\Helper\Table $table */
|
||||
$table = $this->getHelperSet()->get('table');
|
||||
$table->setHeaders(array(
|
||||
'ownCloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login',
|
||||
'Dir', 'Sharer'));
|
||||
$rows = array();
|
||||
$resultSet = $dui->getUsers();
|
||||
$resultSet = $this->dui->getUsers();
|
||||
foreach($resultSet as $user) {
|
||||
$hAS = $user->getHasActiveShares() ? 'Y' : 'N';
|
||||
$lastLogin = ($user->getLastLogin() > 0) ?
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
namespace OCA\user_ldap\lib;
|
||||
|
||||
use OCA\User_LDAP\Mapping\GroupMapping;
|
||||
use OCA\User_LDAP\Mapping\UserMapping;
|
||||
|
||||
class Jobs extends \OC\BackgroundJob\TimedJob {
|
||||
static private $groupsFromDB;
|
||||
@ -172,6 +173,9 @@ class Jobs extends \OC\BackgroundJob\TimedJob {
|
||||
$connector = new Connection($ldapWrapper, $configPrefixes[0]);
|
||||
$ldapAccess = new Access($connector, $ldapWrapper, $userManager);
|
||||
$groupMapper = new GroupMapping(\OC::$server->getDatabaseConnection());
|
||||
$userMapper = new UserMapping(\OC::$server->getDatabaseConnection());
|
||||
$ldapAccess->setGroupMapper($groupMapper);
|
||||
$ldapAccess->setUserMapper($userMapper);
|
||||
self::$groupBE = new \OCA\user_ldap\GROUP_LDAP($ldapAccess);
|
||||
} else {
|
||||
self::$groupBE = new \OCA\user_ldap\Group_Proxy($configPrefixes, $ldapWrapper);
|
||||
|
||||
@ -22,29 +22,22 @@ use \OCA\User_LDAP\Mapping\UserMapping;
|
||||
* @package OCA\user_ldap\lib;
|
||||
*/
|
||||
class CleanUp extends \OC\BackgroundJob\TimedJob {
|
||||
/**
|
||||
* @var int $limit amount of users that should be checked per run
|
||||
*/
|
||||
/** @var int $limit amount of users that should be checked per run */
|
||||
protected $limit = 50;
|
||||
|
||||
/**
|
||||
* @var \OCP\UserInterface $userBackend
|
||||
*/
|
||||
/** @var int $defaultIntervalMin default interval in minutes */
|
||||
protected $defaultIntervalMin = 51;
|
||||
|
||||
/** @var \OCP\UserInterface $userBackend */
|
||||
protected $userBackend;
|
||||
|
||||
/**
|
||||
* @var \OCP\IConfig $ocConfig
|
||||
*/
|
||||
/** @var \OCP\IConfig $ocConfig */
|
||||
protected $ocConfig;
|
||||
|
||||
/**
|
||||
* @var \OCP\IDBConnection $db
|
||||
*/
|
||||
/** @var \OCP\IDBConnection $db */
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @var Helper $ldapHelper
|
||||
*/
|
||||
/** @var Helper $ldapHelper */
|
||||
protected $ldapHelper;
|
||||
|
||||
/** @var \OCA\User_LDAP\Mapping\UserMapping */
|
||||
@ -53,11 +46,6 @@ class CleanUp extends \OC\BackgroundJob\TimedJob {
|
||||
/** @var \OCA\User_LDAP\lib\User\DeletedUsersIndex */
|
||||
protected $dui;
|
||||
|
||||
/**
|
||||
* @var int $defaultIntervalMin default interval in minutes
|
||||
*/
|
||||
protected $defaultIntervalMin = 51;
|
||||
|
||||
public function __construct() {
|
||||
$minutes = \OC::$server->getConfig()->getSystemValue(
|
||||
'ldapUserCleanupInterval', strval($this->defaultIntervalMin));
|
||||
@ -177,7 +165,7 @@ class CleanUp extends \OC\BackgroundJob\TimedJob {
|
||||
* checks users whether they are still existing
|
||||
* @param array $users result from getMappedUsers()
|
||||
*/
|
||||
private function checkUsers($users) {
|
||||
private function checkUsers(array $users) {
|
||||
foreach($users as $user) {
|
||||
$this->checkUser($user);
|
||||
}
|
||||
@ -187,7 +175,7 @@ class CleanUp extends \OC\BackgroundJob\TimedJob {
|
||||
* checks whether a user is still existing in LDAP
|
||||
* @param string[] $user
|
||||
*/
|
||||
private function checkUser($user) {
|
||||
private function checkUser(array $user) {
|
||||
if($this->userBackend->userExistsOnLDAP($user['name'])) {
|
||||
//still available, all good
|
||||
|
||||
|
||||
@ -49,8 +49,13 @@ class DeletedUsersIndex {
|
||||
/**
|
||||
* @var array $deletedUsers
|
||||
*/
|
||||
protected $deletedUsers = false;
|
||||
protected $deletedUsers;
|
||||
|
||||
/**
|
||||
* @param OCP\IConfig $config
|
||||
* @param OCP\IDBConnection $db
|
||||
* @param OCA\User_LDAP\Mapping\UserMapping $mapping
|
||||
*/
|
||||
public function __construct(\OCP\IConfig $config, \OCP\IDBConnection $db, UserMapping $mapping) {
|
||||
$this->config = $config;
|
||||
$this->db = $db;
|
||||
|
||||
@ -71,6 +71,12 @@ class OfflineUser {
|
||||
*/
|
||||
protected $mapping;
|
||||
|
||||
/**
|
||||
* @param string $ocName
|
||||
* @param OCP\IConfig $config
|
||||
* @param OCP\IDBConnection $db
|
||||
* @param OCA\User_LDAP\Mapping\UserMapping $mapping
|
||||
*/
|
||||
public function __construct($ocName, \OCP\IConfig $config, \OCP\IDBConnection $db, UserMapping $mapping) {
|
||||
$this->ocName = $ocName;
|
||||
$this->config = $config;
|
||||
|
||||
@ -105,30 +105,6 @@ class Test_CleanUp extends \PHPUnit_Framework_TestCase {
|
||||
$this->assertSame(true, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test whether sql is OK
|
||||
*/
|
||||
public function test_getMappedUsers() {
|
||||
$args = $this->getMocks();
|
||||
|
||||
$bgJob = new \OCA\User_LDAP\Jobs\CleanUp();
|
||||
$bgJob->setArguments($args);
|
||||
|
||||
if(version_compare(\PHPUnit_Runner_Version::id(), '3.8', '<')) {
|
||||
//otherwise we run into
|
||||
//https://github.com/sebastianbergmann/phpunit-mock-objects/issues/103
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
$stmt = $this->getMock('\Doctrine\DBAL\Driver\Statement');
|
||||
|
||||
$args['db']->expects($this->once())
|
||||
->method('prepare')
|
||||
->will($this->returnValue($stmt));
|
||||
|
||||
$bgJob->getMappedUsers(0, $bgJob->getChunkSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* check whether offset will be reset when it needs to
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user