Skip to content

Commit

Permalink
refactor(FolderManager): Simplify CirclesManager access
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Sep 16, 2024
1 parent 009c3b1 commit 80eabb9
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions lib/Folder/FolderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,7 @@ public function getFolderByPath(string $path): int {
* @throws Exception
*/
private function getAllApplicable(): array {
$queryHelper = null;
if ($this->isCirclesAvailable($circlesManager)) {
$queryHelper = $circlesManager?->getQueryHelper();
}
$queryHelper = $this->getCirclesManager()?->getQueryHelper();

$query = $queryHelper?->getQueryBuilder() ?? $this->connection->getQueryBuilder();
$query->select('g.folder_id', 'g.group_id', 'g.circle_id', 'g.permissions')
Expand Down Expand Up @@ -596,7 +593,8 @@ public function getFoldersForGroups(array $groupIds, int $rootStorageId = 0): ar
* @throws Exception
*/
public function getFoldersFromCircleMemberships(IUser $user, int $rootStorageId = 0): array {
if (!$this->isCirclesAvailable($circlesManager)) {
$circlesManager = $this->getCirclesManager();
if ($circlesManager === null) {
return [];
}

Expand Down Expand Up @@ -931,7 +929,8 @@ public function getFolderPermissionsForUser(IUser $user, int $folderId): int {
* @return bool
*/
public function isACircle(string $groupId): bool {
if (!$this->isCirclesAvailable($circlesManager)) {
$circlesManager = $this->getCirclesManager();
if ($circlesManager === null) {
return false;
}

Expand All @@ -953,22 +952,11 @@ public function isACircle(string $groupId): bool {
return false;
}

/**
* returns if the circles manager is available.
* also set the parameter.
*
* @param CirclesManager|null $circlesManager
*
* @return bool
*/
public function isCirclesAvailable(?CirclesManager &$circlesManager = null): bool {
public function getCirclesManager(): ?CirclesManager {
try {
/** @var CirclesManager $circlesManager */
$circlesManager = Server::get(CirclesManager::class);
return Server::get(CirclesManager::class);
} catch (ContainerExceptionInterface|AutoloadNotAllowedException $e) {
return false;
return null;
}

return true;
}
}

0 comments on commit 80eabb9

Please sign in to comment.