From 6046fff9bcf4339f521c169bd40729f4f07f8bf1 Mon Sep 17 00:00:00 2001 From: nextcloud-command Date: Sun, 10 Mar 2024 02:41:58 +0000 Subject: [PATCH 1/2] chore(dev-deps): Bump nextcloud/ocp package Signed-off-by: GitHub --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index c89f651e..8406e234 100644 --- a/composer.lock +++ b/composer.lock @@ -134,12 +134,12 @@ "source": { "type": "git", "url": "https://github.com/nextcloud-deps/ocp.git", - "reference": "ef30cb8584a788bf01916ab00c39303e5f58f260" + "reference": "d23dac5fbce5d4eb53696da612285f4cbb666c90" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/ef30cb8584a788bf01916ab00c39303e5f58f260", - "reference": "ef30cb8584a788bf01916ab00c39303e5f58f260", + "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/d23dac5fbce5d4eb53696da612285f4cbb666c90", + "reference": "d23dac5fbce5d4eb53696da612285f4cbb666c90", "shasum": "" }, "require": { @@ -171,7 +171,7 @@ "issues": "https://github.com/nextcloud-deps/ocp/issues", "source": "https://github.com/nextcloud-deps/ocp/tree/master" }, - "time": "2024-01-12T00:34:25+00:00" + "time": "2024-03-09T00:30:46+00:00" }, { "name": "psr/clock", From 7cb1548ec2cba9cae2550dab04d8aff97a50eeae Mon Sep 17 00:00:00 2001 From: provokateurin Date: Wed, 13 Mar 2024 13:56:20 +0100 Subject: [PATCH 2/2] refactor: Migrate away from deprecated OCP APIs Signed-off-by: provokateurin --- lib/AppInfo/Application.php | 2 +- lib/JWTManager.php | 18 +++++++++--------- lib/SitesManager.php | 22 +++++++++++----------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 33e94cce..09ca85e6 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -63,7 +63,7 @@ public function registerSites( foreach ($sites as $site) { if ($site['type'] === SitesManager::TYPE_QUOTA) { - $settingsManager->registerSetting(IManager::KEY_PERSONAL_SETTINGS, Personal::class); + $settingsManager->registerSetting(IManager::SETTINGS_PERSONAL, Personal::class); continue; } diff --git a/lib/JWTManager.php b/lib/JWTManager.php index c1f34d3b..4d1774ba 100644 --- a/lib/JWTManager.php +++ b/lib/JWTManager.php @@ -27,15 +27,15 @@ use OCA\External\AppInfo\Application; use OCA\External\Vendor\Firebase\JWT\JWT; use OCP\AppFramework\Utility\ITimeFactory; -use OCP\IConfig; +use OCP\IAppConfig; use OCP\IURLGenerator; class JWTManager { - protected IConfig $config; + protected IAppConfig $config; protected ITimeFactory $timeFactory; protected IURLGenerator $urlGenerator; - public function __construct(IConfig $config, + public function __construct(IAppConfig $config, ITimeFactory $timeFactory, IURLGenerator $urlGenerator) { $this->config = $config; @@ -70,7 +70,7 @@ public function getTokenPublicKey(?string $alg = null): string { } $this->ensureTokenKeys($alg); - return $this->config->getAppValue(Application::APP_ID, 'jwt_token_pubkey_' . strtolower($alg)); + return $this->config->getValueString(Application::APP_ID, 'jwt_token_pubkey_' . strtolower($alg)); } protected function getTokenPrivateKey(?string $alg = null): string { @@ -79,11 +79,11 @@ protected function getTokenPrivateKey(?string $alg = null): string { } $this->ensureTokenKeys($alg); - return $this->config->getAppValue(Application::APP_ID, 'jwt_token_privkey_' . strtolower($alg)); + return $this->config->getValueString(Application::APP_ID, 'jwt_token_privkey_' . strtolower($alg)); } protected function ensureTokenKeys(string $alg): void { - $secret = $this->config->getAppValue(Application::APP_ID, 'jwt_token_privkey_' . strtolower($alg)); + $secret = $this->config->getValueString(Application::APP_ID, 'jwt_token_privkey_' . strtolower($alg)); if ($secret) { return; } @@ -117,11 +117,11 @@ protected function ensureTokenKeys(string $alg): void { throw new \Exception('Unsupported algorithm ' . $alg); } - $this->config->setAppValue(Application::APP_ID, 'jwt_token_privkey_' . strtolower($alg), $secret); - $this->config->setAppValue(Application::APP_ID, 'jwt_token_pubkey_' . strtolower($alg), $public); + $this->config->setValueString(Application::APP_ID, 'jwt_token_privkey_' . strtolower($alg), $secret); + $this->config->setValueString(Application::APP_ID, 'jwt_token_pubkey_' . strtolower($alg), $public); } protected function getTokenAlgorithm(): string { - return $this->config->getAppValue(Application::APP_ID, 'jwt_token_alg', 'ES256'); + return $this->config->getValueString(Application::APP_ID, 'jwt_token_alg', 'ES256'); } } diff --git a/lib/SitesManager.php b/lib/SitesManager.php index 4f6c7465..8c12eaf8 100644 --- a/lib/SitesManager.php +++ b/lib/SitesManager.php @@ -33,7 +33,7 @@ use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFile; -use OCP\IConfig; +use OCP\IAppConfig; use OCP\IGroupManager; use OCP\IRequest; use OCP\IUser; @@ -55,7 +55,7 @@ class SitesManager { /** @var IRequest */ protected $request; - /** @var IConfig */ + /** @var IAppConfig */ protected $config; /** @var IFactory */ @@ -78,7 +78,7 @@ class SitesManager { public function __construct(IRequest $request, - IConfig $config, + IAppConfig $config, IAppManager $appManager, IGroupManager $groupManager, IUserSession $userSession, @@ -166,7 +166,7 @@ public function getSitesToDisplay() { * @return array[] */ public function getSites() { - $jsonEncodedList = $this->config->getAppValue('external', 'sites', ''); + $jsonEncodedList = $this->config->getValueString('external', 'sites', ''); $sites = json_decode($jsonEncodedList, true); if (!is_array($sites) || empty($sites)) { @@ -217,7 +217,7 @@ protected function fillSiteArray(array $site): array { * @throws IconNotFoundException */ public function addSite($name, $url, $lang, $type, $device, $icon, array $groups, $redirect) { - $id = 1 + (int) $this->config->getAppValue('external', 'max_site', '0'); + $id = 1 + $this->config->getValueInt('external', 'max_site'); if ($name === '') { throw new InvalidNameException(); @@ -282,8 +282,8 @@ public function addSite($name, $url, $lang, $type, $device, $icon, array $groups 'groups' => $groups, 'redirect' => $redirect, ]; - $this->config->setAppValue('external', 'sites', json_encode($sites)); - $this->config->setAppValue('external', 'max_site', (string)$id); + $this->config->setValueString('external', 'sites', json_encode($sites)); + $this->config->setValueInt('external', 'max_site', $id); return $sites[$id]; } @@ -376,7 +376,7 @@ public function updateSite($id, $name, $url, $lang, $type, $device, $icon, array 'groups' => $groups, 'redirect' => $redirect, ]; - $this->config->setAppValue('external', 'sites', json_encode($sites)); + $this->config->setValueString('external', 'sites', json_encode($sites)); return $sites[$id]; } @@ -388,7 +388,7 @@ public function deleteSite(int $id): void { } unset($sites[$id]); - $this->config->setAppValue('external', 'sites', json_encode($sites)); + $this->config->setValueString('external', 'sites', json_encode($sites)); } /** @@ -407,8 +407,8 @@ protected function getSitesFromOldConfig(array $sites): array { ]); } - $this->config->setAppValue('external', 'sites', json_encode($fixedSites)); - $this->config->setAppValue('external', 'max_site', (string)max(array_keys($fixedSites))); + $this->config->setValueString('external', 'sites', json_encode($fixedSites)); + $this->config->setValueInt('external', 'max_site', max(array_keys($fixedSites))); return $fixedSites; }