2727use Symfony \Component \Console \Output \OutputInterface ;
2828
2929/**
30- * @psalm-type StorageInfo array{numeric_id: int, id: string, available: bool, last_checked: ?\DateTime, files: int}
30+ * @psalm-type StorageInfo array{numeric_id: int, id: string, available: bool, last_checked: ?\DateTime, files: int, mount_id: ?int }
3131 */
3232class FileUtils {
3333 public function __construct (
@@ -244,12 +244,13 @@ public function getNumericStorageId(string $id): ?int {
244244 */
245245 public function getStorage (int $ id ): ?array {
246246 $ query = $ this ->connection ->getQueryBuilder ();
247- $ query ->select ('numeric_id ' , 'id ' , 'available ' , 'last_checked ' )
247+ $ query ->select ('numeric_id ' , 's. id ' , 'available ' , 'last_checked ' , ' mount_id ' )
248248 ->selectAlias ($ query ->func ()->count ('fileid ' ), 'files ' )
249249 ->from ('storages ' , 's ' )
250250 ->innerJoin ('s ' , 'filecache ' , 'f ' , $ query ->expr ()->eq ('f.storage ' , 's.numeric_id ' ))
251+ ->leftJoin ('s ' , 'mounts ' , 'm ' , $ query ->expr ()->eq ('s.numeric_id ' , 'm.storage_id ' ))
251252 ->where ($ query ->expr ()->eq ('s.numeric_id ' , $ query ->createNamedParameter ($ id , IQueryBuilder::PARAM_INT )))
252- ->groupBy ('s.numeric_id ' , 's.id ' , 's.available ' , 's.last_checked ' );
253+ ->groupBy ('s.numeric_id ' , 's.id ' , 's.available ' , 's.last_checked ' , ' mount_id ' );
253254 $ row = $ query ->executeQuery ()->fetch ();
254255 if ($ row ) {
255256 return [
@@ -258,6 +259,7 @@ public function getStorage(int $id): ?array {
258259 'files ' => $ row ['files ' ],
259260 'available ' => (bool )$ row ['available ' ],
260261 'last_checked ' => $ row ['last_checked ' ] ? new \DateTime ('@ ' . $ row ['last_checked ' ]) : null ,
262+ 'mount_id ' => $ row ['mount_id ' ],
261263 ];
262264 } else {
263265 return null ;
@@ -271,11 +273,12 @@ public function getStorage(int $id): ?array {
271273 */
272274 public function listStorages (?int $ limit ): \Iterator {
273275 $ query = $ this ->connection ->getQueryBuilder ();
274- $ query ->select ('numeric_id ' , 'id ' , 'available ' , 'last_checked ' )
276+ $ query ->select ('numeric_id ' , 's. id ' , 'available ' , 'last_checked ' , ' mount_id ' )
275277 ->selectAlias ($ query ->func ()->count ('fileid ' ), 'files ' )
276278 ->from ('storages ' , 's ' )
277279 ->innerJoin ('s ' , 'filecache ' , 'f ' , $ query ->expr ()->eq ('f.storage ' , 's.numeric_id ' ))
278- ->groupBy ('s.numeric_id ' , 's.id ' , 's.available ' , 's.last_checked ' )
280+ ->leftJoin ('s ' , 'mounts ' , 'm ' , $ query ->expr ()->eq ('s.numeric_id ' , 'm.storage_id ' ))
281+ ->groupBy ('s.numeric_id ' , 's.id ' , 's.available ' , 's.last_checked ' , 'mount_id ' )
279282 ->orderBy ('files ' , 'DESC ' );
280283 if ($ limit !== null ) {
281284 $ query ->setMaxResults ($ limit );
@@ -288,6 +291,7 @@ public function listStorages(?int $limit): \Iterator {
288291 'files ' => $ row ['files ' ],
289292 'available ' => (bool )$ row ['available ' ],
290293 'last_checked ' => $ row ['last_checked ' ] ? new \DateTime ('@ ' . $ row ['last_checked ' ]) : null ,
294+ 'mount_id ' => $ row ['mount_id ' ],
291295 ];
292296 }
293297 }
@@ -303,6 +307,7 @@ public function formatStorage(array $storage): array {
303307 'files ' => $ storage ['files ' ],
304308 'available ' => $ storage ['available ' ] ? 'true ' : 'false ' ,
305309 'last_checked ' => $ storage ['last_checked ' ]?->format(\DATE_ATOM ),
310+ 'external_mount_id ' => $ storage ['mount_id ' ],
306311 ];
307312 }
308313
0 commit comments