From 7923dfd9b88a4030956caf3dcfe2e58a486134d3 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Tue, 10 Sep 2024 19:31:13 +0200 Subject: [PATCH 1/2] refactor: Replace \OC::$server->get with \OCP\Server::get Signed-off-by: Christoph Wurst --- lib/Command/Trashbin/Cleanup.php | 2 +- lib/Folder/FolderManager.php | 8 ++++---- lib/Mount/MountProvider.php | 2 +- tests/Trash/TrashBackendTest.php | 14 +++++++------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/Command/Trashbin/Cleanup.php b/lib/Command/Trashbin/Cleanup.php index bdf0c58cd..7abccee08 100644 --- a/lib/Command/Trashbin/Cleanup.php +++ b/lib/Command/Trashbin/Cleanup.php @@ -25,7 +25,7 @@ class Cleanup extends Base { public function __construct(FolderManager $folderManager, IRootFolder $rootFolder) { parent::__construct(); if (\OC::$server->getAppManager()->isEnabledForUser('files_trashbin')) { - $this->trashBackend = \OC::$server->get(TrashBackend::class); + $this->trashBackend = \OCP\Server::get(TrashBackend::class); $this->folderManager = $folderManager; } } diff --git a/lib/Folder/FolderManager.php b/lib/Folder/FolderManager.php index 4ff3b78dc..8e9f19737 100644 --- a/lib/Folder/FolderManager.php +++ b/lib/Folder/FolderManager.php @@ -230,7 +230,7 @@ private function getFolderMappings(int $id): array { private function getManageAcl(array $mappings): array { return array_filter(array_map(function (array $entry): ?array { if ($entry['mapping_type'] === 'user') { - $user = \OC::$server->get(IUserManager::class)->get($entry['mapping_id']); + $user = \OCP\Server::get(IUserManager::class)->get($entry['mapping_id']); if ($user === null) { return null; } @@ -240,7 +240,7 @@ private function getManageAcl(array $mappings): array { 'displayname' => (string)$user->getDisplayName() ]; } - $group = \OC::$server->get(IGroupManager::class)->get($entry['mapping_id']); + $group = \OCP\Server::get(IGroupManager::class)->get($entry['mapping_id']); if ($group === null) { return []; } @@ -304,7 +304,7 @@ public function getFolderAclEnabled(int $id): bool { public function getFolderByPath(string $path): int { /** @var Node $node */ - $node = \OC::$server->get(IRootFolder::class)->get($path); + $node = \OCP\Server::get(IRootFolder::class)->get($path); /** @var GroupMountPoint $mountPoint */ $mountPoint = $node->getMountPoint(); return $mountPoint->getFolderId(); @@ -412,7 +412,7 @@ public function canManageACL(int $folderId, IUser $user): bool { // Call private server api if (class_exists('\OC\Settings\AuthorizedGroupMapper')) { - $authorizedGroupMapper = \OC::$server->get('\OC\Settings\AuthorizedGroupMapper'); + $authorizedGroupMapper = \OCP\Server::get('\OC\Settings\AuthorizedGroupMapper'); $settingClasses = $authorizedGroupMapper->findAllClassesForUser($user); if (in_array('OCA\GroupFolders\Settings\Admin', $settingClasses, true)) { return true; diff --git a/lib/Mount/MountProvider.php b/lib/Mount/MountProvider.php index eaff0a700..5d34a1eb2 100644 --- a/lib/Mount/MountProvider.php +++ b/lib/Mount/MountProvider.php @@ -163,7 +163,7 @@ private function getCurrentUID(): ?string { try { // wopi requests are not logged in, instead we need to get the editor user from the access token if (strpos($this->request->getRawPathInfo(), 'apps/richdocuments/wopi') && class_exists('OCA\Richdocuments\Db\WopiMapper')) { - $wopiMapper = \OC::$server->get('OCA\Richdocuments\Db\WopiMapper'); + $wopiMapper = \OCP\Server::get('OCA\Richdocuments\Db\WopiMapper'); $token = $this->request->getParam('access_token'); if ($token) { $wopi = $wopiMapper->getPathForToken($token); diff --git a/tests/Trash/TrashBackendTest.php b/tests/Trash/TrashBackendTest.php index c902728fb..9c45ea428 100644 --- a/tests/Trash/TrashBackendTest.php +++ b/tests/Trash/TrashBackendTest.php @@ -50,18 +50,18 @@ public function setUp(): void { $this->normalUser = $this->createUser('normal', 'test'); /** @var Database $groupBackend */ - $groupBackend = \OC::$server->get(Database::class); + $groupBackend = \OCP\Server::get(Database::class); $groupBackend->createGroup('gf_manager'); $groupBackend->createGroup('gf_normal'); $groupBackend->addToGroup('manager', 'gf_manager'); $groupBackend->addToGroup('normal', 'gf_normal'); - $this->trashBackend = \OC::$server->get(TrashBackend::class); - $this->folderManager = \OC::$server->get(FolderManager::class); + $this->trashBackend = \OCP\Server::get(TrashBackend::class); + $this->folderManager = \OCP\Server::get(FolderManager::class); /** @var ACLManagerFactory $aclManagerFactory */ - $aclManagerFactory = \OC::$server->get(ACLManagerFactory::class); + $aclManagerFactory = \OCP\Server::get(ACLManagerFactory::class); $this->aclManager = $aclManagerFactory->getACLManager($this->managerUser); - $this->ruleManager = \OC::$server->get(RuleManager::class); + $this->ruleManager = \OCP\Server::get(RuleManager::class); $this->folderId = $this->folderManager->createFolder($this->folderName); $this->folderManager->addApplicableGroup($this->folderId, 'gf_manager'); @@ -70,7 +70,7 @@ public function setUp(): void { $this->folderManager->setManageACL($this->folderId, 'user', 'manager', true); /** @var IRootFolder $rootFolder */ - $rootFolder = \OC::$server->get(IRootFolder::class); + $rootFolder = \OCP\Server::get(IRootFolder::class); $this->managerUserFolder = $rootFolder->getUserFolder('manager'); $this->normalUserFolder = $rootFolder->getUserFolder('normal'); @@ -90,7 +90,7 @@ protected function tearDown(): void { $this->folderManager->removeFolder($this->folderId); /** @var SetupManager $setupManager */ - $setupManager = \OC::$server->get(SetupManager::class); + $setupManager = \OCP\Server::get(SetupManager::class); $setupManager->tearDown(); parent::tearDown(); } From d18571fd33f632efaa51ac7eae08d4dabd1eda1d Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Wed, 11 Sep 2024 15:19:48 +0200 Subject: [PATCH 2/2] fix: PSALM Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- lib/Folder/FolderManager.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Folder/FolderManager.php b/lib/Folder/FolderManager.php index 8e9f19737..a41b42353 100644 --- a/lib/Folder/FolderManager.php +++ b/lib/Folder/FolderManager.php @@ -230,7 +230,7 @@ private function getFolderMappings(int $id): array { private function getManageAcl(array $mappings): array { return array_filter(array_map(function (array $entry): ?array { if ($entry['mapping_type'] === 'user') { - $user = \OCP\Server::get(IUserManager::class)->get($entry['mapping_id']); + $user = Server::get(IUserManager::class)->get($entry['mapping_id']); if ($user === null) { return null; } @@ -240,14 +240,14 @@ private function getManageAcl(array $mappings): array { 'displayname' => (string)$user->getDisplayName() ]; } - $group = \OCP\Server::get(IGroupManager::class)->get($entry['mapping_id']); + $group = Server::get(IGroupManager::class)->get($entry['mapping_id']); if ($group === null) { return []; } return [ 'type' => 'group', - 'id' => (string)$group->getGID(), - 'displayname' => (string)$group->getDisplayName() + 'id' => $group->getGID(), + 'displayname' => $group->getDisplayName() ]; }, $mappings), function (?array $element): bool { return $element !== null; @@ -304,7 +304,7 @@ public function getFolderAclEnabled(int $id): bool { public function getFolderByPath(string $path): int { /** @var Node $node */ - $node = \OCP\Server::get(IRootFolder::class)->get($path); + $node = Server::get(IRootFolder::class)->get($path); /** @var GroupMountPoint $mountPoint */ $mountPoint = $node->getMountPoint(); return $mountPoint->getFolderId(); @@ -412,7 +412,7 @@ public function canManageACL(int $folderId, IUser $user): bool { // Call private server api if (class_exists('\OC\Settings\AuthorizedGroupMapper')) { - $authorizedGroupMapper = \OCP\Server::get('\OC\Settings\AuthorizedGroupMapper'); + $authorizedGroupMapper = Server::get('\OC\Settings\AuthorizedGroupMapper'); $settingClasses = $authorizedGroupMapper->findAllClassesForUser($user); if (in_array('OCA\GroupFolders\Settings\Admin', $settingClasses, true)) { return true;