diff --git a/lib/Service/CollectiveHelper.php b/lib/Service/CollectiveHelper.php index f97d8cbee4..0d763da107 100644 --- a/lib/Service/CollectiveHelper.php +++ b/lib/Service/CollectiveHelper.php @@ -34,12 +34,10 @@ public function __construct(CollectiveMapper $collectiveMapper, * @param bool $getLevel * @param bool $getUserSettings * - * @return array + * @return CollectiveInfo[] * @throws NotFoundException * @throws NotPermittedException * @throws MissingDependencyException - * - * The array key of the returned result is the collective id. */ public function getCollectivesForUser(string $userId, bool $getLevel = true, bool $getUserSettings = true): array { $collectiveInfos = []; @@ -62,7 +60,7 @@ public function getCollectivesForUser(string $userId, bool $getLevel = true, boo $userPageOrder = ($settings ? $settings->getSetting('page_order') : null) ?? Collective::defaultPageOrder; $userShowRecentPages = ($settings ? $settings->getSetting('show_recent_pages') : null) ?? Collective::defaultShowRecentPages; } - $collectiveInfos[$c->getId()] = new CollectiveInfo( + $collectiveInfos[] = new CollectiveInfo( $c, $circle->getSanitizedName(), $level, @@ -77,12 +75,10 @@ public function getCollectivesForUser(string $userId, bool $getLevel = true, boo /** * @param string $userId * - * @return array + * @return CollectiveInfo[] * @throws NotFoundException * @throws NotPermittedException * @throws MissingDependencyException - * - * The array key of the returned result is the collective id. */ public function getCollectivesTrashForUser(string $userId): array { $collectiveInfos = []; @@ -91,11 +87,10 @@ public function getCollectivesTrashForUser(string $userId): array { return $circle->getSingleId(); }, $circles); $circles = array_combine($cids, $circles); - /** @var Collective[] $collectives */ $collectives = $this->collectiveMapper->findTrashByCircleIdsAndUser($cids, $userId); foreach ($collectives as $c) { $cid = $c->getCircleId(); - $collectiveInfos[$c->getId()] = new CollectiveInfo( + $collectiveInfos[] = new CollectiveInfo( $c, $circles[$cid]->getSanitizedName(), $this->circleHelper->getLevel($cid, $userId) diff --git a/lib/Service/CollectiveService.php b/lib/Service/CollectiveService.php index ec4abf47de..cfc31ee213 100644 --- a/lib/Service/CollectiveService.php +++ b/lib/Service/CollectiveService.php @@ -104,7 +104,7 @@ public function getCollectiveWithShare(int $id, string $userId): CollectiveInfo /** * @param string $userId * - * @return array + * @return CollectiveInfo[] * @throws NotFoundException * @throws NotPermittedException * @throws MissingDependencyException diff --git a/lib/Service/RecentPagesService.php b/lib/Service/RecentPagesService.php index b26e03188b..a4935d088d 100644 --- a/lib/Service/RecentPagesService.php +++ b/lib/Service/RecentPagesService.php @@ -53,10 +53,13 @@ public function forUser(IUser $user, int $limit = 10): array { $mimeTypeMd = $this->mimeTypeLoader->getId('text/markdown'); $expressions = []; + $collectivesMap = []; foreach ($collectives as $collective) { $value = sprintf($appData . '/collectives/%d/%%', $collective->getId()); $expressions[] = $qb->expr()->like('f.path', $qb->createNamedParameter($value, IQueryBuilder::PARAM_STR)); + $collectivesMap[$collective->getId()] = $collective; } + unset($collectives); $qb->select('p.*', 'f.mtime as timestamp', 'f.name as filename', 'f.path as path') ->from('filecache', 'f') @@ -71,7 +74,7 @@ public function forUser(IUser $user, int $limit = 10): array { $pages = []; while ($row = $r->fetch()) { $collectiveId = (int)explode('/', $row['path'], 4)[2]; - if (!isset($collectives[$collectiveId])) { + if (!isset($collectivesMap[$collectiveId])) { continue; } @@ -81,7 +84,7 @@ public function forUser(IUser $user, int $limit = 10): array { unset($splitPath); // prepare link and title - $pathParts = [$collectives[$collectiveId]->getName()]; + $pathParts = [$collectivesMap[$collectiveId]->getName()]; if ($internalPath !== '' && $internalPath !== '.') { $pathParts = array_merge($pathParts, explode('/', $internalPath)); } @@ -97,7 +100,7 @@ public function forUser(IUser $user, int $limit = 10): array { // not returning a PageInfo instance because it would be either incomplete or too expensive to build completely $recentPage = new RecentPage(); $recentPage - ->setCollectiveName($this->collectiveService->getCollectiveNameWithEmoji($collectives[$collectiveId])) + ->setCollectiveName($this->collectiveService->getCollectiveNameWithEmoji($collectivesMap[$collectiveId])) ->setTitle($title) ->setPageUrl($url) ->setTimestamp($row['timestamp']);