Skip to content

Commit

Permalink
Improve syncuser with dependency injection
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume COLSON <guillaume.colson@univ-lorraine.fr>
  • Loading branch information
goyome committed Oct 21, 2021
1 parent 4098a47 commit 8e6cc99
Showing 1 changed file with 10 additions and 40 deletions.
50 changes: 10 additions & 40 deletions apps/user_ldap/lib/Command/SyncUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,11 @@
*/
namespace OCA\User_LDAP\Command;

use OC\ServerNotAvailableException;
use OCA\User_LDAP\AccessFactory;
use OCA\User_LDAP\Configuration;
use OCA\User_LDAP\ConnectionFactory;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\User\Manager;

use OCA\User_LDAP\User_Proxy;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IUserManager;
use OCP\Notification\IManager;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -46,24 +36,15 @@
class SyncUser extends Command {
/** @var \OCP\IConfig */
protected $ocConfig;
/** @var Manager */
protected $userManager;
/** @var IDBConnection */
protected $dbc;
/** @var User_Proxy */
protected $backend;
/** @var Helper */
protected $helper;

public function __construct(IConfig $ocConfig) {
public function __construct(IConfig $ocConfig, User_Proxy $uBackend, Helper $helper) {
$this->ocConfig = $ocConfig;
$this->dbc = \OC::$server->getDatabaseConnection();
$this->userManager = new \OCA\User_LDAP\User\Manager(
\OC::$server->getConfig(),
new \OCA\User_LDAP\FilesystemHelper(),
new \OCA\User_LDAP\LogWrapper(),
\OC::$server->getAvatarManager(),
new \OCP\Image(),
\OC::$server->getUserManager(),
\OC::$server->getNotificationManager(),
\OC::$server->getShareManager()
);
$this->backend = $uBackend;
$this->helper = $helper;

parent::__construct();
}
Expand All @@ -81,24 +62,13 @@ protected function configure() {
}

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

$connectionFactory = new ConnectionFactory($ldapWrapper);
$connection = $connectionFactory->get($prefix);

$accessFactory = new AccessFactory(
$ldapWrapper,
$this->userManager,
$helper,
$this->ocConfig,
\OC::$server->getUserManager()
);
$access = $this->backend->getLDAPAccess($uid);

$access = $accessFactory->get($connection);
$access->setUserMapper(new UserMapping($this->dbc));
$connection = $access->getConnection();

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

0 comments on commit 8e6cc99

Please sign in to comment.