Skip to content

Commit bc32838

Browse files
Merge pull request #54826 from nextcloud/bug/54379/use-show-file-route-comment-search
2 parents e5dc38b + a37ed05 commit bc32838

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

apps/comments/lib/Search/CommentsSearchProvider.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use OCP\Search\SearchResult;
1818
use OCP\Search\SearchResultEntry;
1919
use function array_map;
20-
use function pathinfo;
2120

2221
class CommentsSearchProvider implements IProvider {
2322
public function __construct(
@@ -49,22 +48,25 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
4948
$this->l10n->t('Comments'),
5049
array_map(function (Result $result) {
5150
$path = $result->path;
52-
$pathInfo = pathinfo($path);
5351
$isUser = $this->userManager->userExists($result->authorId);
5452
$avatarUrl = $isUser
5553
? $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $result->authorId, 'size' => 42])
5654
: $this->urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => $result->authorId, 'size' => 42]);
57-
return new SearchResultEntry(
55+
$link = $this->urlGenerator->linkToRoute(
56+
'files.View.showFile',
57+
['fileid' => $result->fileId]
58+
);
59+
$searchResultEntry = new SearchResultEntry(
5860
$avatarUrl,
5961
$result->name,
6062
$path,
61-
$this->urlGenerator->linkToRouteAbsolute('files.view.index', [
62-
'dir' => $pathInfo['dirname'],
63-
'scrollto' => $pathInfo['basename'],
64-
]),
63+
$link,
6564
'',
6665
true
6766
);
67+
$searchResultEntry->addAttribute('fileId', (string)$result->fileId);
68+
$searchResultEntry->addAttribute('path', $path);
69+
return $searchResultEntry;
6870
}, $this->legacyProvider->search($query->getTerm()))
6971
);
7072
}

apps/comments/lib/Search/LegacyProvider.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OCP\Comments\IComment;
1212
use OCP\Comments\ICommentsManager;
1313
use OCP\Files\Folder;
14+
use OCP\Files\InvalidPathException;
1415
use OCP\Files\Node;
1516
use OCP\Files\NotFoundException;
1617
use OCP\IUser;
@@ -61,9 +62,10 @@ public function search($query): array {
6162
$result[] = new Result($query,
6263
$comment,
6364
$displayName,
64-
$file->getPath()
65+
$file->getPath(),
66+
$file->getId(),
6567
);
66-
} catch (NotFoundException $e) {
68+
} catch (NotFoundException|InvalidPathException $e) {
6769
continue;
6870
}
6971
}

apps/comments/lib/Search/Result.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class Result extends BaseResult {
3434
* @deprecated 20.0.0
3535
*/
3636
public $fileName;
37+
/**
38+
* @deprecated 20.0.0
39+
*/
40+
public int $fileId;
3741

3842
/**
3943
* @throws NotFoundException
@@ -47,6 +51,7 @@ public function __construct(
4751
*/
4852
public string $authorName,
4953
string $path,
54+
int $fileId,
5055
) {
5156
parent::__construct(
5257
$comment->getId(),
@@ -58,6 +63,7 @@ public function __construct(
5863
$this->authorId = $comment->getActorId();
5964
$this->fileName = basename($path);
6065
$this->path = $this->getVisiblePath($path);
66+
$this->fileId = $fileId;
6167
}
6268

6369
/**

build/psalm-baseline.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
<code><![CDATA[$result->authorId]]></code>
7272
<code><![CDATA[$result->authorId]]></code>
7373
<code><![CDATA[$result->authorId]]></code>
74+
<code><![CDATA[$result->fileId]]></code>
75+
<code><![CDATA[$result->fileId]]></code>
7476
<code><![CDATA[$result->name]]></code>
7577
<code><![CDATA[$result->path]]></code>
7678
</DeprecatedProperty>
@@ -81,7 +83,8 @@
8183
<code><![CDATA[new Result($query,
8284
$comment,
8385
$displayName,
84-
$file->getPath()
86+
$file->getPath(),
87+
$file->getId(),
8588
)]]></code>
8689
</DeprecatedClass>
8790
<DeprecatedMethod>
@@ -108,6 +111,7 @@
108111
<DeprecatedProperty>
109112
<code><![CDATA[$this->authorId]]></code>
110113
<code><![CDATA[$this->comment]]></code>
114+
<code><![CDATA[$this->fileId]]></code>
111115
<code><![CDATA[$this->fileName]]></code>
112116
<code><![CDATA[$this->path]]></code>
113117
</DeprecatedProperty>

0 commit comments

Comments
 (0)