diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index fee66f99894..776a4bbe2fc 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -794,4 +794,30 @@ class Manager extends PublicEmitter implements IUserManager { public function getDisplayNameCache(): DisplayNameCache { return $this->displayNameCache; } + + /** + * Gets the list of users sorted by lastLogin, from most recent to least recent + * + * @param int $offset from which offset to fetch + * @return \Iterator list of user IDs + * @since 30.0.0 + */ + public function getSeenUsers(int $offset = 0): \Iterator { + $limit = 1000; + + do { + $userIds = $this->getSeenUserIds($limit, $offset); + $offset += $limit; + + foreach ($userIds as $userId) { + foreach ($this->backends as $backend) { + if ($backend->userExists($userId)) { + $user = $this->getUserObject($userId, $backend, false); + yield $user; + break; + } + } + } + } while (count($userIds) === $limit); + } } diff --git a/lib/public/IUserManager.php b/lib/public/IUserManager.php index d4638f396e7..cb71ba7d2ec 100644 --- a/lib/public/IUserManager.php +++ b/lib/public/IUserManager.php @@ -232,4 +232,15 @@ interface IUserManager { * @since 26.0.0 */ public function validateUserId(string $uid, bool $checkDataDirectory = false): void; + + /** + * Gets the list of users. + * An iterator is returned allowing the caller to stop the iteration at any time. + * The offset argument allows the caller to continue the iteration at a specific offset. + * + * @param int $offset from which offset to fetch + * @return \Iterator list of IUser object + * @since 29.0.15 + */ + public function getSeenUsers(int $offset = 0): \Iterator; }