]> source.dussan.org Git - nextcloud-server.git/commitdiff
smaller fixes: coding style, PHPdoc, typos and few for DI
authorArthur Schiwon <blizzz@owncloud.com>
Tue, 6 Jan 2015 16:50:06 +0000 (17:50 +0100)
committerArthur Schiwon <blizzz@owncloud.com>
Tue, 6 Jan 2015 16:50:06 +0000 (17:50 +0100)
apps/user_ldap/appinfo/register_command.php
apps/user_ldap/command/checkuser.php
apps/user_ldap/command/showremnants.php
apps/user_ldap/lib/jobs.php
apps/user_ldap/lib/jobs/cleanup.php
apps/user_ldap/lib/user/deletedusersindex.php
apps/user_ldap/lib/user/offlineuser.php
apps/user_ldap/tests/jobs/cleanup.php

index e0013c4eb7a72333fb2031457acda0b028894279..0e918b82335cb25051af4e3e30df4e6616978f74 100644 (file)
@@ -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)
+);
index 5b1dc36c1d0ab92d6e3d7839496870dbbcca5db5..f9065a7c8d6f6c5e39cf93587d81c771819c035d 100644 (file)
@@ -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.');
                }
 
index 8144a54cbeeffa5c69bd122a59cf5f406fccc874..ab78cee96e70a71b06a2efebe88a0b40542f98d7 100644 (file)
@@ -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) ?
index 391a10d31f8f2a5f8c3ec7e2b12e9d35d2cd6e94..e8e6df0b9d0cd02d2205bd399783bdc0bdd0fb63 100644 (file)
@@ -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);
index 35252d6f6e5d06a5a25f9593c98b5385eeaa0dce..83cfeb048c8d42734b5d03f1100c9166d49f10cf 100644 (file)
@@ -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
 
index 6758553027982f6c98f8e6a749db42e2ee06b44a..e17ed3384daa42560ea92eadaaabe0e74a206614 100644 (file)
@@ -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;
index 9383320fae2c31006623754b6e6aa37b5832d29f..e5c87fd23fc075174a90bd298ecedbbddecf36e6 100644 (file)
@@ -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;
index 642bad571342633f5b922b982aab64b1429deaa3..78bda66c54f35d5d7aa11f2cd47c90355ebd9633 100644 (file)
@@ -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
         */