Skip to content

Commit 5471dd1

Browse files
committed
feat(dav): allow extending propfind properties via event
Signed-off-by: Benjamin Frueh <[email protected]>
1 parent ebfdbf8 commit 5471dd1

2 files changed

Lines changed: 72 additions & 2 deletions

File tree

lib/private/Files/Storage/DAV.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use OCP\AppFramework\Http;
1616
use OCP\Constants;
1717
use OCP\Diagnostics\IEventLogger;
18+
use OCP\EventDispatcher\IEventDispatcher;
19+
use OCP\Files\Events\BeforePropfindEvent;
1820
use OCP\Files\FileInfo;
1921
use OCP\Files\ForbiddenException;
2022
use OCP\Files\IMimeTypeDetector;
@@ -232,6 +234,34 @@ public function opendir(string $path) {
232234
return false;
233235
}
234236

237+
/**
238+
* @return array<string>
239+
*/
240+
protected function getPropfindProperties(): array {
241+
$event = new BeforePropfindEvent(self::PROPFIND_PROPS);
242+
Server::get(IEventDispatcher::class)->dispatchTyped($event);
243+
return $event->getProperties();
244+
}
245+
246+
/**
247+
* Get property value from cached PROPFIND response.
248+
* For accessing app-specific properties not included in getMetaData().
249+
*
250+
* @param string $path
251+
* @param string $propertyName
252+
* @return mixed
253+
*/
254+
public function getPropfindPropertyValue(string $path, string $propertyName): mixed {
255+
$path = $this->cleanPath($path);
256+
$propfindResponse = $this->statCache->get($path);
257+
258+
if (!is_array($propfindResponse)) {
259+
return null;
260+
}
261+
262+
return $propfindResponse[$propertyName] ?? null;
263+
}
264+
235265
/**
236266
* Propfind call with cache handling.
237267
*
@@ -254,7 +284,7 @@ protected function propfind(string $path): array|false {
254284
try {
255285
$response = $this->client->propFind(
256286
$this->encodePath($path),
257-
self::PROPFIND_PROPS
287+
$this->getPropfindProperties()
258288
);
259289
$this->statCache->set($path, $response);
260290
} catch (ClientHttpException $e) {
@@ -818,7 +848,7 @@ public function getDirectoryContent(string $directory): \Traversable {
818848
try {
819849
$responses = $this->client->propFind(
820850
$this->encodePath($directory),
821-
self::PROPFIND_PROPS,
851+
$this->getPropfindProperties(),
822852
1
823853
);
824854

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCP\Files\Events;
11+
12+
use OCP\EventDispatcher\Event;
13+
14+
/**
15+
* @since 32.0.0
16+
*/
17+
class BeforePropfindEvent extends Event {
18+
private array $properties;
19+
20+
public function __construct(array $properties) {
21+
parent::__construct();
22+
$this->properties = $properties;
23+
}
24+
25+
/**
26+
* @return array<string>
27+
* @since 32.0.0
28+
*/
29+
public function getProperties(): array {
30+
return $this->properties;
31+
}
32+
33+
/**
34+
* @param array<string> $properties
35+
* @since 32.0.0
36+
*/
37+
public function addProperties(array $properties): void {
38+
$this->properties = [...$this->properties, ...$properties];
39+
}
40+
}

0 commit comments

Comments
 (0)