diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 16b518a9d..02a34c026 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -58,11 +58,11 @@ use OCP\Group\Events\GroupDeletedEvent; use OCP\Group\Events\UserAddedEvent; use OCP\Group\Events\UserRemovedEvent; -use OCP\IServerContainer; use OCP\Share\IManager as IShareManager; use OCP\User\Events\UserChangedEvent; use OCP\User\Events\UserCreatedEvent; use OCP\User\Events\UserDeletedEvent; +use Psr\Container\ContainerInterface; use Throwable; /** @@ -81,8 +81,6 @@ class Application extends App implements IBootstrap { public const CLIENT_TIMEOUT = 3; - private ConfigService $configService; - public function __construct(array $params = []) { parent::__construct(self::APP_ID, $params); } @@ -129,26 +127,20 @@ public function register(IRegistrationContext $context): void { /** - * @param IBootContext $context - * * @throws Throwable */ public function boot(IBootContext $context): void { - $serverContainer = $context->getServerContainer(); - $context->injectFn(function (IShareManager $shareManager) { $shareManager->registerShareProvider(ShareByCircleProvider::class); }); - $this->configService = $context->getAppContainer() - ->get(ConfigService::class); - $context->injectFn(Closure::fromCallable([$this, 'registerMountProvider'])); } - public function registerMountProvider(IServerContainer $container) { - if (!$this->configService->isGSAvailable()) { + public function registerMountProvider(ContainerInterface $container): void { + $configService = $container->get(ConfigService::class); + if (!$configService->isGSAvailable()) { return; } diff --git a/lib/Circles/FileSharingBroadcaster.php b/lib/Circles/FileSharingBroadcaster.php index 5bd630829..fd35ac4e3 100644 --- a/lib/Circles/FileSharingBroadcaster.php +++ b/lib/Circles/FileSharingBroadcaster.php @@ -9,7 +9,6 @@ namespace OCA\Circles\Circles; use Exception; -use OC; use OC\Share20\Share; use OCA\Circles\AppInfo\Application; use OCA\Circles\Db\FileSharesRequest; @@ -23,7 +22,6 @@ use OCA\Circles\Service\ConfigService; use OCA\Circles\Service\MiscService; use OCA\FederatedFileSharing\Notifications; -use OCP\AppFramework\QueryException; use OCP\Defaults; use OCP\Federation\ICloudIdManager; use OCP\Files\IRootFolder; @@ -32,12 +30,14 @@ use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; +use OCP\L10N\IFactory; use OCP\Mail\IEMailTemplate; use OCP\Mail\IMailer; use OCP\Server; use OCP\Share\Exceptions\IllegalIDChangeException; use OCP\Share\IShare; use OCP\Util; +use Psr\Container\ContainerExceptionInterface; use Psr\Log\LoggerInterface; /** @@ -49,8 +49,7 @@ class FileSharingBroadcaster implements IBroadcaster { /** @var bool */ private $initiated = false; - /** @var IL10N */ - private $l10n = null; + private ?IL10N $l10n = null; /** @var IMailer */ private $mailer; @@ -101,7 +100,7 @@ public function init() { } $this->initiated = true; - $this->l10n = OC::$server->getL10N(Application::APP_ID); + $this->l10n = Server::get(IFactory::class)->get(Application::APP_ID); $this->mailer = Server::get(IMailer::class); $this->rootFolder = Server::get(IRootFolder::class); $this->userManager = Server::get(IUserManager::class); @@ -114,7 +113,7 @@ public function init() { $this->tokensRequest = Server::get(TokensRequest::class); $this->configService = Server::get(ConfigService::class); $this->miscService = Server::get(MiscService::class); - } catch (QueryException $e) { + } catch (ContainerExceptionInterface $e) { $this->logger->info('Circles: cannot init FileSharingBroadcaster - ' . $e->getMessage(), ['exception' => $e]); } @@ -122,7 +121,7 @@ public function init() { $this->federationNotifications = Server::get(Notifications::class); $this->federatedEnabled = true; - } catch (QueryException $e) { + } catch (ContainerExceptionInterface $e) { } } @@ -388,7 +387,7 @@ private function sharedByMail( $lang = $this->configService->getCoreValueForUser($share->getSharedBy(), 'lang', ''); if ($lang !== '') { - $this->l10n = OC::$server->getL10N(Application::APP_ID, $lang); + $this->l10n = Server::get(IFactory::class)->get(Application::APP_ID, $lang); } $displayName = $this->miscService->getDisplayName($share->getSharedBy()); diff --git a/lib/Migration/Version0024Date20220317190331.php b/lib/Migration/Version0024Date20220317190331.php index 81cae6b1d..904702f5e 100644 --- a/lib/Migration/Version0024Date20220317190331.php +++ b/lib/Migration/Version0024Date20220317190331.php @@ -32,7 +32,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if ($schema->hasTable('circles_membership')) { $table = $schema->getTable('circles_membership'); - if (!$table->hasPrimaryKey()) { + if ($table->getPrimaryKey() === null) { $indexes = $table->getIndexes(); // conflict in Oracle with existing unique index, duplicate of primaryKey. foreach ($indexes as $index) { diff --git a/lib/Model/BaseCircle.php b/lib/Model/BaseCircle.php index 0c848c8e1..1b0fed17a 100644 --- a/lib/Model/BaseCircle.php +++ b/lib/Model/BaseCircle.php @@ -7,9 +7,10 @@ namespace OCA\Circles\Model; -use OC; use OCA\Circles\AppInfo\Application; use OCP\IL10N; +use OCP\L10N\IFactory; +use OCP\Server; /** * @deprecated @@ -88,7 +89,7 @@ class BaseCircle { private $links; public function __construct($type = -1, $name = '') { - $this->l10n = OC::$server->getL10N(Application::APP_ID); + $this->l10n = Server::get(IFactory::class)->get(Application::APP_ID); if ($type > -1) { $this->type = $type; diff --git a/lib/Model/BaseMember.php b/lib/Model/BaseMember.php index 640e32b65..dcc5eff0c 100644 --- a/lib/Model/BaseMember.php +++ b/lib/Model/BaseMember.php @@ -8,10 +8,11 @@ namespace OCA\Circles\Model; use JsonSerializable; -use OC; use OCA\Circles\AppInfo\Application; use OCA\Circles\Service\MiscService; use OCP\IL10N; +use OCP\L10N\IFactory; +use OCP\Server; /** * @deprecated @@ -91,7 +92,7 @@ class BaseMember implements JsonSerializable { * @param int $type */ public function __construct($userId = '', $type = 0, $circleUniqueId = '') { - $this->l10n = OC::$server->getL10N(Application::APP_ID); + $this->l10n = Server::get(IFactory::class)->get(Application::APP_ID); $this->setType($type); $this->setUserId($userId); diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index 1db6beace..0dce7b92d 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -21,6 +21,8 @@ use OCA\Circles\Tools\Traits\TArrayTools; use OCA\Circles\Tools\Traits\TNCLogger; use OCA\Circles\Tools\Traits\TStringTools; +use OCP\AppFramework\Services\IAppConfig; +use OCP\Config\IUserConfig; use OCP\IConfig; use OCP\IURLGenerator; @@ -191,23 +193,19 @@ class ConfigService { public const DISPLAY_PARENTHESIS = 2; - /** @var IConfig */ - private $config; - - /** @var IURLGenerator */ - private $urlGenerator; - - /** * ConfigService constructor. * * @param IConfig $config * @param IURLGenerator $urlGenerator */ - public function __construct(IConfig $config, IURLGenerator $urlGenerator) { - $this->config = $config; - $this->urlGenerator = $urlGenerator; - + public function __construct( + private readonly IConfig $config, + private readonly IAppConfig $appConfig, + private readonly IUserConfig $userConfig, + private readonly \OCP\IAppConfig $globalAppConfig, + private readonly IURLGenerator $urlGenerator, + ) { $this->setup('app', Application::APP_ID); } @@ -220,7 +218,7 @@ public function __construct(IConfig $config, IURLGenerator $urlGenerator) { * @return string */ public function getAppValue(string $key): string { - if (($value = $this->config->getAppValue(Application::APP_ID, $key, '')) !== '') { + if (($value = $this->appConfig->getAppValueString($key)) !== '') { return $value; } @@ -259,7 +257,7 @@ public function getAppValueBool(string $key): bool { * @return void */ public function setAppValue(string $key, string $value): void { - $this->config->setAppValue(Application::APP_ID, $key, $value); + $this->appConfig->setAppValueString($key, $value); } @@ -267,7 +265,7 @@ public function setAppValue(string $key, string $value): void { * */ public function unsetAppConfig(): void { - $this->config->deleteAppValues(Application::APP_ID); + $this->appConfig->deleteAppValues(); } @@ -293,7 +291,7 @@ public function getAvailableHosts(): array { * @return string */ public function getCoreValueForUser($userId, $key, $default = '') { - return $this->config->getUserValue($userId, 'core', $key, $default); + return $this->userConfig->getValueString($userId, 'core', $key, $default); } @@ -365,11 +363,7 @@ public function isSinglePasswordAvailable(Circle $circle): bool { * @return bool */ public function enforcePasswordOnSharedFile(Circle $circle): bool { - if ($this->config->getAppValue( - 'core', - 'shareapi_enforce_links_password', - 'no' - ) === 'yes') { + if ($this->globalAppConfig->getValueBool('core', 'shareapi_enforce_links_password')) { return true; } @@ -590,7 +584,7 @@ public function getFrontalInstance(): string { // using old settings local_cloud_id from NC20, deprecated in NC25 if ($frontalCloudId === '') { - $frontalCloudId = $this->config->getAppValue(Application::APP_ID, 'local_cloud_id', ''); + $frontalCloudId = $this->appConfig->getAppValueString('local_cloud_id'); if ($frontalCloudId !== '') { $this->setAppValue(self::FRONTAL_CLOUD_ID, $frontalCloudId); } diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index 099a23e2b..bc8c4b03d 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -5,13 +5,6 @@ - - - getAppContainer()]]> - getServerContainer()]]> - - - @@ -28,8 +21,6 @@ getUserId())]]> - - getId()]]> @@ -155,15 +146,7 @@ - - - - - - - - settings)]]> @@ -178,9 +161,6 @@ - - - @@ -349,15 +329,6 @@ - - - - - - - - -