Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<category>auth</category>
<dependencies>
<php min-version="8.4"/>
<nextcloud min-version="31" max-version="33"/>
<nextcloud min-version="31" max-version="34"/>
</dependencies>
<settings>
<admin>\OCA\UserSQL\Settings\Admin</admin>
Expand Down
12 changes: 9 additions & 3 deletions lib/Action/EmailSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCA\UserSQL\Properties;
use OCA\UserSQL\Repository\UserRepository;
use OCP\IConfig;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -56,6 +57,10 @@ class EmailSync implements IUserAction
* @var UserRepository The user repository.
*/
private $userRepository;
/**
* @var IUserManager The user manager object.
*/
private $userManager;

/**
* The default constructor.
Expand All @@ -68,13 +73,14 @@ class EmailSync implements IUserAction
*/
public function __construct(
$appName, LoggerInterface $logger, Properties $properties, IConfig $config,
UserRepository $userRepository
UserRepository $userRepository, IUserManager $userManager
) {
$this->appName = $appName;
$this->logger = $logger;
$this->properties = $properties;
$this->config = $config;
$this->userRepository = $userRepository;
$this->userManager = $userManager;
}

/**
Expand Down Expand Up @@ -104,7 +110,7 @@ public function doAction(User $user)
$this->config->setUserValue(
$user->uid, "settings", "email", $user->email
);
\OC::$server->getUserManager()->get($user->uid)->setEMailAddress($user->email);
$this->userManager->get($user->uid)->setEMailAddress($user->email);
}

$result = true;
Expand All @@ -126,7 +132,7 @@ public function doAction(User $user)
$this->config->setUserValue(
$user->uid, "settings", "email", $user->email
);
\OC::$server->getUserManager()->get($user->uid)->setEMailAddress($user->email);
$this->userManager->get($user->uid)->setEMailAddress($user->email);
}

$result = true;
Expand Down
13 changes: 10 additions & 3 deletions lib/Action/NameSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCA\UserSQL\Properties;
use OCA\UserSQL\Repository\UserRepository;
use OCP\IConfig;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -56,6 +57,10 @@ class NameSync implements IUserAction
* @var UserRepository The user repository.
*/
private $userRepository;
/**
* @var IUserManager The user manager provider.
*/
private $userManager;

/**
* The default constructor.
Expand All @@ -65,16 +70,18 @@ class NameSync implements IUserAction
* @param Properties $properties The properties array.
* @param IConfig $config The config instance.
* @param UserRepository $userRepository The user repository.
* @param IUserManager $userManager The user manager provider.
*/
public function __construct(
$appName, LoggerInterface $logger, Properties $properties, IConfig $config,
UserRepository $userRepository
UserRepository $userRepository, IUserManager $userManager
) {
$this->appName = $appName;
$this->logger = $logger;
$this->properties = $properties;
$this->config = $config;
$this->userRepository = $userRepository;
$this->userManager = $userManager;
}

/**
Expand All @@ -99,7 +106,7 @@ public function doAction(User $user)
$this->config->setUserValue(
$user->uid, "settings", "displayName", $user->name
);
\OC::$server->getUserManager()->get($user->uid)->setDisplayName($user->name);
$this->userManager->get($user->uid)->setDisplayName($user->name);
}

$result = true;
Expand All @@ -121,7 +128,7 @@ public function doAction(User $user)
$this->config->setUserValue(
$user->uid, "settings", "displayName", $user->name
);
\OC::$server->getUserManager()->get($user->uid)->setDisplayName($user->name);
$this->userManager->get($user->uid)->setDisplayName($user->name);
}

$result = true;
Expand Down
11 changes: 8 additions & 3 deletions lib/Backend/GroupBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ final class GroupBackend extends ABackend implements
* @var Properties The properties array.
*/
private $properties;
/**
* @var IUserManager The user manager provider
*/
private $userManager;

