diff --git a/lib/Listener/FileListener.php b/lib/Listener/FileListener.php index 42bc33f..d03d1b4 100644 --- a/lib/Listener/FileListener.php +++ b/lib/Listener/FileListener.php @@ -115,10 +115,39 @@ public function handle(Event $event): void { } $files = $this->storageService->getFilesInMount($mount->getNumericStorageId(), $node->getId(), 0, 0); foreach ($files as $fileId) { - $this->postInsert(current($this->rootFolder->getById($fileId)), false, true); + $node = current($this->rootFolder->getById($fileId)); + try { + $fileHandle = $node->fopen('r'); + } catch (LockedException|NotPermittedException $e) { + $this->logger->error('Could not open file ' . $node->getPath() . ' for reading', ['exception' => $e]); + return; + } + foreach ($userIds as $userId) { + try { + $source = new Source($userId, 'file: ' . $node->getId(), $fileHandle, $node->getMtime(), $node->getMimeType()); + } catch (InvalidPathException|NotFoundException $e) { + $this->logger->error('Could not find file ' . $node->getPath(), ['exception' => $e]); + break; + } + $this->langRopeService->deleteSources($userId, [$source]); + } } } else { - // TODO: remove index entry of $node for $userIds + try { + $fileHandle = $node->fopen('r'); + } catch (LockedException|NotPermittedException $e) { + $this->logger->error('Could not open file ' . $node->getPath() . ' for reading', ['exception' => $e]); + return; + } + foreach ($userIds as $userId) { + try { + $source = new Source($userId, 'file: ' . $node->getId(), $fileHandle, $node->getMtime(), $node->getMimeType()); + } catch (InvalidPathException|NotFoundException $e) { + $this->logger->error('Could not find file ' . $node->getPath(), ['exception' => $e]); + break; + } + $this->langRopeService->deleteSources($userId, [$source]); + } } } if ($event instanceof BeforeNodeDeletedEvent) {