Skip to content

Commit b85bdf4

Browse files
author
Julien Veyssier
authored
Merge pull request #31193 from nextcloud/enh/webdav-propfind-count-sub-elements
Add optional WebDav propfind properties to count sub elements
2 parents 012668d + 71a9ebc commit b85bdf4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

apps/dav/lib/Connector/Sabre/FilesPlugin.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class FilesPlugin extends ServerPlugin {
7777
public const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time';
7878
public const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time';
7979
public const SHARE_NOTE = '{http://nextcloud.org/ns}note';
80+
public const SUBFOLDER_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-folder-count';
81+
public const SUBFILE_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-file-count';
8082

8183
/**
8284
* Reference to main server object
@@ -435,14 +437,31 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
435437
});
436438
}
437439

438-
if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
440+
if ($node instanceof Directory) {
439441
$propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node) {
440442
return $node->getSize();
441443
});
442444

443445
$propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function () use ($node) {
444446
return $node->getFileInfo()->isEncrypted() ? '1' : '0';
445447
});
448+
449+
$requestProperties = $propFind->getRequestedProperties();
450+
if (in_array(self::SUBFILE_COUNT_PROPERTYNAME, $requestProperties, true)
451+
|| in_array(self::SUBFOLDER_COUNT_PROPERTYNAME, $requestProperties, true)) {
452+
$nbFiles = 0;
453+
$nbFolders = 0;
454+
foreach ($node->getChildren() as $child) {
455+
if ($child instanceof File) {
456+
$nbFiles++;
457+
} elseif ($child instanceof Directory) {
458+
$nbFolders++;
459+
}
460+
}
461+
462+
$propFind->handle(self::SUBFILE_COUNT_PROPERTYNAME, $nbFiles);
463+
$propFind->handle(self::SUBFOLDER_COUNT_PROPERTYNAME, $nbFolders);
464+
}
446465
}
447466
}
448467

0 commit comments

Comments
 (0)