summaryrefslogtreecommitdiffstats
path: root/lib/private/user
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-12-01 12:48:23 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-12-02 09:14:41 +0100
commit6abc02cb884d4384f6892082373eab50c805486d (patch)
tree11a13db66f3ba6e00ba110270b17e123341aafc3 /lib/private/user
parentfe67db1ad0efc6a703a752ef22ee7098519c69c4 (diff)
downloadnextcloud-server-6abc02cb884d4384f6892082373eab50c805486d.tar.gz
nextcloud-server-6abc02cb884d4384f6892082373eab50c805486d.zip
Proposal: add enumeration function to IUserManager which simply calls a callbask for each user in all backends
Diffstat (limited to 'lib/private/user')
-rw-r--r--lib/private/user/manager.php34
1 files changed, 30 insertions, 4 deletions
diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php
index 109f08f47a0..8d93b998d99 100644
--- a/lib/private/user/manager.php
+++ b/lib/private/user/manager.php
@@ -294,21 +294,47 @@ class Manager extends PublicEmitter implements IUserManager {
$userCountStatistics = array();
foreach ($this->backends as $backend) {
if ($backend->implementsActions(\OC_User_Backend::COUNT_USERS)) {
- $backendusers = $backend->countUsers();
- if($backendusers !== false) {
+ $backendUsers = $backend->countUsers();
+ if($backendUsers !== false) {
if($backend instanceof \OCP\IUserBackend) {
$name = $backend->getBackendName();
} else {
$name = get_class($backend);
}
if(isset($userCountStatistics[$name])) {
- $userCountStatistics[$name] += $backendusers;
+ $userCountStatistics[$name] += $backendUsers;
} else {
- $userCountStatistics[$name] = $backendusers;
+ $userCountStatistics[$name] = $backendUsers;
}
}
}
}
return $userCountStatistics;
}
+
+ /**
+ * The callback is executed for each user on each backend.
+ * If the callback returns false no further users will be retrieved.
+ *
+ * @param \Closure $callback
+ * @return void
+ * @since 9.0.0
+ */
+ public function callForAllUsers(\Closure $callback, $search = '') {
+ foreach($this->getBackends() as $backend) {
+ $limit = 50;
+ $offset = 0;
+ do {
+ $users = $backend->getUsers($search, $limit, $offset);
+ foreach ($users as $user) {
+ $user = $this->get($user);
+ $return = $callback($user);
+ if ($return === false) {
+ break;
+ }
+ }
+ $offset += $limit;
+ } while (count($users) >= $limit);
+ }
+ }
}