/**
* The default constructor.
Expand All @@ -81,16 +85,18 @@ final class GroupBackend extends ABackend implements
* @param LoggerInterface $logger The logger instance.
* @param Properties $properties The properties array.
* @param GroupRepository $groupRepository The group repository.
* @param IUserManager $userManager The user manager provider.
*/
public function __construct(
$AppName, Cache $cache, LoggerInterface $logger, Properties $properties,
GroupRepository $groupRepository
GroupRepository $groupRepository, IUserManager $userManager
) {
$this->appName = $AppName;
$this->cache = $cache;
$this->logger = $logger;
$this->properties = $properties;
$this->groupRepository = $groupRepository;
$this->userManager = $userManager;
}

/**
Expand Down Expand Up @@ -434,9 +440,8 @@ public function searchInGroup(string $gid, string $search = '', int $limit = -1,
}

$users = [];
$userManager = \OCP\Server::get(IUserManager::class);
foreach ($names as $uid => $name) {
$users[$uid] = new LazyUser($uid, $userManager, $name);
$users[$uid] = new LazyUser($uid, $this->userManager, $name);
}

return $users;
Expand Down
13 changes: 10 additions & 3 deletions lib/Backend/UserBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
use OCP\Security\Events\ValidatePasswordPolicyEvent;
use OCP\User\Backend\ABackend;
Expand Down Expand Up @@ -100,6 +101,10 @@ final class UserBackend extends ABackend implements
* @var IUserAction[] The actions to execute.
*/
private $actions;
/**
* @var IUserManager The user manager object.
*/
private $userManager;

/**
* The default constructor.
Expand All @@ -112,11 +117,12 @@ final class UserBackend extends ABackend implements
* @param IL10N $localization The localization service.
* @param IConfig $config The config instance.
* @param IEventDispatcher $eventDispatcher The event dispatcher.
* @param IUserManager $userManager The user manager provider.
*/
public function __construct(
$AppName, Cache $cache, LoggerInterface $logger, Properties $properties,
UserRepository $userRepository, IL10N $localization, IConfig $config,
IEventDispatcher $eventDispatcher
IEventDispatcher $eventDispatcher, IUserManager $userManager
) {
$this->appName = $AppName;
$this->cache = $cache;
Expand All @@ -126,6 +132,7 @@ public function __construct(
$this->localization = $localization;
$this->config = $config;
$this->eventDispatcher = $eventDispatcher;
$this->userManager = $userManager;
$this->actions = [];

$this->initActions();
Expand All @@ -141,7 +148,7 @@ private function initActions()
) {
$this->actions[] = new EmailSync(
$this->appName, $this->logger, $this->properties, $this->config,
$this->userRepository
$this->userRepository, $this->userManager
);
}
if (!empty($this->properties[Opt::QUOTA_SYNC])
Expand All @@ -157,7 +164,7 @@ private function initActions()
) {
$this->actions[] = new NameSync(
$this->appName, $this->logger, $this->properties, $this->config,
$this->userRepository
$this->userRepository, $this->userManager
);
}
}
Expand Down
7 changes: 4 additions & 3 deletions lib/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OCA\UserSQL\Constant\App;
use OCA\UserSQL\Constant\Opt;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
use Psr\Log\LoggerInterface;

