Skip to content

Commit 88dcfe6

Browse files
icewind1991AndyScherzinger
authored andcommitted
feat: add mount id to info:storage(s)
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 3c36f17 commit 88dcfe6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

core/Command/Info/FileUtils.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
use Symfony\Component\Console\Output\OutputInterface;
2929

3030
/**
31-
* @psalm-type StorageInfo array{numeric_id: int, id: string, available: bool, last_checked: ?\DateTime, files: int}
31+
* @psalm-type StorageInfo array{numeric_id: int, id: string, available: bool, last_checked: ?\DateTime, files: int, mount_id: ?int}
3232
*/
3333
class FileUtils {
3434
public function __construct(
@@ -245,12 +245,13 @@ public function getNumericStorageId(string $id): ?int {
245245
*/
246246
public function getStorage(int $id): ?array {
247247
$query = $this->connection->getQueryBuilder();
248-
$query->select('numeric_id', 'id', 'available', 'last_checked')
248+
$query->select('numeric_id', 's.id', 'available', 'last_checked', 'mount_id')
249249
->selectAlias($query->func()->count('fileid'), 'files')
250250
->from('storages', 's')
251251
->innerJoin('s', 'filecache', 'f', $query->expr()->eq('f.storage', 's.numeric_id'))
252+
->leftJoin('s', 'mounts', 'm', $query->expr()->eq('s.numeric_id', 'm.storage_id'))
252253
->where($query->expr()->eq('s.numeric_id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
253-
->groupBy('s.numeric_id', 's.id', 's.available', 's.last_checked');
254+
->groupBy('s.numeric_id', 's.id', 's.available', 's.last_checked', 'mount_id');
254255
$row = $query->executeQuery()->fetch();
255256
if ($row) {
256257
return [
@@ -259,6 +260,7 @@ public function getStorage(int $id): ?array {
259260
'files' => $row['files'],
260261
'available' => (bool)$row['available'],
261262
'last_checked' => $row['last_checked'] ? new \DateTime('@' . $row['last_checked']) : null,
263+
'mount_id' => $row['mount_id'],
262264
];
263265
} else {
264266
return null;
@@ -272,11 +274,12 @@ public function getStorage(int $id): ?array {
272274
*/
273275
public function listStorages(?int $limit): \Iterator {
274276
$query = $this->connection->getQueryBuilder();
275-
$query->select('numeric_id', 'id', 'available', 'last_checked')
277+
$query->select('numeric_id', 's.id', 'available', 'last_checked', 'mount_id')
276278
->selectAlias($query->func()->count('fileid'), 'files')
277279
->from('storages', 's')
278280
->innerJoin('s', 'filecache', 'f', $query->expr()->eq('f.storage', 's.numeric_id'))
279-
->groupBy('s.numeric_id', 's.id', 's.available', 's.last_checked')
281+
->leftJoin('s', 'mounts', 'm', $query->expr()->eq('s.numeric_id', 'm.storage_id'))
282+
->groupBy('s.numeric_id', 's.id', 's.available', 's.last_checked', 'mount_id')
280283
->orderBy('files', 'DESC');
281284
if ($limit !== null) {
282285
$query->setMaxResults($limit);
@@ -289,6 +292,7 @@ public function listStorages(?int $limit): \Iterator {
289292
'files' => $row['files'],
290293
'available' => (bool)$row['available'],
291294
'last_checked' => $row['last_checked'] ? new \DateTime('@' . $row['last_checked']) : null,
295+
'mount_id' => $row['mount_id'],
292296
];
293297
}
294298
}
@@ -304,6 +308,7 @@ public function formatStorage(array $storage): array {
304308
'files' => $storage['files'],
305309
'available' => $storage['available'] ? 'true' : 'false',
306310
'last_checked' => $storage['last_checked']?->format(\DATE_ATOM),
311+
'external_mount_id' => $storage['mount_id'],
307312
];
308313
}
309314

0 commit comments

Comments
 (0)