Skip to content

Commit

Permalink
Merge pull request #3824 from nextcloud/dav-search-getlastmodified
Browse files Browse the repository at this point in the history
fix searching and ordering on getlastmodified
  • Loading branch information
icewind1991 authored Mar 14, 2017
2 parents 8d91c84 + e392d02 commit 8217b16
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions apps/dav/lib/Files/FileSearchBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function getPropertyDefinitionsForScope($href, $path) {
// 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),

Expand Down Expand Up @@ -236,7 +236,7 @@ private function mapPropertyNameToColumn($propertyName) {
return 'name';
case '{DAV:}getcontenttype':
return 'mimetype';
case '{DAV:}getlastmodifed':
case '{DAV:}getlastmodified':
return 'mtime';
case FilesPlugin::SIZE_PROPERTYNAME:
return 'size';
Expand All @@ -261,6 +261,12 @@ private function castValue($propertyName, $value) {
case SearchPropertyDefinition::DATATYPE_INTEGER:
case SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER:
return 0 + $value;
case SearchPropertyDefinition::DATATYPE_DATETIME:
if (is_numeric($value)) {
return 0 + $value;
}
$date = \DateTime::createFromFormat(\DateTime::ATOM, $value);
return ($date instanceof \DateTime) ? $date->getTimestamp() : 0;
default:
return $value;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/Files/FileSearchBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function testSearchMtime() {
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);
Expand Down

0 comments on commit 8217b16

Please sign in to comment.