summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2022-04-14 22:08:23 +0200
committerGitHub <noreply@github.com>2022-04-14 22:08:23 +0200
commit24aae72e7e6b65458b867d42cf5f1e0d30d3b985 (patch)
tree9526efa1259e8859c9f94a8fa4d3427fa33fa50d
parente5c6de3c01bf9c1af56cab2f0af2003361413605 (diff)
parent6b1fbb4fb10533dc477637dcd2fd966fec02a44d (diff)
downloadnextcloud-server-24aae72e7e6b65458b867d42cf5f1e0d30d3b985.tar.gz
nextcloud-server-24aae72e7e6b65458b867d42cf5f1e0d30d3b985.zip
Merge pull request #31641 from nextcloud/backport/31193/stable23
[stable23] Add optional WebDav propfind properties to count sub elements
-rw-r--r--apps/dav/lib/Connector/Sabre/FilesPlugin.php21
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 156507e4467..0fc7ac4af4e 100644
--- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php
+++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php
@@ -76,6 +76,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
@@ -429,7 +431,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();
});
@@ -437,6 +439,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);
+ }
}
}