Expand All @@ -50,10 +51,10 @@ class Cache
* @param string $AppName The application name.
* @param IConfig $config The config instance.
* @param LoggerInterface $logger The logger instance.
@param ICacheFactory $factory The cache factory instance.
*/
public function __construct($AppName, IConfig $config, LoggerInterface $logger)
public function __construct($AppName, IConfig $config, LoggerInterface $logger, ICacheFactory $factory)
{
$factory = \OC::$server->getMemCacheFactory();
$useCache = $config->getAppValue(
$AppName, Opt::USE_CACHE, App::FALSE_VALUE
);
Expand All @@ -62,7 +63,7 @@ public function __construct($AppName, IConfig $config, LoggerInterface $logger)
$this->cache = new NullCache();
} else {
if ($factory->isAvailable()) {
$this->cache = $factory->createDistributed();
$this->cache = $factory->createDistributed($AppName);
}
if ($this->cache === null || ($this->cache instanceof NullCache)) {
$logger->debug(
Expand Down
10 changes: 8 additions & 2 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OC\DatabaseException;
use OC\DB\Connection;
use OC\DB\ConnectionFactory;
use OC\SystemConfig;
use OCA\UserSQL\Cache;
use OCA\UserSQL\Constant\App;
use OCA\UserSQL\Constant\DB;
Expand Down Expand Up @@ -65,6 +66,10 @@ class SettingsController extends Controller
* @var Cache The cache instance.
*/
private $cache;
/**
* @var SystemConfig The system configuration provider.
*/
private $systemConfig;

/**
* The default constructor.
Expand All @@ -78,14 +83,15 @@ class SettingsController extends Controller
*/
public function __construct(
$appName, IRequest $request, LoggerInterface $logger, IL10N $localization,
Properties $properties, Cache $cache
Properties $properties, Cache $cache, SystemConfig $systemConfig
) {
parent::__construct($appName, $request);
$this->appName = $appName;
$this->logger = $logger;
$this->localization = $localization;
$this->properties = $properties;
$this->cache = $cache;
$this->systemConfig = $systemConfig;
}

/**
Expand Down Expand Up @@ -157,7 +163,7 @@ private function getConnection()
}

$connectionFactory = new ConnectionFactory(
\OC::$server->getSystemConfig()
$this->systemConfig()
);

$parameters = [
Expand Down
25 changes: 13 additions & 12 deletions lib/Query/DataQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Doctrine\DBAL\Exception as DBALException;
use OC\DB\Connection;
use OC\DB\ConnectionFactory;
use OC\SystemConfig;
use OCA\UserSQL\Constant\DB;
use OCA\UserSQL\Constant\Query;
use OCA\UserSQL\Properties;
Expand Down Expand Up @@ -69,15 +70,17 @@ class DataQuery
* @param LoggerInterface $logger The logger instance.
* @param Properties $properties The properties array.
* @param QueryProvider $queryProvider The query provider.
* @param SystemConfig $systemConfig The system configuration provider.
*/
public function __construct(
$AppName, LoggerInterface $logger, Properties $properties,
QueryProvider $queryProvider
QueryProvider $queryProvider, SystemConfig $systemConfig
) {
$this->appName = $AppName;
$this->logger = $logger;
$this->properties = $properties;
$this->queryProvider = $queryProvider;
$this->systemConfig = $systemConfig;
$this->connection = false;
}

Expand All @@ -98,10 +101,10 @@ public function update($queryName, $params = [])
/**
* Run a given query and return the result.
*
* @param string $queryName The query to execute.
* @param array $params The query parameters to bind.
* @param int $limit Results limit. Defaults to -1 (no limit).
* @param int $offset Results offset. Defaults to 0.
* @param string $queryName The query to execute.
* @param array $params The query parameters to bind.
* @param int $limit Results limit. Defaults to -1 (no limit).
* @param int $offset Results offset. Defaults to 0.
*
* @return Statement|bool Result of query or FALSE on failure.
*/
Expand Down Expand Up @@ -142,9 +145,7 @@ private function execQuery(
*/
private function connectToDatabase()
{
$connectionFactory = new ConnectionFactory(
\OC::$server->getSystemConfig()
);
$connectionFactory = new ConnectionFactory($this->systemConfig);

$parameters = array(
"host" => $this->properties[DB::HOSTNAME],
Expand Down Expand Up @@ -184,10 +185,10 @@ private function connectToDatabase()
* Fetch a value from the first row and the first column which
* the given query returns. Empty result set is consider to be a failure.
*
* @param string $queryName The query to execute.
* @param array $params The query parameters to bind.
* @param bool $failure Value returned on database query failure.
* Defaults to FALSE.
* @param string $queryName The query to execute.
* @param array $params The query parameters to bind.
* @param bool $failure Value returned on database query failure.
* Defaults to FALSE.
*
* @return array|bool Queried value or $failure value on failure.
*/
Expand Down