[Pkg-owncloud-commits] [owncloud] 04/21: consolidate requirement check

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 78feb6514b7a449439c9024387f77b52b0399154
Author: Arthur Schiwon <blizzz at owncloud.com>
Date:   Wed Jun 11 14:51:40 2014 +0200

    consolidate requirement check
---
 apps/user_ldap/lib/wizard.php | 43 +++++++++++++++++++++----------------------
 1 file changed, 21 insertions(+), 22 deletions(-)

diff --git a/apps/user_ldap/lib/wizard.php b/apps/user_ldap/lib/wizard.php
index 364dfcf..27099e5 100644
--- a/apps/user_ldap/lib/wizard.php
+++ b/apps/user_ldap/lib/wizard.php
@@ -70,6 +70,14 @@ class Wizard extends LDAPUtility {
 	 * @return int|bool
 	 */
 	public function countEntries($filter, $type) {
+		$reqs = array('ldapHost', 'ldapPort', 'ldapBase');
+		if($type === 'users') {
+			$reqs[] = 'ldapUserFilter';
+		}
+		if(!$this->checkRequirements($reqs)) {
+			throw new \Exception('Requirements not met', 400);
+		}
+
 		$con = new Connection($this->ldap, '', null);
 		$con->setConfiguration($this->configuration->getConfiguration());
 		$ldapAccess = new Access($con, $this->ldap);
@@ -78,53 +86,44 @@ class Wizard extends LDAPUtility {
 		} else if($type === 'users') {
 			$result = $ldapAccess->countUsers($filter);
 		} else {
-			throw new \Excpetion('internal error: invald object type');
+			throw new \Exception('internal error: invald object type', 500);
 		}
 
 		return $result;
 	}
 
 	public function countGroups() {
-		if(!$this->checkRequirements(array('ldapHost',
-										   'ldapPort',
-										   'ldapBase',
-										   ))) {
-			return  false;
-		}
-
 		$base = $this->configuration->ldapBase[0];
 		$filter = $this->configuration->ldapGroupFilter;
-		$l = \OC_L10N::get('user_ldap');
 
 		if(empty($filter)) {
-			$output = $l->n('%s group found', '%s groups found', 0, array(0));
+			$output = self::$l->n('%s group found', '%s groups found', 0, array(0));
 			$this->result->addChange('ldap_group_count', $output);
 			return $this->result;
 		}
 
-		$groupsTotal = $this->countEntries($filter, 'groups');
+		try {
+			$groupsTotal = $this->countEntries($filter, 'groups');
+		} catch (\Exception $e) {
+			//400 can be ignored, 500 is forwarded
+			if($e->getCode() === 500) {
+				throw $e;
+			}
+			return false;
+		}
 		$groupsTotal = ($groupsTotal !== false) ? $groupsTotal : 0;
-		$output = $l->n('%s group found', '%s groups found', $groupsTotal, $groupsTotal);
+		$output = self::$l->n('%s group found', '%s groups found', $groupsTotal, $groupsTotal);
 		$this->result->addChange('ldap_group_count', $output);
 		return $this->result;
 	}
 
 	public function countUsers() {
-		if(!$this->checkRequirements(array('ldapHost',
-										   'ldapPort',
-										   'ldapBase',
-										   'ldapUserFilter',
-										   ))) {
-			return  false;
-		}
-
 		$base = $this->configuration->ldapBase[0];
 		$filter = $this->configuration->ldapUserFilter;
 
 		$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', $usersTotal, $usersTotal);
+		$output = self::$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