Skip to content

Commit cc1f484

Browse files
committed
Improve syncuser with dependency injection
Signed-off-by: Guillaume COLSON <guillaume.colson@univ-lorraine.fr>
1 parent 38fa165 commit cc1f484

File tree

1 file changed

+10
-40
lines changed

1 file changed

+10
-40
lines changed

apps/user_ldap/lib/Command/SyncUser.php

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,11 @@
2121
*/
2222
namespace OCA\User_LDAP\Command;
2323

24-
use OC\ServerNotAvailableException;
25-
use OCA\User_LDAP\AccessFactory;
26-
use OCA\User_LDAP\Configuration;
27-
use OCA\User_LDAP\ConnectionFactory;
2824
use OCA\User_LDAP\Helper;
2925
use OCA\User_LDAP\LDAP;
30-
use OCA\User_LDAP\Mapping\UserMapping;
31-
use OCA\User_LDAP\User\Manager;
3226

3327
use OCA\User_LDAP\User_Proxy;
34-
use OCP\IAvatarManager;
3528
use OCP\IConfig;
36-
use OCP\IDBConnection;
37-
use OCP\IUserManager;
38-
use OCP\Notification\IManager;
3929

4030
use Symfony\Component\Console\Command\Command;
4131
use Symfony\Component\Console\Input\InputArgument;
@@ -46,24 +36,15 @@
4636
class SyncUser extends Command {
4737
/** @var \OCP\IConfig */
4838
protected $ocConfig;
49-
/** @var Manager */
50-
protected $userManager;
51-
/** @var IDBConnection */
52-
protected $dbc;
39+
/** @var User_Proxy */
40+
protected $backend;
41+
/** @var Helper */
42+
protected $helper;
5343

54-
public function __construct(IConfig $ocConfig) {
44+
public function __construct(IConfig $ocConfig, User_Proxy $uBackend, Helper $helper) {
5545
$this->ocConfig = $ocConfig;
56-
$this->dbc = \OC::$server->getDatabaseConnection();
57-
$this->userManager = new \OCA\User_LDAP\User\Manager(
58-
\OC::$server->getConfig(),
59-
new \OCA\User_LDAP\FilesystemHelper(),
60-
new \OCA\User_LDAP\LogWrapper(),
61-
\OC::$server->getAvatarManager(),
62-
new \OCP\Image(),
63-
\OC::$server->getUserManager(),
64-
\OC::$server->getNotificationManager(),
65-
\OC::$server->getShareManager()
66-
);
46+
$this->backend = $uBackend;
47+
$this->helper = $helper;
6748

6849
parent::__construct();
6950
}
@@ -81,24 +62,13 @@ protected function configure() {
8162
}
8263

8364
protected function execute(InputInterface $input, OutputInterface $output): int {
84-
$helper = new Helper($this->ocConfig, \OC::$server->getDatabaseConnection());
85-
$configPrefixes = $helper->getServerConfigurationPrefixes(true);
65+
$configPrefixes = $this->helper->getServerConfigurationPrefixes(true);
8666
$prefix = $this->ocConfig->getAppValue('user_ldap', 'background_sync_prefix', null);
8767
$ldapWrapper = new LDAP();
8868

89-
$connectionFactory = new ConnectionFactory($ldapWrapper);
90-
$connection = $connectionFactory->get($prefix);
91-
92-
$accessFactory = new AccessFactory(
93-
$ldapWrapper,
94-
$this->userManager,
95-
$helper,
96-
$this->ocConfig,
97-
\OC::$server->getUserManager()
98-
);
69+
$access = $this->backend->getLDAPAccess($uid);
9970

100-
$access = $accessFactory->get($connection);
101-
$access->setUserMapper(new UserMapping($this->dbc));
71+
$connection = $access->getConnection();
10272

10373
$loginName = $access->escapeFilterPart($input->getArgument('uid'));
10474
$filter = str_replace('%uid', $loginName, $connection->ldapLoginFilter);

0 commit comments

Comments
 (0)