diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-12-01 12:48:23 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-12-02 09:14:41 +0100 |
commit | 6abc02cb884d4384f6892082373eab50c805486d (patch) | |
tree | 11a13db66f3ba6e00ba110270b17e123341aafc3 /apps/dav | |
parent | fe67db1ad0efc6a703a752ef22ee7098519c69c4 (diff) | |
download | nextcloud-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 'apps/dav')
-rw-r--r-- | apps/dav/command/syncsystemaddressbook.php | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/apps/dav/command/syncsystemaddressbook.php b/apps/dav/command/syncsystemaddressbook.php index 288616d065b..bb2896abc60 100644 --- a/apps/dav/command/syncsystemaddressbook.php +++ b/apps/dav/command/syncsystemaddressbook.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,28 +70,24 @@ 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); - $name = $user->getBackendClassName(); - $userId = $user->getUID(); - - $cardId = "$name:$userId.vcf"; - $card = $this->backend->getCard($systemAddressBook['id'], $cardId); - if ($card === false) { - $vCard = $converter->createCardFromUser($user); - $this->backend->createCard($systemAddressBook['id'], $cardId, $vCard->serialize()); - } else { - $vCard = Reader::read($card['carddata']); - if ($converter->updateCard($vCard, $user)) { - $this->backend->updateCard($systemAddressBook['id'], $cardId, $vCard->serialize()); - } + $this->userManager->callForAllUsers(function($user) use ($systemAddressBook, $converter, $progress) { + /** @var IUser $user */ + $name = $user->getBackendClassName(); + $userId = $user->getUID(); + + $cardId = "$name:$userId.vcf"; + $card = $this->backend->getCard($systemAddressBook['id'], $cardId); + if ($card === false) { + $vCard = $converter->createCardFromUser($user); + $this->backend->createCard($systemAddressBook['id'], $cardId, $vCard->serialize()); + } else { + $vCard = Reader::read($card['carddata']); + if ($converter->updateCard($vCard, $user)) { + $this->backend->updateCard($systemAddressBook['id'], $cardId, $vCard->serialize()); } - $progress->advance(); } - } + $progress->advance(); + }); $progress->finish(); $output->writeln(''); } |