mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
Merge pull request #58092 from nextcloud/backport/57914/stable32
[stable32] feat(dav): allow extending propfind properties via event
This commit is contained in:
commit
80faad97a4
4 changed files with 76 additions and 2 deletions
|
|
@ -431,6 +431,7 @@ return array(
|
|||
'OCP\\Files\\Events\\BeforeFileScannedEvent' => $baseDir . '/lib/public/Files/Events/BeforeFileScannedEvent.php',
|
||||
'OCP\\Files\\Events\\BeforeFileSystemSetupEvent' => $baseDir . '/lib/public/Files/Events/BeforeFileSystemSetupEvent.php',
|
||||
'OCP\\Files\\Events\\BeforeFolderScannedEvent' => $baseDir . '/lib/public/Files/Events/BeforeFolderScannedEvent.php',
|
||||
'OCP\\Files\\Events\\BeforeRemotePropfindEvent' => $baseDir . '/lib/public/Files/Events/BeforeRemotePropfindEvent.php',
|
||||
'OCP\\Files\\Events\\BeforeZipCreatedEvent' => $baseDir . '/lib/public/Files/Events/BeforeZipCreatedEvent.php',
|
||||
'OCP\\Files\\Events\\FileCacheUpdated' => $baseDir . '/lib/public/Files/Events/FileCacheUpdated.php',
|
||||
'OCP\\Files\\Events\\FileScannedEvent' => $baseDir . '/lib/public/Files/Events/FileScannedEvent.php',
|
||||
|
|
|
|||
|
|
@ -472,6 +472,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OCP\\Files\\Events\\BeforeFileScannedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeFileScannedEvent.php',
|
||||
'OCP\\Files\\Events\\BeforeFileSystemSetupEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeFileSystemSetupEvent.php',
|
||||
'OCP\\Files\\Events\\BeforeFolderScannedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeFolderScannedEvent.php',
|
||||
'OCP\\Files\\Events\\BeforeRemotePropfindEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeRemotePropfindEvent.php',
|
||||
'OCP\\Files\\Events\\BeforeZipCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeZipCreatedEvent.php',
|
||||
'OCP\\Files\\Events\\FileCacheUpdated' => __DIR__ . '/../../..' . '/lib/public/Files/Events/FileCacheUpdated.php',
|
||||
'OCP\\Files\\Events\\FileScannedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/FileScannedEvent.php',
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ use OC\MemCache\ArrayCache;
|
|||
use OCP\AppFramework\Http;
|
||||
use OCP\Constants;
|
||||
use OCP\Diagnostics\IEventLogger;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Files\Events\BeforeRemotePropfindEvent;
|
||||
use OCP\Files\FileInfo;
|
||||
use OCP\Files\ForbiddenException;
|
||||
use OCP\Files\IMimeTypeDetector;
|
||||
|
|
@ -232,6 +234,34 @@ class DAV extends Common {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
protected function getPropfindProperties(): array {
|
||||
$event = new BeforeRemotePropfindEvent(self::PROPFIND_PROPS);
|
||||
Server::get(IEventDispatcher::class)->dispatchTyped($event);
|
||||
return $event->getProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get property value from cached PROPFIND response.
|
||||
* For accessing app-specific properties not included in getMetaData().
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $propertyName
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPropfindPropertyValue(string $path, string $propertyName): mixed {
|
||||
$path = $this->cleanPath($path);
|
||||
$propfindResponse = $this->statCache->get($path);
|
||||
|
||||
if (!is_array($propfindResponse)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $propfindResponse[$propertyName] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Propfind call with cache handling.
|
||||
*
|
||||
|
|
@ -254,7 +284,7 @@ class DAV extends Common {
|
|||
try {
|
||||
$response = $this->client->propFind(
|
||||
$this->encodePath($path),
|
||||
self::PROPFIND_PROPS
|
||||
$this->getPropfindProperties()
|
||||
);
|
||||
$this->statCache->set($path, $response);
|
||||
} catch (ClientHttpException $e) {
|
||||
|
|
@ -818,7 +848,7 @@ class DAV extends Common {
|
|||
try {
|
||||
$responses = $this->client->propFind(
|
||||
$this->encodePath($directory),
|
||||
self::PROPFIND_PROPS,
|
||||
$this->getPropfindProperties(),
|
||||
1
|
||||
);
|
||||
|
||||
|
|
|
|||
42
lib/public/Files/Events/BeforeRemotePropfindEvent.php
Normal file
42
lib/public/Files/Events/BeforeRemotePropfindEvent.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCP\Files\Events;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* This event is fired before a PROPFIND request is sent to remote WebDAV storage
|
||||
* Used to extend the list of properties to request additional data from the remote server
|
||||
*
|
||||
* @since 32.0.7
|
||||
*/
|
||||
class BeforeRemotePropfindEvent extends Event {
|
||||
public function __construct(
|
||||
private array $properties,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
* @since 32.0.7
|
||||
*/
|
||||
public function getProperties(): array {
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string> $properties
|
||||
* @since 32.0.7
|
||||
*/
|
||||
public function addProperties(array $properties): void {
|
||||
array_push($this->properties, ...$properties);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue