Proposal: add enumeration function to IUserManager which simply calls a callbask for each user in all backends

remotes/origin/share-copy-source-mounts
Thomas Müller 9 years ago
parent fe67db1ad0
commit 6abc02cb88
  1. 11
      apps/dav/command/syncsystemaddressbook.php
  2. 34
      lib/private/user/manager.php
  3. 7
      lib/public/iusermanager.php

@ -7,6 +7,7 @@ use OCA\DAV\CardDAV\Converter;
use OCA\DAV\Connector\Sabre\Principal;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IUser;
use OCP\IUserManager;
use Sabre\CardDAV\Plugin;
use Sabre\VObject\Component\VCard;
@ -69,11 +70,8 @@ class SyncSystemAddressBook extends Command {
$output->writeln('Syncing users ...');
$progress = new ProgressBar($output);
$progress->start();
$page = 0;
foreach( $this->userManager->getBackends() as $backend) {
$users = $backend->getUsers('', 50, $page++);
foreach($users as $user) {
$user = $this->userManager->get($user);
$this->userManager->callForAllUsers(function($user) use ($systemAddressBook, $converter, $progress) {
/** @var IUser $user */
$name = $user->getBackendClassName();
$userId = $user->getUID();
@ -89,8 +87,7 @@ class SyncSystemAddressBook extends Command {
}
}
$progress->advance();
}
}
});
$progress->finish();
$output->writeln('');
}

@ -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);
}
}
}

@ -134,4 +134,11 @@ interface IUserManager {
* @since 8.0.0
*/
public function countUsers();
/**
* @param \Closure $callback
* @return void
* @since 9.0.0
*/
public function callForAllUsers (\Closure $callback, $search = '');
}

Loading…
Cancel
Save