Skip to content

Commit 3a69df1

Browse files
committed
fix: setup user FS before getting files by ID
Signed-off-by: Anupam Kumar <[email protected]>
1 parent 60c1607 commit 3a69df1

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

lib/Service/MetadataService.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace OCA\ContextChat\Service;
99

10+
use OC\Files\SetupManager;
1011
use OCA\ContextChat\Logger;
1112
use OCA\ContextChat\Public\ContentManager;
1213
use OCA\ContextChat\Public\IContentProvider;
@@ -166,14 +167,34 @@ public function getEnrichedSources(string $userId, string ...$sources): array {
166167
}
167168
}
168169

169-
# for files
170-
foreach ($sources as $source) {
171-
if (!str_starts_with($source, ProviderConfigService::getDefaultProviderKey() . ': ')) {
172-
continue;
173-
}
174-
$enrichedSources[] = $this->getMetadataObjectForId($userId, $source);
170+
$setupManager = \OCP\Server::get(SetupManager::class);
171+
$user = $this->userManager->get($userId);
172+
173+
if ($user === null) {
174+
$this->logger->warning('User not found for enriching sources', ['userId' => $userId]);
175+
return $enrichedSources;
175176
}
176177

177-
return $enrichedSources;
178+
try {
179+
$setupManager->setupForUser($user);
180+
} catch (\Throwable $e) {
181+
$this->logger->error('Error setting up filesystem for user ' . $userId . ': ' . $e->getMessage(), ['exception' => $e]);
182+
return $enrichedSources;
183+
}
184+
185+
try {
186+
# for files
187+
foreach ($sources as $source) {
188+
if (!str_starts_with($source, ProviderConfigService::getDefaultProviderKey() . ': ')) {
189+
continue;
190+
}
191+
$enrichedSources[] = $this->getMetadataObjectForId($userId, $source);
192+
}
193+
} catch (\Throwable $e) {
194+
$this->logger->error('Error enriching file sources: ' . $e->getMessage(), ['exception' => $e]);
195+
} finally {
196+
$setupManager->tearDown();
197+
return $enrichedSources;
198+
}
178199
}
179200
}

0 commit comments

Comments
 (0)