From f8fa205543d84d3d6edbdb70c8e790eb1b7b2837 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 e253d7dd1..d7d8e96c6 100644 --- a/lib/SessionStatistics.php +++ b/lib/SessionStatistics.php @@ -50,15 +50,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') @@ -66,7 +74,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 bedd7ddfb..332785a61 100644 --- a/templates/settings-admin.php +++ b/templates/settings-admin.php @@ -280,6 +280,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 3c83d898f..b6c206c90 100644 --- a/tests/lib/SessionStatisticsTest.php +++ b/tests/lib/SessionStatisticsTest.php @@ -106,7 +106,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 @@ -115,5 +115,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 } }