|
|
|
|
@ -23,14 +23,14 @@ use OCP\Files\IRootFolder; |
|
|
|
|
use OCP\Files\Mount\IMountPoint; |
|
|
|
|
use OCP\Files\Node; |
|
|
|
|
use OCP\Files\NotFoundException; |
|
|
|
|
use OCP\IDBConnection; |
|
|
|
|
use OCP\Files\NotPermittedException; |
|
|
|
|
use OCP\IDBConnection; |
|
|
|
|
use OCP\Share\IShare; |
|
|
|
|
use OCP\Util; |
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @psalm-type StorageInfo array{numeric_id: int, id: string, available: bool, last_checked: ?\DateTime, files: int} |
|
|
|
|
* @psalm-type StorageInfo array{numeric_id: int, id: string, available: bool, last_checked: ?\DateTime, files: int, mount_id: ?int} |
|
|
|
|
*/ |
|
|
|
|
class FileUtils { |
|
|
|
|
public function __construct( |
|
|
|
|
@ -246,12 +246,13 @@ class FileUtils { |
|
|
|
|
*/ |
|
|
|
|
public function getStorage(int $id): ?array { |
|
|
|
|
$query = $this->connection->getQueryBuilder(); |
|
|
|
|
$query->select('numeric_id', 'id', 'available', 'last_checked') |
|
|
|
|
$query->select('numeric_id', 's.id', 'available', 'last_checked', 'mount_id') |
|
|
|
|
->selectAlias($query->func()->count('fileid'), 'files') |
|
|
|
|
->from('storages', 's') |
|
|
|
|
->innerJoin('s', 'filecache', 'f', $query->expr()->eq('f.storage', 's.numeric_id')) |
|
|
|
|
->leftJoin('s', 'mounts', 'm', $query->expr()->eq('s.numeric_id', 'm.storage_id')) |
|
|
|
|
->where($query->expr()->eq('s.numeric_id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT))) |
|
|
|
|
->groupBy('s.numeric_id', 's.id', 's.available', 's.last_checked'); |
|
|
|
|
->groupBy('s.numeric_id', 's.id', 's.available', 's.last_checked', 'mount_id'); |
|
|
|
|
$row = $query->executeQuery()->fetch(); |
|
|
|
|
if ($row) { |
|
|
|
|
return [ |
|
|
|
|
@ -260,6 +261,7 @@ class FileUtils { |
|
|
|
|
'files' => $row['files'], |
|
|
|
|
'available' => (bool)$row['available'], |
|
|
|
|
'last_checked' => $row['last_checked'] ? new \DateTime('@' . $row['last_checked']) : null, |
|
|
|
|
'mount_id' => $row['mount_id'], |
|
|
|
|
]; |
|
|
|
|
} else { |
|
|
|
|
return null; |
|
|
|
|
@ -273,11 +275,12 @@ class FileUtils { |
|
|
|
|
*/ |
|
|
|
|
public function listStorages(?int $limit): \Iterator { |
|
|
|
|
$query = $this->connection->getQueryBuilder(); |
|
|
|
|
$query->select('numeric_id', 'id', 'available', 'last_checked') |
|
|
|
|
$query->select('numeric_id', 's.id', 'available', 'last_checked', 'mount_id') |
|
|
|
|
->selectAlias($query->func()->count('fileid'), 'files') |
|
|
|
|
->from('storages', 's') |
|
|
|
|
->innerJoin('s', 'filecache', 'f', $query->expr()->eq('f.storage', 's.numeric_id')) |
|
|
|
|
->groupBy('s.numeric_id', 's.id', 's.available', 's.last_checked') |
|
|
|
|
->leftJoin('s', 'mounts', 'm', $query->expr()->eq('s.numeric_id', 'm.storage_id')) |
|
|
|
|
->groupBy('s.numeric_id', 's.id', 's.available', 's.last_checked', 'mount_id') |
|
|
|
|
->orderBy('files', 'DESC'); |
|
|
|
|
if ($limit !== null) { |
|
|
|
|
$query->setMaxResults($limit); |
|
|
|
|
@ -290,6 +293,7 @@ class FileUtils { |
|
|
|
|
'files' => $row['files'], |
|
|
|
|
'available' => (bool)$row['available'], |
|
|
|
|
'last_checked' => $row['last_checked'] ? new \DateTime('@' . $row['last_checked']) : null, |
|
|
|
|
'mount_id' => $row['mount_id'], |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -305,6 +309,7 @@ class FileUtils { |
|
|
|
|
'files' => $storage['files'], |
|
|
|
|
'available' => $storage['available'] ? 'true' : 'false', |
|
|
|
|
'last_checked' => $storage['last_checked']?->format(\DATE_ATOM), |
|
|
|
|
'external_mount_id' => $storage['mount_id'], |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|