From 49cda5a8fccc94b1185f496bd7779f4a80dfff01 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Tue, 21 Dec 2021 13:38:43 +0100 Subject: [PATCH 1/2] DAV SEARCH: Expose upload_time and creation_time fixes #21385 --- apps/dav/lib/Connector/Sabre/FilesPlugin.php | 3 +++ apps/dav/lib/Files/FileSearchBackend.php | 13 +++++++++++++ lib/private/Files/Cache/SearchBuilder.php | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index 95f3db9a65b32..4ee056a1c0a03 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -404,6 +404,9 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) $propFind->handle(self::CREATION_TIME_PROPERTYNAME, function () use ($node) { return $node->getFileInfo()->getCreationTime(); }); + $propFind->handle(self::CREATIONDATE_PROPERTYNAME, function () use ($node) { + return $node->getFileInfo()->getCreationTime(); + }); } if ($node instanceof \OCA\DAV\Connector\Sabre\File) { diff --git a/apps/dav/lib/Files/FileSearchBackend.php b/apps/dav/lib/Files/FileSearchBackend.php index 45e911db182a0..123f8b86fb654 100644 --- a/apps/dav/lib/Files/FileSearchBackend.php +++ b/apps/dav/lib/Files/FileSearchBackend.php @@ -118,6 +118,9 @@ public function getPropertyDefinitionsForScope($href, $path) { new SearchPropertyDefinition('{DAV:}displayname', true, true, true), new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true), new SearchPropertyDefinition('{DAV:}getlastmodified', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME), + new SearchPropertyDefinition('{DAV:}creationdate', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME), + new SearchPropertyDefinition(FilesPlugin::CREATION_TIME_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME), + new SearchPropertyDefinition(FilesPlugin::UPLOAD_TIME_PROPERTYNAME, 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), new SearchPropertyDefinition(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, true, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), @@ -249,6 +252,11 @@ private function getSearchResultProperty(SearchResult $result, SearchPropertyDef return $node->getName(); case '{DAV:}getlastmodified': return $node->getLastModified(); + case '{DAV:}creationdate': + case FilesPlugin::CREATION_TIME_PROPERTYNAME: + return $node->getFileInfo()->getCreationTime(); + case FilesPlugin::UPLOAD_TIME_PROPERTYNAME: + return $node->getFileInfo()->getUploadTime(); case FilesPlugin::SIZE_PROPERTYNAME: return $node->getSize(); case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME: @@ -351,6 +359,11 @@ private function mapPropertyNameToColumn(SearchPropertyDefinition $property) { return 'mimetype'; case '{DAV:}getlastmodified': return 'mtime'; + case '{DAV:}creationdate': + case FilesPlugin::CREATION_TIME_PROPERTYNAME: + return 'creation_time'; + case FilesPlugin::UPLOAD_TIME_PROPERTYNAME: + return 'upload_time'; case FilesPlugin::SIZE_PROPERTYNAME: return 'size'; case TagsPlugin::FAVORITE_PROPERTYNAME: diff --git a/lib/private/Files/Cache/SearchBuilder.php b/lib/private/Files/Cache/SearchBuilder.php index 003d3ac15e776..3449c18d3df92 100644 --- a/lib/private/Files/Cache/SearchBuilder.php +++ b/lib/private/Files/Cache/SearchBuilder.php @@ -178,6 +178,8 @@ private function validateComparison(ISearchComparison $operator) { $types = [ 'mimetype' => 'string', 'mtime' => 'integer', + 'creation_time' => 'integer', + 'upload_time' => 'integer', 'name' => 'string', 'path' => 'string', 'size' => 'integer', @@ -188,6 +190,8 @@ private function validateComparison(ISearchComparison $operator) { ]; $comparisons = [ 'mimetype' => ['eq', 'like'], + 'creation_time' => ['eq', 'gt', 'lt', 'gte', 'lte'], + 'upload_time' => ['eq', 'gt', 'lt', 'gte', 'lte'], 'mtime' => ['eq', 'gt', 'lt', 'gte', 'lte'], 'name' => ['eq', 'like', 'clike'], 'path' => ['eq', 'like', 'clike'], From d5a9f868aea38f597c5840fe06ba740f8ad8f741 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Wed, 27 Apr 2022 18:25:22 +0200 Subject: [PATCH 2/2] Add return type Co-authored-by: Carl Schwan --- apps/dav/lib/Connector/Sabre/FilesPlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index 4ee056a1c0a03..3f322034c33f7 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -404,7 +404,7 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) $propFind->handle(self::CREATION_TIME_PROPERTYNAME, function () use ($node) { return $node->getFileInfo()->getCreationTime(); }); - $propFind->handle(self::CREATIONDATE_PROPERTYNAME, function () use ($node) { + $propFind->handle(self::CREATIONDATE_PROPERTYNAME, function () use ($node): int { return $node->getFileInfo()->getCreationTime(); }); }