From af9776e926720e67e43490e56110821174241d4e Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Wed, 28 Oct 2026 12:57:45 +0100 Subject: [PATCH] feat: Show all users who logged at least once Backport: the stable34 admin page is rendered from templates/settings-admin.php, so the new box is added there instead of the Vue component. Signed-off-by: Carl Schwan Assisted-by: ClaudeCode:claude-opus-5-5 --- lib/SessionStatistics.php | 12 ++++++++++-- templates/settings-admin.php | 8 ++++++++ tests/lib/SessionStatisticsTest.php | 3 ++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/SessionStatistics.php b/lib/SessionStatistics.php index fa246cbf..b5f305b7 100644 --- a/lib/SessionStatistics.php +++ b/lib/SessionStatistics.php @@ -49,15 +49,23 @@ public function getSessionStatistics(): array { 'last3months' => $this->getNumberOfActiveUsers(self::OFFSET_3MONTHS), 'last6months' => $this->getNumberOfActiveUsers(self::OFFSET_6MONTHS), 'lastyear' => $this->getNumberOfActiveUsers(self::OFFSET_1YEAR), + 'total' => $this->getNumberOfUsersLoggedInSince(1), ]; } /** - * get number of active user in a given time span + * Get number of active user in a given time span * * @param int $offset seconds */ private function getNumberOfActiveUsers(int $offset): int { + return $this->getNumberOfUsersLoggedInSince($this->timeFactory->getTime() - $offset); + } + + /** + * Get number of users whose last login is at or after the given timestamp + */ + private function getNumberOfUsersLoggedInSince(int $timestamp): int { $queryBuilder = $this->connection->getQueryBuilder(); $queryBuilder->select($queryBuilder->func()->count('userid')) ->from('preferences') @@ -65,7 +73,7 @@ private function getNumberOfActiveUsers(int $offset): int { ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('lastLogin'))) ->andwhere($queryBuilder->expr()->gte( $queryBuilder->expr()->castColumn('configvalue', IQueryBuilder::PARAM_INT), - $queryBuilder->createNamedParameter($this->timeFactory->getTime() - $offset, IQueryBuilder::PARAM_INT), + $queryBuilder->createNamedParameter($timestamp, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT, )); diff --git a/templates/settings-admin.php b/templates/settings-admin.php index a9bce872..02ef536e 100644 --- a/templates/settings-admin.php +++ b/templates/settings-admin.php @@ -285,6 +285,14 @@ function FormatMegabytes(int $byte): string { t('%s%% of all users', [round($_['activeUsers']['last1month'] * 100 / $_['storage']['num_users'], 1)])) ?> + + 0) : ?> +
+ t('Logged in at least once')); ?>
+
+ t('%s%% of all users', [round($_['activeUsers']['total'] * 100 / $_['storage']['num_users'], 1)])) ?> +
+ diff --git a/tests/lib/SessionStatisticsTest.php b/tests/lib/SessionStatisticsTest.php index 279b9c8d..fd97ce5c 100644 --- a/tests/lib/SessionStatisticsTest.php +++ b/tests/lib/SessionStatisticsTest.php @@ -104,7 +104,7 @@ public function testGetSessionStatistics() { $result = $this->instance->getSessionStatistics(); - $this->assertSame(8, count($result)); + $this->assertSame(9, count($result)); $this->assertSame(2, $result['last5minutes']); // 2 users in last 5 minutes $this->assertSame(5, $result['last1hour']); // 2 + 3 users in last hour $this->assertSame(6, $result['last24hours']); // 2 + 3 + 1 users in last day @@ -113,5 +113,6 @@ public function testGetSessionStatistics() { $this->assertSame(8, $result['last3months']); // 2 + 3 + 1 + 0 + 1 + 1 users in last 3 months $this->assertSame(9, $result['last6months']); // 2 + 3 + 1 + 0 + 1 + 1 + 1 users in last 6 months $this->assertSame(12, $result['lastyear']); // 2 + 3 + 1 + 0 + 1 + 1 + 1 + 3 users in last year + $this->assertGreaterThanOrEqual(12, $result['total']); // all 12 users, plus any existing lastLogin values in the database } }