0
0
Fork 0
mirror of https://github.com/verdigado/organization_folders.git synced 2024-11-22 12:40:28 +01:00
organization_folders/lib/Dav/PropFindPlugin.php

56 lines
1.5 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace OCA\OrganizationFolders\Dav;
use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
use Sabre\DAV\INode;
use Sabre\DAV\PropFind;
use OCA\DAV\Connector\Sabre\Node;
use OCA\GroupFolders\Folder\FolderManager;
use OCA\GroupFolders\Mount\GroupMountPoint;
use OCA\OrganizationFolders\Service\ResourceService;
class PropFindPlugin extends ServerPlugin {
public const ORGANIZATION_FOLDER_ID_PROPERTYNAME = '{http://verdigado.com/ns}organization-folder-id';
public const ORGANIZATION_FOLDER_RESOURCE_ID_PROPERTYNAME = '{http://verdigado.com/ns}organization-folder-resource-id';
public function __construct(
private FolderManager $folderManager,
private ResourceService $resourceService,
) {
}
public function initialize(Server $server): void {
$server->on('propFind', $this->propFind(...));
}
public function propFind(PropFind $propFind, INode $node): void {
if (!$node instanceof Node) {
return;
}
$fileInfo = $node->getFileInfo();
$mount = $fileInfo->getMountPoint();
if (!$mount instanceof GroupMountPoint) {
return;
}
$propFind->handle(self::ORGANIZATION_FOLDER_ID_PROPERTYNAME, function () use ($fileInfo): int {
return $this->folderManager->getFolderByPath($fileInfo->getPath());
});
$propFind->handle(self::ORGANIZATION_FOLDER_RESOURCE_ID_PROPERTYNAME, function () use ($node): ?int {
try {
return $this->resourceService->findByFileId($node->getId())->getId();
} catch (\Exception $e) {
return null;
}
});
}
}