Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"psalm:clear": "psalm --clear-cache && psalm --clear-global-cache",
"psalm:fix": "psalm --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType",
"test": "@test:unit",
"test:unit": "phpunit --configuration tests/phpunit.xml --no-coverage"
"test:unit": "TEST_DONT_LOAD_APPS=1 phpunit --configuration tests/phpunit.xml --no-coverage"
},
"config": {
"optimize-autoloader": true,
Expand Down
36 changes: 23 additions & 13 deletions lib/Controller/QueueController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace OCA\ContextChat\Controller;

use OC\User\NoUserException;
use OCA\ContextChat\BackgroundJobs\StorageCrawlJob;
use OCA\ContextChat\Db\QueueActionMapper;
use OCA\ContextChat\Db\QueueContentItem;
Expand All @@ -30,6 +31,7 @@
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\DB\Exception;
use OCP\Files\Config\ICachedMountInfo;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\File;
use OCP\Files\IRootFolder;
Expand Down Expand Up @@ -96,7 +98,6 @@ public function getFileContents(IRootFolder $rootFolder, int $fileId, string $us
#[ExAppRequired]
#[ApiRoute(verb: 'GET', url: '/queues/documents/')]
public function getDocumentsQueueItems(
StorageService $storageService,
IRootFolder $rootFolder,
QueueMapper $queueMapper,
QueueContentItemMapper $queueContentItemMapper,
Expand All @@ -122,7 +123,7 @@ public function getDocumentsQueueItems(
foreach ($documents as $document) {
if ($queueMapper->lock($document->getId())) {
try {
$files[$document->getId()] = $this->getFileSource($document, $rootFolder, $storageService, $userMountCache);
$files[$document->getId()] = $this->getFileSource($document, $rootFolder, $userMountCache);
} catch (\Exception $e) {
$this->logger->warning($e->getMessage(), ['exception' => $e]);
$queueMapper->delete($document);
Expand Down Expand Up @@ -285,22 +286,31 @@ public function countActionsQueueItems(QueueActionMapper $queueActionMapper) : D
}
}

private function getFileSource(QueueFile $document, IRootFolder $rootFolder, StorageService $storageService, IUserMountCache $userMountCache) : Source {
$mounts = $userMountCache->getMountsForStorageId($document->getStorageId());
private function getFileSource(QueueFile $document, IRootFolder $rootFolder, IUserMountCache $userMountCache) : Source {
$mounts = $userMountCache->getMountsForFileId($document->getFileId());
if (empty($mounts)) {
throw new \Exception('Couldn\'t find any mounts for this storage');
throw new \Exception('Couldn\'t find any mounts for file ' . $document->getFileId());
}
$userId = $mounts[0]->getUser()->getUID();
$userIds = array_values(array_unique(array_map(
static fn (ICachedMountInfo $mountInfo) => $mountInfo->getUser()->getUID(),
$mounts,
)));

try {
$file = $rootFolder->getUserFolder($userId)->getFirstNodeById($document->getFileId());
} catch (NotPermittedException $e) {
throw new \Exception('Not allowed to get user folder');
$file = null;
foreach ($userIds as $userId) {
try {
$node = $rootFolder->getUserFolder($userId)->getFirstNodeById($document->getFileId());
} catch (NotPermittedException|NoUserException) {
continue;
}
if ($node instanceof File) {
$file = $node;
break;
}
}
if (!($file instanceof File)) {
throw new \Exception('File not found or not a file');
if ($file === null) {
throw new \Exception('File ' . $document->getFileId() . ' not found or not a file (tried users: ' . implode(', ', $userIds) . ')');
}
$userIds = $storageService->getUsersForFileId($document->getFileId());

return new Source(
$userIds,
Expand Down
5 changes: 5 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,10 @@
<directory name="lib" />
</errorLevel>
</MissingOverrideAttribute>
<UndefinedClass>
<errorLevel type="suppress">
<referencedClass name="OC\User\NoUserException" />
</errorLevel>
</UndefinedClass>
</issueHandlers>
</psalm>
Loading
Loading