diff --git a/lib/Command/SyncMissingUsersToCommon.php b/lib/Command/SyncMissingUsersToCommon.php
index 5df790f519c6e594087dcf2fc462e9d51795b19f..2ceba7209c19a959cfbf614d148777fb53bbeb09 100644
--- a/lib/Command/SyncMissingUsersToCommon.php
+++ b/lib/Command/SyncMissingUsersToCommon.php
@@ -118,23 +118,17 @@ class SyncMissingUsersToCommon extends Command {
* Process all users from NextCloud
*/
private function processAllUsers(string $ipAddress, bool $isDryRun, OutputInterface $output, array &$stats): void {
- $allUsers = [];
- $this->userManager->callForAllUsers(function (IUser $user) use (&$allUsers) {
- $allUsers[] = $user;
- });
- $totalUsers = count($allUsers);
- $output->writeln(sprintf('Processing all users from NextCloud (total: %d)', $totalUsers));
+ $userCount = 0;
+ $output->writeln('Processing all users from NextCloud');
- $lastProcessed = 0;
- foreach ($allUsers as $user) {
- $before = $stats['processed'];
+ $this->userManager->callForAllUsers(function (IUser $user) use (&$userCount, $ipAddress, $isDryRun, $output, &$stats) {
$this->processSingleUser($user->getUID(), $ipAddress, $isDryRun, $output, $stats);
- if ($stats['processed'] > 0 && $stats['processed'] % 100 === 0 && $stats['processed'] !== $lastProcessed) {
+ $userCount++;
+ if ($userCount > 0 && $userCount % 100 === 0) {
$output->writeln(sprintf('Progress: %d processed, %d success, %d errors',
- $stats['processed'], $stats['success'], $stats['errors']));
- $lastProcessed = $stats['processed'];
+ $userCount, $stats['success'], $stats['errors']));
}
- }
+ });
}
/**