diff options
author | Julien Veyssier <eneiluj@posteo.net> | 2022-02-15 16:18:41 +0100 |
---|---|---|
committer | Julien Veyssier <eneiluj@posteo.net> | 2022-03-19 21:22:56 +0100 |
commit | 71a9ebc754cabda63c517144131b6270412a66b5 (patch) | |
tree | 4f46d6778c2519c08ccfbdd2fcc46b32d461f70e /apps/dav/lib/Connector/Sabre/FilesPlugin.php | |
parent | a1c148a7e7810e104834dea89e8f61bad76424f1 (diff) | |
download | nextcloud-server-71a9ebc754cabda63c517144131b6270412a66b5.tar.gz nextcloud-server-71a9ebc754cabda63c517144131b6270412a66b5.zip |
add optional WebDav propfind properties to show number of folders/files inside a folder
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
Diffstat (limited to 'apps/dav/lib/Connector/Sabre/FilesPlugin.php')
-rw-r--r-- | apps/dav/lib/Connector/Sabre/FilesPlugin.php | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index 95f3db9a65b..017b1d31841 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -77,6 +77,8 @@ class FilesPlugin extends ServerPlugin { public const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time'; public const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time'; public const SHARE_NOTE = '{http://nextcloud.org/ns}note'; + public const SUBFOLDER_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-folder-count'; + public const SUBFILE_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-file-count'; /** * Reference to main server object @@ -435,7 +437,7 @@ class FilesPlugin extends ServerPlugin { }); } - if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) { + if ($node instanceof Directory) { $propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node) { return $node->getSize(); }); @@ -443,6 +445,23 @@ class FilesPlugin extends ServerPlugin { $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function () use ($node) { return $node->getFileInfo()->isEncrypted() ? '1' : '0'; }); + + $requestProperties = $propFind->getRequestedProperties(); + if (in_array(self::SUBFILE_COUNT_PROPERTYNAME, $requestProperties, true) + || in_array(self::SUBFOLDER_COUNT_PROPERTYNAME, $requestProperties, true)) { + $nbFiles = 0; + $nbFolders = 0; + foreach ($node->getChildren() as $child) { + if ($child instanceof File) { + $nbFiles++; + } elseif ($child instanceof Directory) { + $nbFolders++; + } + } + + $propFind->handle(self::SUBFILE_COUNT_PROPERTYNAME, $nbFiles); + $propFind->handle(self::SUBFOLDER_COUNT_PROPERTYNAME, $nbFolders); + } } } |