diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index f1b4b48a1b..b84d9b218b 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -190,10 +190,10 @@ class Cache implements ICache { } $data['permissions'] = (int)$data['permissions']; if (isset($data['creation_time'])) { - $data['creation_time'] = (int) $data['creation_time']; + $data['creation_time'] = (int)$data['creation_time']; } if (isset($data['upload_time'])) { - $data['upload_time'] = (int) $data['upload_time']; + $data['upload_time'] = (int)$data['upload_time']; } return new CacheEntry($data); } @@ -819,6 +819,10 @@ class Cache implements ICache { $query->whereStorageId(); if ($this->querySearchHelper->shouldJoinTags($searchQuery->getSearchOperation())) { + $user = $searchQuery->getUser(); + if ($user === null) { + throw new \InvalidArgumentException("Searching by tag requires the user to be set in the query"); + } $query ->innerJoin('file', 'vcategory_to_object', 'tagmap', $builder->expr()->eq('file.fileid', 'tagmap.objid')) ->innerJoin('tagmap', 'vcategory', 'tag', $builder->expr()->andX( @@ -826,7 +830,7 @@ class Cache implements ICache { $builder->expr()->eq('tagmap.categoryid', 'tag.id') )) ->andWhere($builder->expr()->eq('tag.type', $builder->createNamedParameter('files'))) - ->andWhere($builder->expr()->eq('tag.uid', $builder->createNamedParameter($searchQuery->getUser()->getUID()))); + ->andWhere($builder->expr()->eq('tag.uid', $builder->createNamedParameter($user->getUID()))); } $searchExpr = $this->querySearchHelper->searchOperatorToDBExpr($builder, $searchQuery->getSearchOperation()); @@ -1007,7 +1011,7 @@ class Cache implements ICache { return null; } - return (string) $path; + return (string)$path; } /** diff --git a/lib/private/Files/Search/SearchQuery.php b/lib/private/Files/Search/SearchQuery.php index b7b8b80110..091fe57d21 100644 --- a/lib/private/Files/Search/SearchQuery.php +++ b/lib/private/Files/Search/SearchQuery.php @@ -37,7 +37,7 @@ class SearchQuery implements ISearchQuery { private $offset; /** @var ISearchOrder[] */ private $order; - /** @var IUser */ + /** @var ?IUser */ private $user; private $limitToHome; @@ -48,7 +48,7 @@ class SearchQuery implements ISearchQuery { * @param int $limit * @param int $offset * @param array $order - * @param IUser $user + * @param ?IUser $user * @param bool $limitToHome */ public function __construct( @@ -56,7 +56,7 @@ class SearchQuery implements ISearchQuery { int $limit, int $offset, array $order, - IUser $user, + ?IUser $user = null, bool $limitToHome = false ) { $this->searchOperation = $searchOperation; @@ -96,7 +96,7 @@ class SearchQuery implements ISearchQuery { } /** - * @return IUser + * @return ?IUser */ public function getUser() { return $this->user; diff --git a/lib/public/Files/Search/ISearchQuery.php b/lib/public/Files/Search/ISearchQuery.php index 4d866f8d7b..dd7c901f7f 100644 --- a/lib/public/Files/Search/ISearchQuery.php +++ b/lib/public/Files/Search/ISearchQuery.php @@ -62,7 +62,7 @@ interface ISearchQuery { /** * The user that issued the search * - * @return IUser + * @return ?IUser * @since 12.0.0 */ public function getUser(); diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index 1ba052b8de..6d3367ac09 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -305,10 +305,9 @@ class FolderTest extends NodeTest { ->willReturn('foo'); $cache->expects($this->once()) - ->method('search') - ->with('%qw%') + ->method('searchQuery') ->willReturn([ - ['fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'] + new CacheEntry(['fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']) ]); $root->expects($this->once()) @@ -358,11 +357,10 @@ class FolderTest extends NodeTest { ->willReturn($cache); $cache->expects($this->once()) - ->method('search') - ->with('%qw%') + ->method('searchQuery') ->willReturn([ - ['fileid' => 3, 'path' => 'files/foo', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'], - ['fileid' => 3, 'path' => 'files_trashbin/foo2.d12345', 'name' => 'foo2.d12345', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'], + new CacheEntry(['fileid' => 3, 'path' => 'files/foo', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']), + new CacheEntry(['fileid' => 3, 'path' => 'files_trashbin/foo2.d12345', 'name' => 'foo2.d12345', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']), ]); $root->expects($this->once()) @@ -409,10 +407,9 @@ class FolderTest extends NodeTest { ->willReturn($cache); $cache->expects($this->once()) - ->method('search') - ->with('%qw%') + ->method('searchQuery') ->willReturn([ - ['fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'] + new CacheEntry(['fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']) ]); $root->expects($this->once()) @@ -475,17 +472,15 @@ class FolderTest extends NodeTest { ->willReturn($subCache); $cache->expects($this->once()) - ->method('search') - ->with('%qw%') + ->method('searchQuery') ->willReturn([ - ['fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'] + new CacheEntry(['fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']) ]); $subCache->expects($this->once()) - ->method('search') - ->with('%qw%') + ->method('searchQuery') ->willReturn([ - ['fileid' => 4, 'path' => 'asd/qweasd', 'name' => 'qweasd', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'] + new CacheEntry(['fileid' => 4, 'path' => 'asd/qweasd', 'name' => 'qweasd', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']) ]); $root->expects($this->once())