You are here

public function MongodbFileStorage::spaceUsed in MongoDB 8

Determines total disk space used by a single user or the whole filesystem.

Parameters

int $uid: Optional. A user id, specifying NULL returns the total space used by all non-temporary files.

int $status: (Optional) The file status to consider. The default is to only consider files in status FILE_STATUS_PERMANENT.

Return value

int An integer containing the number of bytes used.

Overrides FileStorageInterface::spaceUsed

File

mongodb_file/src/MongodbFileStorage.php, line 20
Contains \Drupal\mongodb_file\MongodbFileStorage.

Class

MongodbFileStorage

Namespace

Drupal\mongodb_file

Code

public function spaceUsed($uid = NULL, $status = FILE_STATUS_PERMANENT) {
  $pipeine = [];
  if (isset($uid)) {
    $pipeine[] = [
      '$match' => [
        'values.uid.value' => $uid,
      ],
    ];
  }
  $pipeine[] = [
    '$group' => [
      'total' => [
        '$sum' => '$values.0.filesize.value',
      ],
    ],
    '_id' => 'x',
  ];
  return $this->mongo
    ->get('entity.file')
    ->aggregate($pipeine)['total'];
}