Skip to content

Commit ed01f81

Browse files
committed
feat(users): add disabled users to storage stats
And get the total number of users directly from IUserManager Signed-off-by: Thomas Citharel <[email protected]>
1 parent 84890c5 commit ed01f81

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/StorageStatistics.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,22 @@
1313
use OCP\Files\IRootFolder;
1414
use OCP\IAppConfig;
1515
use OCP\IDBConnection;
16+
use OCP\IUserManager;
1617

1718
class StorageStatistics {
1819

1920
public function __construct(
2021
private IDBConnection $connection,
2122
private IRootFolder $rootFolder,
2223
private IAppConfig $appConfig,
24+
private IUserManager $userManager,
2325
) {
2426
}
2527

2628
public function getStorageStatistics(): array {
2729
return [
2830
'num_users' => $this->countUserEntries(),
31+
'num_disabled_users' => $this->countDisabledUserEntries(),
2932
'num_files' => $this->getCountOf('filecache'),
3033
'num_storages' => $this->getCountOf('storages'),
3134
'num_storages_local' => $this->countStorages('local'),
@@ -40,14 +43,11 @@ public function getStorageStatistics(): array {
4043
* count number of users
4144
*/
4245
protected function countUserEntries(): int {
43-
$query = $this->connection->getQueryBuilder();
44-
$query->selectAlias($query->createFunction('COUNT(*)'), 'num_entries')
45-
->from('preferences')
46-
->where($query->expr()->eq('configkey', $query->createNamedParameter('lastLogin')));
47-
$result = $query->executeQuery();
48-
$row = $result->fetch();
49-
$result->closeCursor();
50-
return (int)$row['num_entries'];
46+
return $this->userManager->countSeenUsers();
47+
}
48+
49+
protected function countDisabledUserEntries(): int {
50+
return $this->userManager->countDisabledUsers();
5151
}
5252

5353
protected function getCountOf(string $table): int {

0 commit comments

Comments
 (0)