summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2017-03-08 15:17:39 +0100
committerRobin Appelman <robin@icewind.nl>2017-03-08 16:30:55 +0100
commite61606a767cd6e2c28e3897e7e913e39371078e5 (patch)
treeb2d0cf869dae5f4cce698ca647f827aab178aaa0 /apps/dav
parent2a8e922d67a1246e101f926f1b0ab287db71929e (diff)
downloadnextcloud-server-e61606a767cd6e2c28e3897e7e913e39371078e5.tar.gz
nextcloud-server-e61606a767cd6e2c28e3897e7e913e39371078e5.zip
Allow searching for favorites
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/Files/FileSearchBackend.php16
-rw-r--r--apps/dav/tests/unit/Files/FileSearchBackendTest.php15
2 files changed, 21 insertions, 10 deletions
diff --git a/apps/dav/lib/Files/FileSearchBackend.php b/apps/dav/lib/Files/FileSearchBackend.php
index c429a1727f8..afdb425e8ed 100644
--- a/apps/dav/lib/Files/FileSearchBackend.php
+++ b/apps/dav/lib/Files/FileSearchBackend.php
@@ -28,6 +28,7 @@ use OC\Files\Search\SearchQuery;
use OC\Files\View;
use OCA\DAV\Connector\Sabre\Directory;
use OCA\DAV\Connector\Sabre\FilesPlugin;
+use OCA\DAV\Connector\Sabre\TagsPlugin;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
@@ -114,6 +115,7 @@ class FileSearchBackend implements ISearchBackend {
new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true),
new SearchPropertyDefinition('{DAV:}getlastmodifed', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
+ new SearchPropertyDefinition(TagsPlugin::FAVORITE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_BOOLEAN),
// select only properties
new SearchPropertyDefinition('{DAV:}resourcetype', false, true, false),
@@ -178,7 +180,7 @@ class FileSearchBackend implements ISearchBackend {
private function transformQuery(BasicSearch $query) {
// TODO offset, limit
$orders = array_map([$this, 'mapSearchOrder'], $query->orderBy);
- return new SearchQuery($this->transformSearchOperation($query->where), 0, 0, $orders);
+ return new SearchQuery($this->transformSearchOperation($query->where), 0, 0, $orders, $this->user);
}
/**
@@ -186,7 +188,7 @@ class FileSearchBackend implements ISearchBackend {
* @return ISearchOrder
*/
private function mapSearchOrder(Order $order) {
- return new SearchOrder($order->order === Order::ASC ? ISearchOrder::DIRECTION_ASCENDING : ISearchOrder::DIRECTION_DESCENDING, $this->mapPropertyNameToCollumn($order->property));
+ return new SearchOrder($order->order === Order::ASC ? ISearchOrder::DIRECTION_ASCENDING : ISearchOrder::DIRECTION_DESCENDING, $this->mapPropertyNameToColumn($order->property));
}
/**
@@ -210,13 +212,13 @@ class FileSearchBackend implements ISearchBackend {
if (count($operator->arguments) !== 2) {
throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation');
}
- if (gettype($operator->arguments[0]) !== 'string') {
+ if (!is_string($operator->arguments[0])) {
throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property');
}
if (!($operator->arguments[1] instanceof Literal)) {
throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal');
}
- return new SearchComparison($trimmedType, $this->mapPropertyNameToCollumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value));
+ return new SearchComparison($trimmedType, $this->mapPropertyNameToColumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value));
case Operator::OPERATION_IS_COLLECTION:
return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE);
default:
@@ -228,7 +230,7 @@ class FileSearchBackend implements ISearchBackend {
* @param string $propertyName
* @return string
*/
- private function mapPropertyNameToCollumn($propertyName) {
+ private function mapPropertyNameToColumn($propertyName) {
switch ($propertyName) {
case '{DAV:}displayname':
return 'name';
@@ -238,6 +240,10 @@ class FileSearchBackend implements ISearchBackend {
return 'mtime';
case FilesPlugin::SIZE_PROPERTYNAME:
return 'size';
+ case TagsPlugin::FAVORITE_PROPERTYNAME:
+ return 'favorite';
+ case TagsPlugin::TAGS_PROPERTYNAME:
+ return 'tagname';
default:
throw new \InvalidArgumentException('Unsupported property for search or order: ' . $propertyName);
}
diff --git a/apps/dav/tests/unit/Files/FileSearchBackendTest.php b/apps/dav/tests/unit/Files/FileSearchBackendTest.php
index 24b9a9c51e6..539344b22d5 100644
--- a/apps/dav/tests/unit/Files/FileSearchBackendTest.php
+++ b/apps/dav/tests/unit/Files/FileSearchBackendTest.php
@@ -122,7 +122,8 @@ class FileSearchBackendTest extends TestCase {
),
0,
0,
- []
+ [],
+ $this->user
))
->will($this->returnValue([
new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path')
@@ -150,7 +151,8 @@ class FileSearchBackendTest extends TestCase {
),
0,
0,
- []
+ [],
+ $this->user
))
->will($this->returnValue([
new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path')
@@ -178,7 +180,8 @@ class FileSearchBackendTest extends TestCase {
),
0,
0,
- []
+ [],
+ $this->user
))
->will($this->returnValue([
new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path')
@@ -206,7 +209,8 @@ class FileSearchBackendTest extends TestCase {
),
0,
0,
- []
+ [],
+ $this->user
))
->will($this->returnValue([
new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path')
@@ -234,7 +238,8 @@ class FileSearchBackendTest extends TestCase {
),
0,
0,
- []
+ [],
+ $this->user
))
->will($this->returnValue([
new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path')