From 6074dc9979fbf93eb61f05bc0c5c0512ebc9e070 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 13 Mar 2017 14:44:52 +0100 Subject: fix searching and ordering on getlastmodified Signed-off-by: Robin Appelman --- apps/dav/lib/Files/FileSearchBackend.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/dav/lib/Files/FileSearchBackend.php b/apps/dav/lib/Files/FileSearchBackend.php index afdb425e8ed..784047ad255 100644 --- a/apps/dav/lib/Files/FileSearchBackend.php +++ b/apps/dav/lib/Files/FileSearchBackend.php @@ -113,7 +113,7 @@ class FileSearchBackend implements ISearchBackend { // queryable properties new SearchPropertyDefinition('{DAV:}displayname', true, false, true), new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true), - new SearchPropertyDefinition('{DAV:}getlastmodifed', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME), + new SearchPropertyDefinition('{DAV:}getlastmodified', 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), @@ -236,7 +236,7 @@ class FileSearchBackend implements ISearchBackend { return 'name'; case '{DAV:}getcontenttype': return 'mimetype'; - case '{DAV:}getlastmodifed': + case '{DAV:}getlastmodified': return 'mtime'; case FilesPlugin::SIZE_PROPERTYNAME: return 'size'; @@ -261,6 +261,8 @@ class FileSearchBackend implements ISearchBackend { case SearchPropertyDefinition::DATATYPE_INTEGER: case SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER: return 0 + $value; + case SearchPropertyDefinition::DATATYPE_DATETIME: + return \DateTime::createFromFormat(\DateTime::ATOM, $value)->getTimestamp(); default: return $value; } -- cgit v1.2.3 From ef14dc671f540419a044d353036763a02fe68d58 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 13 Mar 2017 15:59:04 -0600 Subject: fix unit test Signed-off-by: Morris Jobke --- apps/dav/tests/unit/Files/FileSearchBackendTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dav/tests/unit/Files/FileSearchBackendTest.php b/apps/dav/tests/unit/Files/FileSearchBackendTest.php index 539344b22d5..7de92c59763 100644 --- a/apps/dav/tests/unit/Files/FileSearchBackendTest.php +++ b/apps/dav/tests/unit/Files/FileSearchBackendTest.php @@ -216,7 +216,7 @@ class FileSearchBackendTest extends TestCase { new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path') ])); - $query = $this->getBasicQuery(Operator::OPERATION_GREATER_THAN, '{DAV:}getlastmodifed', 10); + $query = $this->getBasicQuery(Operator::OPERATION_GREATER_THAN, '{DAV:}getlastmodified', 10); $result = $this->search->search($query); $this->assertCount(1, $result); -- cgit v1.2.3 From e392d02d80fb347a93e57edf009c1f3ef3549415 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 14 Mar 2017 14:12:40 +0100 Subject: safer casting of datetime Signed-off-by: Robin Appelman --- apps/dav/lib/Files/FileSearchBackend.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/dav/lib/Files/FileSearchBackend.php b/apps/dav/lib/Files/FileSearchBackend.php index 784047ad255..5816c659932 100644 --- a/apps/dav/lib/Files/FileSearchBackend.php +++ b/apps/dav/lib/Files/FileSearchBackend.php @@ -262,7 +262,11 @@ class FileSearchBackend implements ISearchBackend { case SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER: return 0 + $value; case SearchPropertyDefinition::DATATYPE_DATETIME: - return \DateTime::createFromFormat(\DateTime::ATOM, $value)->getTimestamp(); + if (is_numeric($value)) { + return 0 + $value; + } + $date = \DateTime::createFromFormat(\DateTime::ATOM, $value); + return ($date instanceof \DateTime) ? $date->getTimestamp() : 0; default: return $value; } -- cgit v1.2.3