use OCP\Files\IMimeTypeLoader;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
+use OCP\IUserSession;
use Psr\Log\LoggerInterface;
class FileEventsListener implements IEventListener {
- private IRootFolder $rootFolder;
- private IVersionManager $versionManager;
/**
* @var array<int, array>
*/
* @var array<string, Node>
*/
private array $versionsDeleted = [];
- private IMimeTypeLoader $mimeTypeLoader;
- private LoggerInterface $logger;
public function __construct(
- IRootFolder $rootFolder,
- IVersionManager $versionManager,
- IMimeTypeLoader $mimeTypeLoader,
- LoggerInterface $logger,
+ private IRootFolder $rootFolder,
+ private IVersionManager $versionManager,
+ private IMimeTypeLoader $mimeTypeLoader,
+ private IUserSession $userSession,
+ private LoggerInterface $logger,
) {
- $this->rootFolder = $rootFolder;
- $this->versionManager = $versionManager;
- $this->mimeTypeLoader = $mimeTypeLoader;
- $this->logger = $logger;
}
public function handle(Event $event): void {
* If no user is connected, try to use the node's owner.
*/
private function getPathForNode(Node $node): ?string {
- try {
+ $user = $this->userSession->getUser()?->getUID();
+ if ($user) {
return $this->rootFolder
- ->getUserFolder(\OC_User::getUser())
+ ->getUserFolder($user)
->getRelativePath($node->getPath());
- } catch (\Throwable $ex) {
- $owner = $node->getOwner();
- if ($owner === null) {
- return null;
- }
+ }
+
+ $owner = $node->getOwner()?->getUid();
+ if ($owner) {
return $this->rootFolder
- ->getUserFolder($owner->getUid())
+ ->getUserFolder($owner)
->getRelativePath($node->getPath());
}
+
+ return null;
}
}