[Pkg-owncloud-commits] [owncloud] 03/21: LDAP Wizard: count users and groups with the power of paged search
David Prévot
taffit at moszumanska.debian.org
Sat Jun 28 18:44:55 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch 6.0
in repository owncloud.
commit 1c634ab772713a39905cd773c81a6457fff09ba7
Author: Arthur Schiwon <blizzz at owncloud.com>
Date: Wed Jun 11 14:37:23 2014 +0200
LDAP Wizard: count users and groups with the power of paged search
---
apps/user_ldap/lib/wizard.php | 56 +++++++++++++++++++++++--------------------
1 file changed, 30 insertions(+), 26 deletions(-)
diff --git a/apps/user_ldap/lib/wizard.php b/apps/user_ldap/lib/wizard.php
index 8f827d7..364dfcf 100644
--- a/apps/user_ldap/lib/wizard.php
+++ b/apps/user_ldap/lib/wizard.php
@@ -63,6 +63,27 @@ class Wizard extends LDAPUtility {
}
}
+ /**
+ * counts entries in the LDAP directory
+ * @param string $filter the LDAP search filter
+ * @param string $type a string being either 'users' or 'groups';
+ * @return int|bool
+ */
+ public function countEntries($filter, $type) {
+ $con = new Connection($this->ldap, '', null);
+ $con->setConfiguration($this->configuration->getConfiguration());
+ $ldapAccess = new Access($con, $this->ldap);
+ if($type === 'groups') {
+ $result = $ldapAccess->countGroups($filter);
+ } else if($type === 'users') {
+ $result = $ldapAccess->countUsers($filter);
+ } else {
+ throw new \Excpetion('internal error: invald object type');
+ }
+
+ return $result;
+ }
+
public function countGroups() {
if(!$this->checkRequirements(array('ldapHost',
'ldapPort',
@@ -73,26 +94,18 @@ class Wizard extends LDAPUtility {
$base = $this->configuration->ldapBase[0];
$filter = $this->configuration->ldapGroupFilter;
- \OCP\Util::writeLog('user_ldap', 'Wiz: g filter '. print_r($filter, true), \OCP\Util::DEBUG);
$l = \OC_L10N::get('user_ldap');
+
if(empty($filter)) {
$output = $l->n('%s group found', '%s groups found', 0, array(0));
$this->result->addChange('ldap_group_count', $output);
return $this->result;
}
- $cr = $this->getConnection();
- if(!$cr) {
- throw new \Exception('Could not connect to LDAP');
- }
- $rr = $this->ldap->search($cr, $base, $filter, array('dn'));
- if(!$this->ldap->isResource($rr)) {
- return false;
- }
- $entries = $this->ldap->countEntries($cr, $rr);
- $entries = ($entries !== false) ? $entries : 0;
- $output = $l->n('%s group found', '%s groups found', $entries, $entries);
- $this->result->addChange('ldap_group_count', $output);
+ $groupsTotal = $this->countEntries($filter, 'groups');
+ $groupsTotal = ($groupsTotal !== false) ? $groupsTotal : 0;
+ $output = $l->n('%s group found', '%s groups found', $groupsTotal, $groupsTotal);
+ $this->result->addChange('ldap_group_count', $output);
return $this->result;
}
@@ -105,23 +118,14 @@ class Wizard extends LDAPUtility {
return false;
}
- $cr = $this->getConnection();
- if(!$cr) {
- throw new \Exception('Could not connect to LDAP');
- }
-
$base = $this->configuration->ldapBase[0];
$filter = $this->configuration->ldapUserFilter;
- $rr = $this->ldap->search($cr, $base, $filter, array('dn'));
- if(!$this->ldap->isResource($rr)) {
- return false;
- }
- $entries = $this->ldap->countEntries($cr, $rr);
- $entries = ($entries !== false) ? $entries : 0;
+
+ $usersTotal = $this->countEntries($filter, 'users');
+ $usersTotal = ($usersTotal !== false) ? $usersTotal : 0;
$l = \OC_L10N::get('user_ldap');
- $output = $l->n('%s user found', '%s users found', $entries, $entries);
+ $output = $l->n('%s user found', '%s users found', $usersTotal, $usersTotal);
$this->result->addChange('ldap_user_count', $output);
-
return $this->result;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list