only require user to be set in a query that handles tags
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
549db744dc
commit
b8d64d67fe
|
@ -788,6 +788,10 @@ class Cache implements ICache {
|
||||||
$query->whereStorageId();
|
$query->whereStorageId();
|
||||||
|
|
||||||
if ($this->querySearchHelper->shouldJoinTags($searchQuery->getSearchOperation())) {
|
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
|
$query
|
||||||
->innerJoin('file', 'vcategory_to_object', 'tagmap', $builder->expr()->eq('file.fileid', 'tagmap.objid'))
|
->innerJoin('file', 'vcategory_to_object', 'tagmap', $builder->expr()->eq('file.fileid', 'tagmap.objid'))
|
||||||
->innerJoin('tagmap', 'vcategory', 'tag', $builder->expr()->andX(
|
->innerJoin('tagmap', 'vcategory', 'tag', $builder->expr()->andX(
|
||||||
|
@ -795,7 +799,7 @@ class Cache implements ICache {
|
||||||
$builder->expr()->eq('tagmap.categoryid', 'tag.id')
|
$builder->expr()->eq('tagmap.categoryid', 'tag.id')
|
||||||
))
|
))
|
||||||
->andWhere($builder->expr()->eq('tag.type', $builder->createNamedParameter('files')))
|
->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());
|
$searchExpr = $this->querySearchHelper->searchOperatorToDBExpr($builder, $searchQuery->getSearchOperation());
|
||||||
|
|
|
@ -37,7 +37,7 @@ class SearchQuery implements ISearchQuery {
|
||||||
private $offset;
|
private $offset;
|
||||||
/** @var ISearchOrder[] */
|
/** @var ISearchOrder[] */
|
||||||
private $order;
|
private $order;
|
||||||
/** @var IUser */
|
/** @var ?IUser */
|
||||||
private $user;
|
private $user;
|
||||||
private $limitToHome;
|
private $limitToHome;
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ class SearchQuery implements ISearchQuery {
|
||||||
* @param int $limit
|
* @param int $limit
|
||||||
* @param int $offset
|
* @param int $offset
|
||||||
* @param array $order
|
* @param array $order
|
||||||
* @param IUser $user
|
* @param ?IUser $user
|
||||||
* @param bool $limitToHome
|
* @param bool $limitToHome
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
@ -56,7 +56,7 @@ class SearchQuery implements ISearchQuery {
|
||||||
int $limit,
|
int $limit,
|
||||||
int $offset,
|
int $offset,
|
||||||
array $order,
|
array $order,
|
||||||
IUser $user,
|
?IUser $user = null,
|
||||||
bool $limitToHome = false
|
bool $limitToHome = false
|
||||||
) {
|
) {
|
||||||
$this->searchOperation = $searchOperation;
|
$this->searchOperation = $searchOperation;
|
||||||
|
@ -96,7 +96,7 @@ class SearchQuery implements ISearchQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return IUser
|
* @return ?IUser
|
||||||
*/
|
*/
|
||||||
public function getUser() {
|
public function getUser() {
|
||||||
return $this->user;
|
return $this->user;
|
||||||
|
|
|
@ -62,7 +62,7 @@ interface ISearchQuery {
|
||||||
/**
|
/**
|
||||||
* The user that issued the search
|
* The user that issued the search
|
||||||
*
|
*
|
||||||
* @return IUser
|
* @return ?IUser
|
||||||
* @since 12.0.0
|
* @since 12.0.0
|
||||||
*/
|
*/
|
||||||
public function getUser();
|
public function getUser();
|
||||||
|
|
|
@ -305,10 +305,9 @@ class FolderTest extends NodeTest {
|
||||||
->willReturn('foo');
|
->willReturn('foo');
|
||||||
|
|
||||||
$cache->expects($this->once())
|
$cache->expects($this->once())
|
||||||
->method('search')
|
->method('searchQuery')
|
||||||
->with('%qw%')
|
|
||||||
->willReturn([
|
->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())
|
$root->expects($this->once())
|
||||||
|
@ -358,11 +357,10 @@ class FolderTest extends NodeTest {
|
||||||
->willReturn($cache);
|
->willReturn($cache);
|
||||||
|
|
||||||
$cache->expects($this->once())
|
$cache->expects($this->once())
|
||||||
->method('search')
|
->method('searchQuery')
|
||||||
->with('%qw%')
|
|
||||||
->willReturn([
|
->willReturn([
|
||||||
['fileid' => 3, 'path' => 'files/foo', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain'],
|
new CacheEntry(['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_trashbin/foo2.d12345', 'name' => 'foo2.d12345', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$root->expects($this->once())
|
$root->expects($this->once())
|
||||||
|
@ -409,10 +407,9 @@ class FolderTest extends NodeTest {
|
||||||
->willReturn($cache);
|
->willReturn($cache);
|
||||||
|
|
||||||
$cache->expects($this->once())
|
$cache->expects($this->once())
|
||||||
->method('search')
|
->method('searchQuery')
|
||||||
->with('%qw%')
|
|
||||||
->willReturn([
|
->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())
|
$root->expects($this->once())
|
||||||
|
@ -475,17 +472,15 @@ class FolderTest extends NodeTest {
|
||||||
->willReturn($subCache);
|
->willReturn($subCache);
|
||||||
|
|
||||||
$cache->expects($this->once())
|
$cache->expects($this->once())
|
||||||
->method('search')
|
->method('searchQuery')
|
||||||
->with('%qw%')
|
|
||||||
->willReturn([
|
->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())
|
$subCache->expects($this->once())
|
||||||
->method('search')
|
->method('searchQuery')
|
||||||
->with('%qw%')
|
|
||||||
->willReturn([
|
->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())
|
$root->expects($this->once())
|
||||||
|
|
Loading…
Reference in New Issue