Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions apps/files/lib/Search/FilesSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use OCP\Files\Search\ISearchOrder;
use OCP\IL10N;
use OCP\IPreview;
use OCP\ITags;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Search\FilterDefinition;
Expand Down Expand Up @@ -130,12 +131,28 @@
);
$searchResultEntry->addAttribute('fileId', (string)$result->getId());
$searchResultEntry->addAttribute('path', $path);
$searchResultEntry->addAttribute('favorite', $this->isFavorite((string)$result->getId()) ? "true" : "false");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$searchResultEntry->addAttribute('favorite', $this->isFavorite((string)$result->getId()) ? "true" : "false");
$searchResultEntry->addAttribute('favorite', $this->isFavorite($result->getId()) ? "true" : "false");

return $searchResultEntry;
}, $userFolder->search($fileQuery)),
$query->getCursor() + $query->getLimit()
);
}

private function isFavorite(string $fileId): bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private function isFavorite(string $fileId): bool {
private function isFavorite(int $fileId): bool {

$tagManager = \OCP\Server::get(\OCP\ITagManager::class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be injected in the constructor instead.

$tagger = $tagManager->load('files');
if ($tagger === null) {
return false;
}
$tags = $tagger->getTagsForObjects([$fileId]);

Check failure on line 147 in apps/files/lib/Search/FilesSearchProvider.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidArgument

apps/files/lib/Search/FilesSearchProvider.php:147:38: InvalidArgument: Argument 1 of OCP\ITags::getTagsForObjects expects list<int>, but list{string} provided (see https://psalm.dev/004)

if ($tags === false || empty($tags)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($tags === false || empty($tags)) {
if ($tags === false || empty($tags[$fileId])) {

return false;
}

return array_search(ITags::TAG_FAVORITE, current($tags)) !== false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return array_search(ITags::TAG_FAVORITE, current($tags)) !== false;
return array_search(ITags::TAG_FAVORITE, $tags[$fileId]) !== false;

}

private function buildSearchQuery(ISearchQuery $query, IUser $user): SearchQuery {
$comparisons = [];
foreach ($query->getFilters() as $name => $filter) {
Expand Down
Loading