Completed
Pull Request — master (#3233)
by Christoph
57:05 queued 37:22
created
apps/user_ldap/lib/User/IUserTools.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -30,13 +30,13 @@
 block discarded – undo
30 30
  * defines methods that are required by User class for LDAP interaction
31 31
  */
32 32
 interface IUserTools {
33
-	public function getConnection();
33
+    public function getConnection();
34 34
 
35
-	public function readAttribute($dn, $attr, $filter = 'objectClass=*');
35
+    public function readAttribute($dn, $attr, $filter = 'objectClass=*');
36 36
 
37
-	public function stringResemblesDN($string);
37
+    public function stringResemblesDN($string);
38 38
 
39
-	public function dn2username($dn, $ldapname = null);
39
+    public function dn2username($dn, $ldapname = null);
40 40
 
41
-	public function username2dn($name);
41
+    public function username2dn($name);
42 42
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/User/Manager.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 * @return null
131 131
 	 */
132 132
 	private function checkAccess() {
133
-		if(is_null($this->access)) {
133
+		if (is_null($this->access)) {
134 134
 			throw new \Exception('LDAP Access instance must be set first');
135 135
 		}
136 136
 	}
@@ -150,18 +150,18 @@  discard block
 block discarded – undo
150 150
 			$this->access->getConnection()->ldapUserDisplayName,
151 151
 			$this->access->getConnection()->ldapUserDisplayName2,
152 152
 		);
153
-		foreach($possible as $attr) {
154
-			if(!is_null($attr)) {
153
+		foreach ($possible as $attr) {
154
+			if (!is_null($attr)) {
155 155
 				$attributes[] = $attr;
156 156
 			}
157 157
 		}
158 158
 
159 159
 		$homeRule = $this->access->getConnection()->homeFolderNamingRule;
160
-		if(strpos($homeRule, 'attr:') === 0) {
160
+		if (strpos($homeRule, 'attr:') === 0) {
161 161
 			$attributes[] = substr($homeRule, strlen('attr:'));
162 162
 		}
163 163
 
164
-		if(!$minimal) {
164
+		if (!$minimal) {
165 165
 			// attributes that are not really important but may come with big
166 166
 			// payload.
167 167
 			$attributes = array_merge($attributes, array(
@@ -204,11 +204,11 @@  discard block
 block discarded – undo
204 204
 	 */
205 205
 	protected function createInstancyByUserName($id) {
206 206
 		//most likely a uid. Check whether it is a deleted user
207
-		if($this->isDeletedUser($id)) {
207
+		if ($this->isDeletedUser($id)) {
208 208
 			return $this->getDeletedUser($id);
209 209
 		}
210 210
 		$dn = $this->access->username2dn($id);
211
-		if($dn !== false) {
211
+		if ($dn !== false) {
212 212
 			return $this->createAndCache($dn, $id);
213 213
 		}
214 214
 		return null;
@@ -222,15 +222,15 @@  discard block
 block discarded – undo
222 222
 	 */
223 223
 	public function get($id) {
224 224
 		$this->checkAccess();
225
-		if(isset($this->usersByDN[$id])) {
225
+		if (isset($this->usersByDN[$id])) {
226 226
 			return $this->usersByDN[$id];
227
-		} else if(isset($this->usersByUid[$id])) {
227
+		} else if (isset($this->usersByUid[$id])) {
228 228
 			return $this->usersByUid[$id];
229 229
 		}
230 230
 
231
-		if($this->access->stringResemblesDN($id) ) {
231
+		if ($this->access->stringResemblesDN($id)) {
232 232
 			$uid = $this->access->dn2username($id);
233
-			if($uid !== false) {
233
+			if ($uid !== false) {
234 234
 				return $this->createAndCache($id, $uid);
235 235
 			}
236 236
 		}
Please login to merge, or discard this patch.
Indentation   +195 added lines, -195 removed lines patch added patch discarded remove patch
@@ -42,200 +42,200 @@
 block discarded – undo
42 42
  * cache
43 43
  */
44 44
 class Manager {
45
-	/** @var IUserTools */
46
-	protected $access;
47
-
48
-	/** @var IConfig */
49
-	protected $ocConfig;
50
-
51
-	/** @var IDBConnection */
52
-	protected $db;
53
-
54
-	/** @var FilesystemHelper */
55
-	protected $ocFilesystem;
56
-
57
-	/** @var LogWrapper */
58
-	protected $ocLog;
59
-
60
-	/** @var Image */
61
-	protected $image;
62
-
63
-	/** @param \OCP\IAvatarManager */
64
-	protected $avatarManager;
65
-
66
-	/**
67
-	 * @var CappedMemoryCache $usersByDN
68
-	 */
69
-	protected $usersByDN;
70
-	/**
71
-	 * @var CappedMemoryCache $usersByUid
72
-	 */
73
-	protected $usersByUid;
74
-
75
-	/**
76
-	 * @param IConfig $ocConfig
77
-	 * @param \OCA\User_LDAP\FilesystemHelper $ocFilesystem object that
78
-	 * gives access to necessary functions from the OC filesystem
79
-	 * @param  \OCA\User_LDAP\LogWrapper $ocLog
80
-	 * @param IAvatarManager $avatarManager
81
-	 * @param Image $image an empty image instance
82
-	 * @param IDBConnection $db
83
-	 * @throws \Exception when the methods mentioned above do not exist
84
-	 */
85
-	public function __construct(IConfig $ocConfig,
86
-								FilesystemHelper $ocFilesystem, LogWrapper $ocLog,
87
-								IAvatarManager $avatarManager, Image $image,
88
-								IDBConnection $db, IUserManager $userManager) {
89
-
90
-		$this->ocConfig      = $ocConfig;
91
-		$this->ocFilesystem  = $ocFilesystem;
92
-		$this->ocLog         = $ocLog;
93
-		$this->avatarManager = $avatarManager;
94
-		$this->image         = $image;
95
-		$this->db            = $db;
96
-		$this->userManager   = $userManager;
97
-		$this->usersByDN     = new CappedMemoryCache();
98
-		$this->usersByUid    = new CappedMemoryCache();
99
-	}
100
-
101
-	/**
102
-	 * @brief binds manager to an instance of IUserTools (implemented by
103
-	 * Access). It needs to be assigned first before the manager can be used.
104
-	 * @param IUserTools
105
-	 */
106
-	public function setLdapAccess(IUserTools $access) {
107
-		$this->access = $access;
108
-	}
109
-
110
-	/**
111
-	 * @brief creates an instance of User and caches (just runtime) it in the
112
-	 * property array
113
-	 * @param string $dn the DN of the user
114
-	 * @param string $uid the internal (owncloud) username
115
-	 * @return \OCA\User_LDAP\User\User
116
-	 */
117
-	private function createAndCache($dn, $uid) {
118
-		$this->checkAccess();
119
-		$user = new User($uid, $dn, $this->access, $this->ocConfig,
120
-			$this->ocFilesystem, clone $this->image, $this->ocLog,
121
-			$this->avatarManager, $this->userManager);
122
-		$this->usersByDN[$dn]   = $user;
123
-		$this->usersByUid[$uid] = $user;
124
-		return $user;
125
-	}
126
-
127
-	/**
128
-	 * @brief checks whether the Access instance has been set
129
-	 * @throws \Exception if Access has not been set
130
-	 * @return null
131
-	 */
132
-	private function checkAccess() {
133
-		if(is_null($this->access)) {
134
-			throw new \Exception('LDAP Access instance must be set first');
135
-		}
136
-	}
137
-
138
-	/**
139
-	 * returns a list of attributes that will be processed further, e.g. quota,
140
-	 * email, displayname, or others.
141
-	 * @param bool $minimal - optional, set to true to skip attributes with big
142
-	 * payload
143
-	 * @return string[]
144
-	 */
145
-	public function getAttributes($minimal = false) {
146
-		$attributes = array('dn', 'uid', 'samaccountname', 'memberof');
147
-		$possible = array(
148
-			$this->access->getConnection()->ldapQuotaAttribute,
149
-			$this->access->getConnection()->ldapEmailAttribute,
150
-			$this->access->getConnection()->ldapUserDisplayName,
151
-			$this->access->getConnection()->ldapUserDisplayName2,
152
-		);
153
-		foreach($possible as $attr) {
154
-			if(!is_null($attr)) {
155
-				$attributes[] = $attr;
156
-			}
157
-		}
158
-
159
-		$homeRule = $this->access->getConnection()->homeFolderNamingRule;
160
-		if(strpos($homeRule, 'attr:') === 0) {
161
-			$attributes[] = substr($homeRule, strlen('attr:'));
162
-		}
163
-
164
-		if(!$minimal) {
165
-			// attributes that are not really important but may come with big
166
-			// payload.
167
-			$attributes = array_merge($attributes, array(
168
-				'jpegphoto',
169
-				'thumbnailphoto'
170
-			));
171
-		}
172
-
173
-		return $attributes;
174
-	}
175
-
176
-	/**
177
-	 * Checks whether the specified user is marked as deleted
178
-	 * @param string $id the Nextcloud user name
179
-	 * @return bool
180
-	 */
181
-	public function isDeletedUser($id) {
182
-		$isDeleted = $this->ocConfig->getUserValue(
183
-			$id, 'user_ldap', 'isDeleted', 0);
184
-		return intval($isDeleted) === 1;
185
-	}
186
-
187
-	/**
188
-	 * creates and returns an instance of OfflineUser for the specified user
189
-	 * @param string $id
190
-	 * @return \OCA\User_LDAP\User\OfflineUser
191
-	 */
192
-	public function getDeletedUser($id) {
193
-		return new OfflineUser(
194
-			$id,
195
-			$this->ocConfig,
196
-			$this->db,
197
-			$this->access->getUserMapper());
198
-	}
199
-
200
-	/**
201
-	 * @brief returns a User object by it's Nextcloud username
202
-	 * @param string $id the DN or username of the user
203
-	 * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\User\OfflineUser|null
204
-	 */
205
-	protected function createInstancyByUserName($id) {
206
-		//most likely a uid. Check whether it is a deleted user
207
-		if($this->isDeletedUser($id)) {
208
-			return $this->getDeletedUser($id);
209
-		}
210
-		$dn = $this->access->username2dn($id);
211
-		if($dn !== false) {
212
-			return $this->createAndCache($dn, $id);
213
-		}
214
-		return null;
215
-	}
216
-
217
-	/**
218
-	 * @brief returns a User object by it's DN or Nextcloud username
219
-	 * @param string $id the DN or username of the user
220
-	 * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\User\OfflineUser|null
221
-	 * @throws \Exception when connection could not be established
222
-	 */
223
-	public function get($id) {
224
-		$this->checkAccess();
225
-		if(isset($this->usersByDN[$id])) {
226
-			return $this->usersByDN[$id];
227
-		} else if(isset($this->usersByUid[$id])) {
228
-			return $this->usersByUid[$id];
229
-		}
230
-
231
-		if($this->access->stringResemblesDN($id) ) {
232
-			$uid = $this->access->dn2username($id);
233
-			if($uid !== false) {
234
-				return $this->createAndCache($id, $uid);
235
-			}
236
-		}
237
-
238
-		return $this->createInstancyByUserName($id);
239
-	}
45
+    /** @var IUserTools */
46
+    protected $access;
47
+
48
+    /** @var IConfig */
49
+    protected $ocConfig;
50
+
51
+    /** @var IDBConnection */
52
+    protected $db;
53
+
54
+    /** @var FilesystemHelper */
55
+    protected $ocFilesystem;
56
+
57
+    /** @var LogWrapper */
58
+    protected $ocLog;
59
+
60
+    /** @var Image */
61
+    protected $image;
62
+
63
+    /** @param \OCP\IAvatarManager */
64
+    protected $avatarManager;
65
+
66
+    /**
67
+     * @var CappedMemoryCache $usersByDN
68
+     */
69
+    protected $usersByDN;
70
+    /**
71
+     * @var CappedMemoryCache $usersByUid
72
+     */
73
+    protected $usersByUid;
74
+
75
+    /**
76
+     * @param IConfig $ocConfig
77
+     * @param \OCA\User_LDAP\FilesystemHelper $ocFilesystem object that
78
+     * gives access to necessary functions from the OC filesystem
79
+     * @param  \OCA\User_LDAP\LogWrapper $ocLog
80
+     * @param IAvatarManager $avatarManager
81
+     * @param Image $image an empty image instance
82
+     * @param IDBConnection $db
83
+     * @throws \Exception when the methods mentioned above do not exist
84
+     */
85
+    public function __construct(IConfig $ocConfig,
86
+                                FilesystemHelper $ocFilesystem, LogWrapper $ocLog,
87
+                                IAvatarManager $avatarManager, Image $image,
88
+                                IDBConnection $db, IUserManager $userManager) {
89
+
90
+        $this->ocConfig      = $ocConfig;
91
+        $this->ocFilesystem  = $ocFilesystem;
92
+        $this->ocLog         = $ocLog;
93
+        $this->avatarManager = $avatarManager;
94
+        $this->image         = $image;
95
+        $this->db            = $db;
96
+        $this->userManager   = $userManager;
97
+        $this->usersByDN     = new CappedMemoryCache();
98
+        $this->usersByUid    = new CappedMemoryCache();
99
+    }
100
+
101
+    /**
102
+     * @brief binds manager to an instance of IUserTools (implemented by
103
+     * Access). It needs to be assigned first before the manager can be used.
104
+     * @param IUserTools
105
+     */
106
+    public function setLdapAccess(IUserTools $access) {
107
+        $this->access = $access;
108
+    }
109
+
110
+    /**
111
+     * @brief creates an instance of User and caches (just runtime) it in the
112
+     * property array
113
+     * @param string $dn the DN of the user
114
+     * @param string $uid the internal (owncloud) username
115
+     * @return \OCA\User_LDAP\User\User
116
+     */
117
+    private function createAndCache($dn, $uid) {
118
+        $this->checkAccess();
119
+        $user = new User($uid, $dn, $this->access, $this->ocConfig,
120
+            $this->ocFilesystem, clone $this->image, $this->ocLog,
121
+            $this->avatarManager, $this->userManager);
122
+        $this->usersByDN[$dn]   = $user;
123
+        $this->usersByUid[$uid] = $user;
124
+        return $user;
125
+    }
126
+
127
+    /**
128
+     * @brief checks whether the Access instance has been set
129
+     * @throws \Exception if Access has not been set
130
+     * @return null
131
+     */
132
+    private function checkAccess() {
133
+        if(is_null($this->access)) {
134
+            throw new \Exception('LDAP Access instance must be set first');
135
+        }
136
+    }
137
+
138
+    /**
139
+     * returns a list of attributes that will be processed further, e.g. quota,
140
+     * email, displayname, or others.
141
+     * @param bool $minimal - optional, set to true to skip attributes with big
142
+     * payload
143
+     * @return string[]
144
+     */
145
+    public function getAttributes($minimal = false) {
146
+        $attributes = array('dn', 'uid', 'samaccountname', 'memberof');
147
+        $possible = array(
148
+            $this->access->getConnection()->ldapQuotaAttribute,
149
+            $this->access->getConnection()->ldapEmailAttribute,
150
+            $this->access->getConnection()->ldapUserDisplayName,
151
+            $this->access->getConnection()->ldapUserDisplayName2,
152
+        );
153
+        foreach($possible as $attr) {
154
+            if(!is_null($attr)) {
155
+                $attributes[] = $attr;
156
+            }
157
+        }
158
+
159
+        $homeRule = $this->access->getConnection()->homeFolderNamingRule;
160
+        if(strpos($homeRule, 'attr:') === 0) {
161
+            $attributes[] = substr($homeRule, strlen('attr:'));
162
+        }
163
+
164
+        if(!$minimal) {
165
+            // attributes that are not really important but may come with big
166
+            // payload.
167
+            $attributes = array_merge($attributes, array(
168
+                'jpegphoto',
169
+                'thumbnailphoto'
170
+            ));
171
+        }
172
+
173
+        return $attributes;
174
+    }
175
+
176
+    /**
177
+     * Checks whether the specified user is marked as deleted
178
+     * @param string $id the Nextcloud user name
179
+     * @return bool
180
+     */
181
+    public function isDeletedUser($id) {
182
+        $isDeleted = $this->ocConfig->getUserValue(
183
+            $id, 'user_ldap', 'isDeleted', 0);
184
+        return intval($isDeleted) === 1;
185
+    }
186
+
187
+    /**
188
+     * creates and returns an instance of OfflineUser for the specified user
189
+     * @param string $id
190
+     * @return \OCA\User_LDAP\User\OfflineUser
191
+     */
192
+    public function getDeletedUser($id) {
193
+        return new OfflineUser(
194
+            $id,
195
+            $this->ocConfig,
196
+            $this->db,
197
+            $this->access->getUserMapper());
198
+    }
199
+
200
+    /**
201
+     * @brief returns a User object by it's Nextcloud username
202
+     * @param string $id the DN or username of the user
203
+     * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\User\OfflineUser|null
204
+     */
205
+    protected function createInstancyByUserName($id) {
206
+        //most likely a uid. Check whether it is a deleted user
207
+        if($this->isDeletedUser($id)) {
208
+            return $this->getDeletedUser($id);
209
+        }
210
+        $dn = $this->access->username2dn($id);
211
+        if($dn !== false) {
212
+            return $this->createAndCache($dn, $id);
213
+        }
214
+        return null;
215
+    }
216
+
217
+    /**
218
+     * @brief returns a User object by it's DN or Nextcloud username
219
+     * @param string $id the DN or username of the user
220
+     * @return \OCA\User_LDAP\User\User|\OCA\User_LDAP\User\OfflineUser|null
221
+     * @throws \Exception when connection could not be established
222
+     */
223
+    public function get($id) {
224
+        $this->checkAccess();
225
+        if(isset($this->usersByDN[$id])) {
226
+            return $this->usersByDN[$id];
227
+        } else if(isset($this->usersByUid[$id])) {
228
+            return $this->usersByUid[$id];
229
+        }
230
+
231
+        if($this->access->stringResemblesDN($id) ) {
232
+            $uid = $this->access->dn2username($id);
233
+            if($uid !== false) {
234
+                return $this->createAndCache($id, $uid);
235
+            }
236
+        }
237
+
238
+        return $this->createInstancyByUserName($id);
239
+    }
240 240
 
241 241
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/User/OfflineUser.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -179,14 +179,14 @@  discard block
 block discarded – undo
179 179
 	 * reads the user details
180 180
 	 */
181 181
 	protected function fetchDetails() {
182
-		$properties = array (
182
+		$properties = array(
183 183
 			'displayName' => 'user_ldap',
184 184
 			'uid'         => 'user_ldap',
185 185
 			'homePath'    => 'user_ldap',
186 186
 			'email'       => 'settings',
187 187
 			'lastLogin'   => 'login'
188 188
 		);
189
-		foreach($properties as $property => $app) {
189
+		foreach ($properties as $property => $app) {
190 190
 			$this->$property = $this->config->getUserValue($this->ocName, $app, $property, '');
191 191
 		}
192 192
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 		', 1);
210 210
 		$query->execute(array($this->ocName));
211 211
 		$sResult = $query->fetchColumn(0);
212
-		if(intval($sResult) === 1) {
212
+		if (intval($sResult) === 1) {
213 213
 			$this->hasActiveShares = true;
214 214
 			return;
215 215
 		}
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 		', 1);
222 222
 		$query->execute(array($this->ocName));
223 223
 		$sResult = $query->fetchColumn(0);
224
-		if(intval($sResult) === 1) {
224
+		if (intval($sResult) === 1) {
225 225
 			$this->hasActiveShares = true;
226 226
 			return;
227 227
 		}
Please login to merge, or discard this patch.
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -27,205 +27,205 @@
 block discarded – undo
27 27
 use OCA\User_LDAP\Mapping\UserMapping;
28 28
 
29 29
 class OfflineUser {
30
-	/**
31
-	 * @var string $ocName
32
-	 */
33
-	protected $ocName;
34
-	/**
35
-	 * @var string $dn
36
-	 */
37
-	protected $dn;
38
-	/**
39
-	 * @var string $uid the UID as provided by LDAP
40
-	 */
41
-	protected $uid;
42
-	/**
43
-	 * @var string $displayName
44
-	 */
45
-	protected $displayName;
46
-	/**
47
-	 * @var string $homePath
48
-	 */
49
-	protected $homePath;
50
-	/**
51
-	 * @var string $lastLogin the timestamp of the last login
52
-	 */
53
-	protected $lastLogin;
54
-	/**
55
-	 * @var string $email
56
-	 */
57
-	protected $email;
58
-	/**
59
-	 * @var bool $hasActiveShares
60
-	 */
61
-	protected $hasActiveShares;
62
-	/**
63
-	 * @var \OCP\IConfig $config
64
-	 */
65
-	protected $config;
66
-	/**
67
-	 * @var \OCP\IDBConnection $db
68
-	 */
69
-	protected $db;
70
-	/**
71
-	 * @var \OCA\User_LDAP\Mapping\UserMapping
72
-	 */
73
-	protected $mapping;
74
-
75
-	/**
76
-	 * @param string $ocName
77
-	 * @param \OCP\IConfig $config
78
-	 * @param \OCP\IDBConnection $db
79
-	 * @param \OCA\User_LDAP\Mapping\UserMapping $mapping
80
-	 */
81
-	public function __construct($ocName, \OCP\IConfig $config, \OCP\IDBConnection $db, UserMapping $mapping) {
82
-		$this->ocName = $ocName;
83
-		$this->config = $config;
84
-		$this->db = $db;
85
-		$this->mapping = $mapping;
86
-		$this->fetchDetails();
87
-	}
88
-
89
-	/**
90
-	 * remove the Delete-flag from the user.
91
-	 */
92
-	public function unmark() {
93
-		$this->config->setUserValue($this->ocName, 'user_ldap', 'isDeleted', '0');
94
-	}
95
-
96
-	/**
97
-	 * exports the user details in an assoc array
98
-	 * @return array
99
-	 */
100
-	public function export() {
101
-		$data = array();
102
-		$data['ocName'] = $this->getOCName();
103
-		$data['dn'] = $this->getDN();
104
-		$data['uid'] = $this->getUID();
105
-		$data['displayName'] = $this->getDisplayName();
106
-		$data['homePath'] = $this->getHomePath();
107
-		$data['lastLogin'] = $this->getLastLogin();
108
-		$data['email'] = $this->getEmail();
109
-		$data['hasActiveShares'] = $this->getHasActiveShares();
110
-
111
-		return $data;
112
-	}
113
-
114
-	/**
115
-	 * getter for Nextcloud internal name
116
-	 * @return string
117
-	 */
118
-	public function getOCName() {
119
-		return $this->ocName;
120
-	}
121
-
122
-	/**
123
-	 * getter for LDAP uid
124
-	 * @return string
125
-	 */
126
-	public function getUID() {
127
-		return $this->uid;
128
-	}
129
-
130
-	/**
131
-	 * getter for LDAP DN
132
-	 * @return string
133
-	 */
134
-	public function getDN() {
135
-		return $this->dn;
136
-	}
137
-
138
-	/**
139
-	 * getter for display name
140
-	 * @return string
141
-	 */
142
-	public function getDisplayName() {
143
-		return $this->displayName;
144
-	}
145
-
146
-	/**
147
-	 * getter for email
148
-	 * @return string
149
-	 */
150
-	public function getEmail() {
151
-		return $this->email;
152
-	}
153
-
154
-	/**
155
-	 * getter for home directory path
156
-	 * @return string
157
-	 */
158
-	public function getHomePath() {
159
-		return $this->homePath;
160
-	}
161
-
162
-	/**
163
-	 * getter for the last login timestamp
164
-	 * @return int
165
-	 */
166
-	public function getLastLogin() {
167
-		return intval($this->lastLogin);
168
-	}
169
-
170
-	/**
171
-	 * getter for having active shares
172
-	 * @return bool
173
-	 */
174
-	public function getHasActiveShares() {
175
-		return $this->hasActiveShares;
176
-	}
177
-
178
-	/**
179
-	 * reads the user details
180
-	 */
181
-	protected function fetchDetails() {
182
-		$properties = array (
183
-			'displayName' => 'user_ldap',
184
-			'uid'         => 'user_ldap',
185
-			'homePath'    => 'user_ldap',
186
-			'email'       => 'settings',
187
-			'lastLogin'   => 'login'
188
-		);
189
-		foreach($properties as $property => $app) {
190
-			$this->$property = $this->config->getUserValue($this->ocName, $app, $property, '');
191
-		}
192
-
193
-		$dn = $this->mapping->getDNByName($this->ocName);
194
-		$this->dn = ($dn !== false) ? $dn : '';
195
-
196
-		$this->determineShares();
197
-	}
198
-
199
-
200
-	/**
201
-	 * finds out whether the user has active shares. The result is stored in
202
-	 * $this->hasActiveShares
203
-	 */
204
-	protected function determineShares() {
205
-		$query = $this->db->prepare('
30
+    /**
31
+     * @var string $ocName
32
+     */
33
+    protected $ocName;
34
+    /**
35
+     * @var string $dn
36
+     */
37
+    protected $dn;
38
+    /**
39
+     * @var string $uid the UID as provided by LDAP
40
+     */
41
+    protected $uid;
42
+    /**
43
+     * @var string $displayName
44
+     */
45
+    protected $displayName;
46
+    /**
47
+     * @var string $homePath
48
+     */
49
+    protected $homePath;
50
+    /**
51
+     * @var string $lastLogin the timestamp of the last login
52
+     */
53
+    protected $lastLogin;
54
+    /**
55
+     * @var string $email
56
+     */
57
+    protected $email;
58
+    /**
59
+     * @var bool $hasActiveShares
60
+     */
61
+    protected $hasActiveShares;
62
+    /**
63
+     * @var \OCP\IConfig $config
64
+     */
65
+    protected $config;
66
+    /**
67
+     * @var \OCP\IDBConnection $db
68
+     */
69
+    protected $db;
70
+    /**
71
+     * @var \OCA\User_LDAP\Mapping\UserMapping
72
+     */
73
+    protected $mapping;
74
+
75
+    /**
76
+     * @param string $ocName
77
+     * @param \OCP\IConfig $config
78
+     * @param \OCP\IDBConnection $db
79
+     * @param \OCA\User_LDAP\Mapping\UserMapping $mapping
80
+     */
81
+    public function __construct($ocName, \OCP\IConfig $config, \OCP\IDBConnection $db, UserMapping $mapping) {
82
+        $this->ocName = $ocName;
83
+        $this->config = $config;
84
+        $this->db = $db;
85
+        $this->mapping = $mapping;
86
+        $this->fetchDetails();
87
+    }
88
+
89
+    /**
90
+     * remove the Delete-flag from the user.
91
+     */
92
+    public function unmark() {
93
+        $this->config->setUserValue($this->ocName, 'user_ldap', 'isDeleted', '0');
94
+    }
95
+
96
+    /**
97
+     * exports the user details in an assoc array
98
+     * @return array
99
+     */
100
+    public function export() {
101
+        $data = array();
102
+        $data['ocName'] = $this->getOCName();
103
+        $data['dn'] = $this->getDN();
104
+        $data['uid'] = $this->getUID();
105
+        $data['displayName'] = $this->getDisplayName();
106
+        $data['homePath'] = $this->getHomePath();
107
+        $data['lastLogin'] = $this->getLastLogin();
108
+        $data['email'] = $this->getEmail();
109
+        $data['hasActiveShares'] = $this->getHasActiveShares();
110
+
111
+        return $data;
112
+    }
113
+
114
+    /**
115
+     * getter for Nextcloud internal name
116
+     * @return string
117
+     */
118
+    public function getOCName() {
119
+        return $this->ocName;
120
+    }
121
+
122
+    /**
123
+     * getter for LDAP uid
124
+     * @return string
125
+     */
126
+    public function getUID() {
127
+        return $this->uid;
128
+    }
129
+
130
+    /**
131
+     * getter for LDAP DN
132
+     * @return string
133
+     */
134
+    public function getDN() {
135
+        return $this->dn;
136
+    }
137
+
138
+    /**
139
+     * getter for display name
140
+     * @return string
141
+     */
142
+    public function getDisplayName() {
143
+        return $this->displayName;
144
+    }
145
+
146
+    /**
147
+     * getter for email
148
+     * @return string
149
+     */
150
+    public function getEmail() {
151
+        return $this->email;
152
+    }
153
+
154
+    /**
155
+     * getter for home directory path
156
+     * @return string
157
+     */
158
+    public function getHomePath() {
159
+        return $this->homePath;
160
+    }
161
+
162
+    /**
163
+     * getter for the last login timestamp
164
+     * @return int
165
+     */
166
+    public function getLastLogin() {
167
+        return intval($this->lastLogin);
168
+    }
169
+
170
+    /**
171
+     * getter for having active shares
172
+     * @return bool
173
+     */
174
+    public function getHasActiveShares() {
175
+        return $this->hasActiveShares;
176
+    }
177
+
178
+    /**
179
+     * reads the user details
180
+     */
181
+    protected function fetchDetails() {
182
+        $properties = array (
183
+            'displayName' => 'user_ldap',
184
+            'uid'         => 'user_ldap',
185
+            'homePath'    => 'user_ldap',
186
+            'email'       => 'settings',
187
+            'lastLogin'   => 'login'
188
+        );
189
+        foreach($properties as $property => $app) {
190
+            $this->$property = $this->config->getUserValue($this->ocName, $app, $property, '');
191
+        }
192
+
193
+        $dn = $this->mapping->getDNByName($this->ocName);
194
+        $this->dn = ($dn !== false) ? $dn : '';
195
+
196
+        $this->determineShares();
197
+    }
198
+
199
+
200
+    /**
201
+     * finds out whether the user has active shares. The result is stored in
202
+     * $this->hasActiveShares
203
+     */
204
+    protected function determineShares() {
205
+        $query = $this->db->prepare('
206 206
 			SELECT COUNT(`uid_owner`)
207 207
 			FROM `*PREFIX*share`
208 208
 			WHERE `uid_owner` = ?
209 209
 		', 1);
210
-		$query->execute(array($this->ocName));
211
-		$sResult = $query->fetchColumn(0);
212
-		if(intval($sResult) === 1) {
213
-			$this->hasActiveShares = true;
214
-			return;
215
-		}
216
-
217
-		$query = $this->db->prepare('
210
+        $query->execute(array($this->ocName));
211
+        $sResult = $query->fetchColumn(0);
212
+        if(intval($sResult) === 1) {
213
+            $this->hasActiveShares = true;
214
+            return;
215
+        }
216
+
217
+        $query = $this->db->prepare('
218 218
 			SELECT COUNT(`owner`)
219 219
 			FROM `*PREFIX*share_external`
220 220
 			WHERE `owner` = ?
221 221
 		', 1);
222
-		$query->execute(array($this->ocName));
223
-		$sResult = $query->fetchColumn(0);
224
-		if(intval($sResult) === 1) {
225
-			$this->hasActiveShares = true;
226
-			return;
227
-		}
228
-
229
-		$this->hasActiveShares = false;
230
-	}
222
+        $query->execute(array($this->ocName));
223
+        $sResult = $query->fetchColumn(0);
224
+        if(intval($sResult) === 1) {
225
+            $this->hasActiveShares = true;
226
+            return;
227
+        }
228
+
229
+        $this->hasActiveShares = false;
230
+    }
231 231
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/IUserLDAP.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -24,26 +24,26 @@
 block discarded – undo
24 24
 
25 25
 interface IUserLDAP {
26 26
 
27
-	//Functions used by LDAPProvider
27
+    //Functions used by LDAPProvider
28 28
 	
29
-	/**
30
-	 * Return access for LDAP interaction.
31
-	 * @param string $uid
32
-	 * @return Access instance of Access for LDAP interaction
33
-	 */
34
-	public function getLDAPAccess($uid);
29
+    /**
30
+     * Return access for LDAP interaction.
31
+     * @param string $uid
32
+     * @return Access instance of Access for LDAP interaction
33
+     */
34
+    public function getLDAPAccess($uid);
35 35
 	
36
-	/**
37
-	 * Return a new LDAP connection for the specified user.
38
-	 * @param string $uid
39
-	 * @return resource of the LDAP connection
40
-	 */
41
-	public function getNewLDAPConnection($uid);
36
+    /**
37
+     * Return a new LDAP connection for the specified user.
38
+     * @param string $uid
39
+     * @return resource of the LDAP connection
40
+     */
41
+    public function getNewLDAPConnection($uid);
42 42
 
43
-	/**
44
-	 * Return the username for the given LDAP DN, if available.
45
-	 * @param string $dn
46
-	 * @return string|false with the username
47
-	 */
48
-	public function dn2UserName($dn);
43
+    /**
44
+     * Return the username for the given LDAP DN, if available.
45
+     * @param string $dn
46
+     * @return string|false with the username
47
+     */
48
+    public function dn2UserName($dn);
49 49
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Controller/ConfigAPIController.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -147,12 +147,12 @@  discard block
 block discarded – undo
147 147
 	public function delete($configID) {
148 148
 		try {
149 149
 			$this->ensureConfigIDExists($configID);
150
-			if(!$this->ldapHelper->deleteServerConfiguration($configID)) {
150
+			if (!$this->ldapHelper->deleteServerConfiguration($configID)) {
151 151
 				throw new OCSException('Could not delete configuration');
152 152
 			}
153
-		} catch(OCSException $e) {
153
+		} catch (OCSException $e) {
154 154
 			throw $e;
155
-		} catch(\Exception $e) {
155
+		} catch (\Exception $e) {
156 156
 			$this->logger->logException($e);
157 157
 			throw new OCSException('An issue occurred when deleting the config.');
158 158
 		}
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 		try {
188 188
 			$this->ensureConfigIDExists($configID);
189 189
 
190
-			if(!is_array($configData)) {
190
+			if (!is_array($configData)) {
191 191
 				throw new OCSBadRequestException('configData is not properly set');
192 192
 			}
193 193
 
@@ -195,13 +195,13 @@  discard block
 block discarded – undo
195 195
 			$configKeys = $configuration->getConfigTranslationArray();
196 196
 
197 197
 			foreach ($configKeys as $i => $key) {
198
-				if(isset($configData[$key])) {
198
+				if (isset($configData[$key])) {
199 199
 					$configuration->$key = $configData[$key];
200 200
 				}
201 201
 			}
202 202
 
203 203
 			$configuration->saveConfiguration();
204
-		} catch(OCSException $e) {
204
+		} catch (OCSException $e) {
205 205
 			throw $e;
206 206
 		} catch (\Exception $e) {
207 207
 			$this->logger->logException($e);
@@ -288,16 +288,16 @@  discard block
 block discarded – undo
288 288
 
289 289
 			$config = new Configuration($configID);
290 290
 			$data = $config->getConfiguration();
291
-			if(!boolval(intval($showPassword))) {
291
+			if (!boolval(intval($showPassword))) {
292 292
 				$data['ldapAgentPassword'] = '***';
293 293
 			}
294 294
 			foreach ($data as $key => $value) {
295
-				if(is_array($value)) {
295
+				if (is_array($value)) {
296 296
 					$value = implode(';', $value);
297 297
 					$data[$key] = $value;
298 298
 				}
299 299
 			}
300
-		} catch(OCSException $e) {
300
+		} catch (OCSException $e) {
301 301
 			throw $e;
302 302
 		} catch (\Exception $e) {
303 303
 			$this->logger->logException($e);
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 	 */
316 316
 	private function ensureConfigIDExists($configID) {
317 317
 		$prefixes = $this->ldapHelper->getServerConfigurationPrefixes();
318
-		if(!in_array($configID, $prefixes, true)) {
318
+		if (!in_array($configID, $prefixes, true)) {
319 319
 			throw new OCSNotFoundException('Config ID not found');
320 320
 		}
321 321
 	}
Please login to merge, or discard this patch.
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -39,281 +39,281 @@
 block discarded – undo
39 39
 
40 40
 class ConfigAPIController extends OCSController {
41 41
 
42
-	/** @var Helper */
43
-	private $ldapHelper;
42
+    /** @var Helper */
43
+    private $ldapHelper;
44 44
 
45
-	/** @var ILogger */
46
-	private $logger;
45
+    /** @var ILogger */
46
+    private $logger;
47 47
 
48
-	public function __construct(
49
-		$appName,
50
-		IRequest $request,
51
-		CapabilitiesManager $capabilitiesManager,
52
-		IUserSession $userSession,
53
-		IUserManager $userManager,
54
-		Manager $keyManager,
55
-		Helper $ldapHelper,
56
-		ILogger $logger
57
-	) {
58
-		parent::__construct(
59
-			$appName,
60
-			$request,
61
-			$capabilitiesManager,
62
-			$userSession,
63
-			$userManager,
64
-			$keyManager
65
-		);
48
+    public function __construct(
49
+        $appName,
50
+        IRequest $request,
51
+        CapabilitiesManager $capabilitiesManager,
52
+        IUserSession $userSession,
53
+        IUserManager $userManager,
54
+        Manager $keyManager,
55
+        Helper $ldapHelper,
56
+        ILogger $logger
57
+    ) {
58
+        parent::__construct(
59
+            $appName,
60
+            $request,
61
+            $capabilitiesManager,
62
+            $userSession,
63
+            $userManager,
64
+            $keyManager
65
+        );
66 66
 
67 67
 
68
-		$this->ldapHelper = $ldapHelper;
69
-		$this->logger = $logger;
70
-	}
68
+        $this->ldapHelper = $ldapHelper;
69
+        $this->logger = $logger;
70
+    }
71 71
 
72
-	/**
73
-	 * creates a new (empty) configuration and returns the resulting prefix
74
-	 *
75
-	 * Example: curl -X POST -H "OCS-APIREQUEST: true"  -u $admin:$password \
76
-	 *   https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config
77
-	 *
78
-	 * results in:
79
-	 *
80
-	 * <?xml version="1.0"?>
81
-	 * <ocs>
82
-	 *   <meta>
83
-	 *     <status>ok</status>
84
-	 *     <statuscode>200</statuscode>
85
-	 *     <message>OK</message>
86
-	 *   </meta>
87
-	 *   <data>
88
-	 *     <configID>s40</configID>
89
-	 *   </data>
90
-	 * </ocs>
91
-	 *
92
-	 * Failing example: if an exception is thrown (e.g. Database connection lost)
93
-	 * the detailed error will be logged. The output will then look like:
94
-	 *
95
-	 * <?xml version="1.0"?>
96
-	 * <ocs>
97
-	 *   <meta>
98
-	 *     <status>failure</status>
99
-	 *     <statuscode>999</statuscode>
100
-	 *     <message>An issue occurred when creating the new config.</message>
101
-	 *   </meta>
102
-	 *   <data/>
103
-	 * </ocs>
104
-	 *
105
-	 * For JSON output provide the format=json parameter
106
-	 *
107
-	 * @return DataResponse
108
-	 * @throws OCSException
109
-	 */
110
-	public function create() {
111
-		try {
112
-			$configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix();
113
-			$configHolder = new Configuration($configPrefix);
114
-			$configHolder->saveConfiguration();
115
-		} catch (\Exception $e) {
116
-			$this->logger->logException($e);
117
-			throw new OCSException('An issue occurred when creating the new config.');
118
-		}
119
-		return new DataResponse(['configID' => $configPrefix]);
120
-	}
72
+    /**
73
+     * creates a new (empty) configuration and returns the resulting prefix
74
+     *
75
+     * Example: curl -X POST -H "OCS-APIREQUEST: true"  -u $admin:$password \
76
+     *   https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config
77
+     *
78
+     * results in:
79
+     *
80
+     * <?xml version="1.0"?>
81
+     * <ocs>
82
+     *   <meta>
83
+     *     <status>ok</status>
84
+     *     <statuscode>200</statuscode>
85
+     *     <message>OK</message>
86
+     *   </meta>
87
+     *   <data>
88
+     *     <configID>s40</configID>
89
+     *   </data>
90
+     * </ocs>
91
+     *
92
+     * Failing example: if an exception is thrown (e.g. Database connection lost)
93
+     * the detailed error will be logged. The output will then look like:
94
+     *
95
+     * <?xml version="1.0"?>
96
+     * <ocs>
97
+     *   <meta>
98
+     *     <status>failure</status>
99
+     *     <statuscode>999</statuscode>
100
+     *     <message>An issue occurred when creating the new config.</message>
101
+     *   </meta>
102
+     *   <data/>
103
+     * </ocs>
104
+     *
105
+     * For JSON output provide the format=json parameter
106
+     *
107
+     * @return DataResponse
108
+     * @throws OCSException
109
+     */
110
+    public function create() {
111
+        try {
112
+            $configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix();
113
+            $configHolder = new Configuration($configPrefix);
114
+            $configHolder->saveConfiguration();
115
+        } catch (\Exception $e) {
116
+            $this->logger->logException($e);
117
+            throw new OCSException('An issue occurred when creating the new config.');
118
+        }
119
+        return new DataResponse(['configID' => $configPrefix]);
120
+    }
121 121
 
122
-	/**
123
-	 * Deletes a LDAP configuration, if present.
124
-	 *
125
-	 * Example:
126
-	 *   curl -X DELETE -H "OCS-APIREQUEST: true" -u $admin:$password \
127
-	 *    https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60
128
-	 *
129
-	 * <?xml version="1.0"?>
130
-	 * <ocs>
131
-	 *   <meta>
132
-	 *     <status>ok</status>
133
-	 *     <statuscode>200</statuscode>
134
-	 *     <message>OK</message>
135
-	 *   </meta>
136
-	 *   <data/>
137
-	 * </ocs>
138
-	 *
139
-	 * @param string $configID
140
-	 * @return DataResponse
141
-	 * @throws OCSBadRequestException
142
-	 * @throws OCSException
143
-	 */
144
-	public function delete($configID) {
145
-		try {
146
-			$this->ensureConfigIDExists($configID);
147
-			if(!$this->ldapHelper->deleteServerConfiguration($configID)) {
148
-				throw new OCSException('Could not delete configuration');
149
-			}
150
-		} catch(OCSException $e) {
151
-			throw $e;
152
-		} catch(\Exception $e) {
153
-			$this->logger->logException($e);
154
-			throw new OCSException('An issue occurred when deleting the config.');
155
-		}
122
+    /**
123
+     * Deletes a LDAP configuration, if present.
124
+     *
125
+     * Example:
126
+     *   curl -X DELETE -H "OCS-APIREQUEST: true" -u $admin:$password \
127
+     *    https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60
128
+     *
129
+     * <?xml version="1.0"?>
130
+     * <ocs>
131
+     *   <meta>
132
+     *     <status>ok</status>
133
+     *     <statuscode>200</statuscode>
134
+     *     <message>OK</message>
135
+     *   </meta>
136
+     *   <data/>
137
+     * </ocs>
138
+     *
139
+     * @param string $configID
140
+     * @return DataResponse
141
+     * @throws OCSBadRequestException
142
+     * @throws OCSException
143
+     */
144
+    public function delete($configID) {
145
+        try {
146
+            $this->ensureConfigIDExists($configID);
147
+            if(!$this->ldapHelper->deleteServerConfiguration($configID)) {
148
+                throw new OCSException('Could not delete configuration');
149
+            }
150
+        } catch(OCSException $e) {
151
+            throw $e;
152
+        } catch(\Exception $e) {
153
+            $this->logger->logException($e);
154
+            throw new OCSException('An issue occurred when deleting the config.');
155
+        }
156 156
 
157
-		return new DataResponse();
158
-	}
157
+        return new DataResponse();
158
+    }
159 159
 
160
-	/**
161
-	 * modifies a configuration
162
-	 *
163
-	 * Example:
164
-	 *   curl -X PUT -d "configData[ldapHost]=ldaps://my.ldap.server&configData[ldapPort]=636" \
165
-	 *    -H "OCS-APIREQUEST: true" -u $admin:$password \
166
-	 *    https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60
167
-	 *
168
-	 * <?xml version="1.0"?>
169
-	 * <ocs>
170
-	 *   <meta>
171
-	 *     <status>ok</status>
172
-	 *     <statuscode>200</statuscode>
173
-	 *     <message>OK</message>
174
-	 *   </meta>
175
-	 *   <data/>
176
-	 * </ocs>
177
-	 *
178
-	 * @param string $configID
179
-	 * @param array $configData
180
-	 * @return DataResponse
181
-	 * @throws OCSException
182
-	 */
183
-	public function modify($configID, $configData) {
184
-		try {
185
-			$this->ensureConfigIDExists($configID);
160
+    /**
161
+     * modifies a configuration
162
+     *
163
+     * Example:
164
+     *   curl -X PUT -d "configData[ldapHost]=ldaps://my.ldap.server&configData[ldapPort]=636" \
165
+     *    -H "OCS-APIREQUEST: true" -u $admin:$password \
166
+     *    https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60
167
+     *
168
+     * <?xml version="1.0"?>
169
+     * <ocs>
170
+     *   <meta>
171
+     *     <status>ok</status>
172
+     *     <statuscode>200</statuscode>
173
+     *     <message>OK</message>
174
+     *   </meta>
175
+     *   <data/>
176
+     * </ocs>
177
+     *
178
+     * @param string $configID
179
+     * @param array $configData
180
+     * @return DataResponse
181
+     * @throws OCSException
182
+     */
183
+    public function modify($configID, $configData) {
184
+        try {
185
+            $this->ensureConfigIDExists($configID);
186 186
 
187
-			if(!is_array($configData)) {
188
-				throw new OCSBadRequestException('configData is not properly set');
189
-			}
187
+            if(!is_array($configData)) {
188
+                throw new OCSBadRequestException('configData is not properly set');
189
+            }
190 190
 
191
-			$configuration = new Configuration($configID);
192
-			$configKeys = $configuration->getConfigTranslationArray();
191
+            $configuration = new Configuration($configID);
192
+            $configKeys = $configuration->getConfigTranslationArray();
193 193
 
194
-			foreach ($configKeys as $i => $key) {
195
-				if(isset($configData[$key])) {
196
-					$configuration->$key = $configData[$key];
197
-				}
198
-			}
194
+            foreach ($configKeys as $i => $key) {
195
+                if(isset($configData[$key])) {
196
+                    $configuration->$key = $configData[$key];
197
+                }
198
+            }
199 199
 
200
-			$configuration->saveConfiguration();
201
-		} catch(OCSException $e) {
202
-			throw $e;
203
-		} catch (\Exception $e) {
204
-			$this->logger->logException($e);
205
-			throw new OCSException('An issue occurred when modifying the config.');
206
-		}
200
+            $configuration->saveConfiguration();
201
+        } catch(OCSException $e) {
202
+            throw $e;
203
+        } catch (\Exception $e) {
204
+            $this->logger->logException($e);
205
+            throw new OCSException('An issue occurred when modifying the config.');
206
+        }
207 207
 
208
-		return new DataResponse();
209
-	}
208
+        return new DataResponse();
209
+    }
210 210
 
211
-	/**
212
-	 * retrieves a configuration
213
-	 *
214
-	 * <?xml version="1.0"?>
215
-	 * <ocs>
216
-	 *   <meta>
217
-	 *     <status>ok</status>
218
-	 *     <statuscode>200</statuscode>
219
-	 *     <message>OK</message>
220
-	 *   </meta>
221
-	 *   <data>
222
-	 *     <ldapHost>ldaps://my.ldap.server</ldapHost>
223
-	 *     <ldapPort>7770</ldapPort>
224
-	 *     <ldapBackupHost></ldapBackupHost>
225
-	 *     <ldapBackupPort></ldapBackupPort>
226
-	 *     <ldapBase>ou=small,dc=my,dc=ldap,dc=server</ldapBase>
227
-	 *     <ldapBaseUsers>ou=users,ou=small,dc=my,dc=ldap,dc=server</ldapBaseUsers>
228
-	 *     <ldapBaseGroups>ou=small,dc=my,dc=ldap,dc=server</ldapBaseGroups>
229
-	 *     <ldapAgentName>cn=root,dc=my,dc=ldap,dc=server</ldapAgentName>
230
-	 *     <ldapAgentPassword>clearTextWithShowPassword=1</ldapAgentPassword>
231
-	 *     <ldapTLS>1</ldapTLS>
232
-	 *     <turnOffCertCheck>0</turnOffCertCheck>
233
-	 *     <ldapIgnoreNamingRules/>
234
-	 *     <ldapUserDisplayName>displayname</ldapUserDisplayName>
235
-	 *     <ldapUserDisplayName2>uid</ldapUserDisplayName2>
236
-	 *     <ldapUserFilterObjectclass>inetOrgPerson</ldapUserFilterObjectclass>
237
-	 *     <ldapUserFilterGroups></ldapUserFilterGroups>
238
-	 *     <ldapUserFilter>(&amp;(objectclass=nextcloudUser)(nextcloudEnabled=TRUE))</ldapUserFilter>
239
-	 *     <ldapUserFilterMode>1</ldapUserFilterMode>
240
-	 *     <ldapGroupFilter>(&amp;(|(objectclass=nextcloudGroup)))</ldapGroupFilter>
241
-	 *     <ldapGroupFilterMode>0</ldapGroupFilterMode>
242
-	 *     <ldapGroupFilterObjectclass>nextcloudGroup</ldapGroupFilterObjectclass>
243
-	 *     <ldapGroupFilterGroups></ldapGroupFilterGroups>
244
-	 *     <ldapGroupDisplayName>cn</ldapGroupDisplayName>
245
-	 *     <ldapGroupMemberAssocAttr>memberUid</ldapGroupMemberAssocAttr>
246
-	 *     <ldapLoginFilter>(&amp;(|(objectclass=inetOrgPerson))(uid=%uid))</ldapLoginFilter>
247
-	 *     <ldapLoginFilterMode>0</ldapLoginFilterMode>
248
-	 *     <ldapLoginFilterEmail>0</ldapLoginFilterEmail>
249
-	 *     <ldapLoginFilterUsername>1</ldapLoginFilterUsername>
250
-	 *     <ldapLoginFilterAttributes></ldapLoginFilterAttributes>
251
-	 *     <ldapQuotaAttribute></ldapQuotaAttribute>
252
-	 *     <ldapQuotaDefault></ldapQuotaDefault>
253
-	 *     <ldapEmailAttribute>mail</ldapEmailAttribute>
254
-	 *     <ldapCacheTTL>20</ldapCacheTTL>
255
-	 *     <ldapUuidUserAttribute>auto</ldapUuidUserAttribute>
256
-	 *     <ldapUuidGroupAttribute>auto</ldapUuidGroupAttribute>
257
-	 *     <ldapOverrideMainServer></ldapOverrideMainServer>
258
-	 *     <ldapConfigurationActive>1</ldapConfigurationActive>
259
-	 *     <ldapAttributesForUserSearch>uid;sn;givenname</ldapAttributesForUserSearch>
260
-	 *     <ldapAttributesForGroupSearch></ldapAttributesForGroupSearch>
261
-	 *     <ldapExperiencedAdmin>0</ldapExperiencedAdmin>
262
-	 *     <homeFolderNamingRule></homeFolderNamingRule>
263
-	 *     <hasPagedResultSupport></hasPagedResultSupport>
264
-	 *     <hasMemberOfFilterSupport></hasMemberOfFilterSupport>
265
-	 *     <useMemberOfToDetectMembership>1</useMemberOfToDetectMembership>
266
-	 *     <ldapExpertUsernameAttr>uid</ldapExpertUsernameAttr>
267
-	 *     <ldapExpertUUIDUserAttr>uid</ldapExpertUUIDUserAttr>
268
-	 *     <ldapExpertUUIDGroupAttr></ldapExpertUUIDGroupAttr>
269
-	 *     <lastJpegPhotoLookup>0</lastJpegPhotoLookup>
270
-	 *     <ldapNestedGroups>0</ldapNestedGroups>
271
-	 *     <ldapPagingSize>500</ldapPagingSize>
272
-	 *     <turnOnPasswordChange>1</turnOnPasswordChange>
273
-	 *     <ldapDynamicGroupMemberURL></ldapDynamicGroupMemberURL>
274
-	 *   </data>
275
-	 * </ocs>
276
-	 *
277
-	 * @param string $configID
278
-	 * @param bool|string $showPassword
279
-	 * @return DataResponse
280
-	 * @throws OCSException
281
-	 */
282
-	public function show($configID, $showPassword = false) {
283
-		try {
284
-			$this->ensureConfigIDExists($configID);
211
+    /**
212
+     * retrieves a configuration
213
+     *
214
+     * <?xml version="1.0"?>
215
+     * <ocs>
216
+     *   <meta>
217
+     *     <status>ok</status>
218
+     *     <statuscode>200</statuscode>
219
+     *     <message>OK</message>
220
+     *   </meta>
221
+     *   <data>
222
+     *     <ldapHost>ldaps://my.ldap.server</ldapHost>
223
+     *     <ldapPort>7770</ldapPort>
224
+     *     <ldapBackupHost></ldapBackupHost>
225
+     *     <ldapBackupPort></ldapBackupPort>
226
+     *     <ldapBase>ou=small,dc=my,dc=ldap,dc=server</ldapBase>
227
+     *     <ldapBaseUsers>ou=users,ou=small,dc=my,dc=ldap,dc=server</ldapBaseUsers>
228
+     *     <ldapBaseGroups>ou=small,dc=my,dc=ldap,dc=server</ldapBaseGroups>
229
+     *     <ldapAgentName>cn=root,dc=my,dc=ldap,dc=server</ldapAgentName>
230
+     *     <ldapAgentPassword>clearTextWithShowPassword=1</ldapAgentPassword>
231
+     *     <ldapTLS>1</ldapTLS>
232
+     *     <turnOffCertCheck>0</turnOffCertCheck>
233
+     *     <ldapIgnoreNamingRules/>
234
+     *     <ldapUserDisplayName>displayname</ldapUserDisplayName>
235
+     *     <ldapUserDisplayName2>uid</ldapUserDisplayName2>
236
+     *     <ldapUserFilterObjectclass>inetOrgPerson</ldapUserFilterObjectclass>
237
+     *     <ldapUserFilterGroups></ldapUserFilterGroups>
238
+     *     <ldapUserFilter>(&amp;(objectclass=nextcloudUser)(nextcloudEnabled=TRUE))</ldapUserFilter>
239
+     *     <ldapUserFilterMode>1</ldapUserFilterMode>
240
+     *     <ldapGroupFilter>(&amp;(|(objectclass=nextcloudGroup)))</ldapGroupFilter>
241
+     *     <ldapGroupFilterMode>0</ldapGroupFilterMode>
242
+     *     <ldapGroupFilterObjectclass>nextcloudGroup</ldapGroupFilterObjectclass>
243
+     *     <ldapGroupFilterGroups></ldapGroupFilterGroups>
244
+     *     <ldapGroupDisplayName>cn</ldapGroupDisplayName>
245
+     *     <ldapGroupMemberAssocAttr>memberUid</ldapGroupMemberAssocAttr>
246
+     *     <ldapLoginFilter>(&amp;(|(objectclass=inetOrgPerson))(uid=%uid))</ldapLoginFilter>
247
+     *     <ldapLoginFilterMode>0</ldapLoginFilterMode>
248
+     *     <ldapLoginFilterEmail>0</ldapLoginFilterEmail>
249
+     *     <ldapLoginFilterUsername>1</ldapLoginFilterUsername>
250
+     *     <ldapLoginFilterAttributes></ldapLoginFilterAttributes>
251
+     *     <ldapQuotaAttribute></ldapQuotaAttribute>
252
+     *     <ldapQuotaDefault></ldapQuotaDefault>
253
+     *     <ldapEmailAttribute>mail</ldapEmailAttribute>
254
+     *     <ldapCacheTTL>20</ldapCacheTTL>
255
+     *     <ldapUuidUserAttribute>auto</ldapUuidUserAttribute>
256
+     *     <ldapUuidGroupAttribute>auto</ldapUuidGroupAttribute>
257
+     *     <ldapOverrideMainServer></ldapOverrideMainServer>
258
+     *     <ldapConfigurationActive>1</ldapConfigurationActive>
259
+     *     <ldapAttributesForUserSearch>uid;sn;givenname</ldapAttributesForUserSearch>
260
+     *     <ldapAttributesForGroupSearch></ldapAttributesForGroupSearch>
261
+     *     <ldapExperiencedAdmin>0</ldapExperiencedAdmin>
262
+     *     <homeFolderNamingRule></homeFolderNamingRule>
263
+     *     <hasPagedResultSupport></hasPagedResultSupport>
264
+     *     <hasMemberOfFilterSupport></hasMemberOfFilterSupport>
265
+     *     <useMemberOfToDetectMembership>1</useMemberOfToDetectMembership>
266
+     *     <ldapExpertUsernameAttr>uid</ldapExpertUsernameAttr>
267
+     *     <ldapExpertUUIDUserAttr>uid</ldapExpertUUIDUserAttr>
268
+     *     <ldapExpertUUIDGroupAttr></ldapExpertUUIDGroupAttr>
269
+     *     <lastJpegPhotoLookup>0</lastJpegPhotoLookup>
270
+     *     <ldapNestedGroups>0</ldapNestedGroups>
271
+     *     <ldapPagingSize>500</ldapPagingSize>
272
+     *     <turnOnPasswordChange>1</turnOnPasswordChange>
273
+     *     <ldapDynamicGroupMemberURL></ldapDynamicGroupMemberURL>
274
+     *   </data>
275
+     * </ocs>
276
+     *
277
+     * @param string $configID
278
+     * @param bool|string $showPassword
279
+     * @return DataResponse
280
+     * @throws OCSException
281
+     */
282
+    public function show($configID, $showPassword = false) {
283
+        try {
284
+            $this->ensureConfigIDExists($configID);
285 285
 
286
-			$config = new Configuration($configID);
287
-			$data = $config->getConfiguration();
288
-			if(!boolval(intval($showPassword))) {
289
-				$data['ldapAgentPassword'] = '***';
290
-			}
291
-			foreach ($data as $key => $value) {
292
-				if(is_array($value)) {
293
-					$value = implode(';', $value);
294
-					$data[$key] = $value;
295
-				}
296
-			}
297
-		} catch(OCSException $e) {
298
-			throw $e;
299
-		} catch (\Exception $e) {
300
-			$this->logger->logException($e);
301
-			throw new OCSException('An issue occurred when modifying the config.');
302
-		}
286
+            $config = new Configuration($configID);
287
+            $data = $config->getConfiguration();
288
+            if(!boolval(intval($showPassword))) {
289
+                $data['ldapAgentPassword'] = '***';
290
+            }
291
+            foreach ($data as $key => $value) {
292
+                if(is_array($value)) {
293
+                    $value = implode(';', $value);
294
+                    $data[$key] = $value;
295
+                }
296
+            }
297
+        } catch(OCSException $e) {
298
+            throw $e;
299
+        } catch (\Exception $e) {
300
+            $this->logger->logException($e);
301
+            throw new OCSException('An issue occurred when modifying the config.');
302
+        }
303 303
 
304
-		return new DataResponse($data);
305
-	}
304
+        return new DataResponse($data);
305
+    }
306 306
 
307
-	/**
308
-	 * if the given config ID is not available, an exception is thrown
309
-	 *
310
-	 * @param string $configID
311
-	 * @throws OCSNotFoundException
312
-	 */
313
-	private function ensureConfigIDExists($configID) {
314
-		$prefixes = $this->ldapHelper->getServerConfigurationPrefixes();
315
-		if(!in_array($configID, $prefixes, true)) {
316
-			throw new OCSNotFoundException('Config ID not found');
317
-		}
318
-	}
307
+    /**
308
+     * if the given config ID is not available, an exception is thrown
309
+     *
310
+     * @param string $configID
311
+     * @throws OCSNotFoundException
312
+     */
313
+    private function ensureConfigIDExists($configID) {
314
+        $prefixes = $this->ldapHelper->getServerConfigurationPrefixes();
315
+        if(!in_array($configID, $prefixes, true)) {
316
+            throw new OCSNotFoundException('Config ID not found');
317
+        }
318
+    }
319 319
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Jobs/CleanUp.php 2 patches
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -40,194 +40,194 @@
 block discarded – undo
40 40
  * @package OCA\User_LDAP\Jobs;
41 41
  */
42 42
 class CleanUp extends TimedJob {
43
-	/** @var int $limit amount of users that should be checked per run */
44
-	protected $limit = 50;
45
-
46
-	/** @var int $defaultIntervalMin default interval in minutes */
47
-	protected $defaultIntervalMin = 51;
48
-
49
-	/** @var User_LDAP|User_Proxy $userBackend */
50
-	protected $userBackend;
51
-
52
-	/** @var \OCP\IConfig $ocConfig */
53
-	protected $ocConfig;
54
-
55
-	/** @var \OCP\IDBConnection $db */
56
-	protected $db;
57
-
58
-	/** @var Helper $ldapHelper */
59
-	protected $ldapHelper;
60
-
61
-	/** @var \OCA\User_LDAP\Mapping\UserMapping */
62
-	protected $mapping;
63
-
64
-	/** @var \OCA\User_LDAP\User\DeletedUsersIndex */
65
-	protected $dui;
66
-
67
-	public function __construct() {
68
-		$minutes = \OC::$server->getConfig()->getSystemValue(
69
-			'ldapUserCleanupInterval', strval($this->defaultIntervalMin));
70
-		$this->setInterval(intval($minutes) * 60);
71
-	}
72
-
73
-	/**
74
-	 * assigns the instances passed to run() to the class properties
75
-	 * @param array $arguments
76
-	 */
77
-	public function setArguments($arguments) {
78
-		//Dependency Injection is not possible, because the constructor will
79
-		//only get values that are serialized to JSON. I.e. whatever we would
80
-		//pass in app.php we do add here, except something else is passed e.g.
81
-		//in tests.
82
-
83
-		if(isset($arguments['helper'])) {
84
-			$this->ldapHelper = $arguments['helper'];
85
-		} else {
86
-			$this->ldapHelper = new Helper(\OC::$server->getConfig());
87
-		}
88
-
89
-		if(isset($arguments['ocConfig'])) {
90
-			$this->ocConfig = $arguments['ocConfig'];
91
-		} else {
92
-			$this->ocConfig = \OC::$server->getConfig();
93
-		}
94
-
95
-		if(isset($arguments['userBackend'])) {
96
-			$this->userBackend = $arguments['userBackend'];
97
-		} else {
98
-			$this->userBackend =  new User_Proxy(
99
-				$this->ldapHelper->getServerConfigurationPrefixes(true),
100
-				new LDAP(),
101
-				$this->ocConfig
102
-			);
103
-		}
104
-
105
-		if(isset($arguments['db'])) {
106
-			$this->db = $arguments['db'];
107
-		} else {
108
-			$this->db = \OC::$server->getDatabaseConnection();
109
-		}
110
-
111
-		if(isset($arguments['mapping'])) {
112
-			$this->mapping = $arguments['mapping'];
113
-		} else {
114
-			$this->mapping = new UserMapping($this->db);
115
-		}
116
-
117
-		if(isset($arguments['deletedUsersIndex'])) {
118
-			$this->dui = $arguments['deletedUsersIndex'];
119
-		} else {
120
-			$this->dui = new DeletedUsersIndex(
121
-				$this->ocConfig, $this->db, $this->mapping);
122
-		}
123
-	}
124
-
125
-	/**
126
-	 * makes the background job do its work
127
-	 * @param array $argument
128
-	 */
129
-	public function run($argument) {
130
-		$this->setArguments($argument);
131
-
132
-		if(!$this->isCleanUpAllowed()) {
133
-			return;
134
-		}
135
-		$users = $this->mapping->getList($this->getOffset(), $this->limit);
136
-		if(!is_array($users)) {
137
-			//something wrong? Let's start from the beginning next time and
138
-			//abort
139
-			$this->setOffset(true);
140
-			return;
141
-		}
142
-		$resetOffset = $this->isOffsetResetNecessary(count($users));
143
-		$this->checkUsers($users);
144
-		$this->setOffset($resetOffset);
145
-	}
146
-
147
-	/**
148
-	 * checks whether next run should start at 0 again
149
-	 * @param int $resultCount
150
-	 * @return bool
151
-	 */
152
-	public function isOffsetResetNecessary($resultCount) {
153
-		return ($resultCount < $this->limit) ? true : false;
154
-	}
155
-
156
-	/**
157
-	 * checks whether cleaning up LDAP users is allowed
158
-	 * @return bool
159
-	 */
160
-	public function isCleanUpAllowed() {
161
-		try {
162
-			if($this->ldapHelper->haveDisabledConfigurations()) {
163
-				return false;
164
-			}
165
-		} catch (\Exception $e) {
166
-			return false;
167
-		}
168
-
169
-		$enabled = $this->isCleanUpEnabled();
170
-
171
-		return $enabled;
172
-	}
173
-
174
-	/**
175
-	 * checks whether clean up is enabled by configuration
176
-	 * @return bool
177
-	 */
178
-	private function isCleanUpEnabled() {
179
-		return (bool)$this->ocConfig->getSystemValue(
180
-			'ldapUserCleanupInterval', strval($this->defaultIntervalMin));
181
-	}
182
-
183
-	/**
184
-	 * checks users whether they are still existing
185
-	 * @param array $users result from getMappedUsers()
186
-	 */
187
-	private function checkUsers(array $users) {
188
-		foreach($users as $user) {
189
-			$this->checkUser($user);
190
-		}
191
-	}
192
-
193
-	/**
194
-	 * checks whether a user is still existing in LDAP
195
-	 * @param string[] $user
196
-	 */
197
-	private function checkUser(array $user) {
198
-		if($this->userBackend->userExistsOnLDAP($user['name'])) {
199
-			//still available, all good
200
-
201
-			return;
202
-		}
203
-
204
-		$this->dui->markUser($user['name']);
205
-	}
206
-
207
-	/**
208
-	 * gets the offset to fetch users from the mappings table
209
-	 * @return int
210
-	 */
211
-	private function getOffset() {
212
-		return intval($this->ocConfig->getAppValue('user_ldap', 'cleanUpJobOffset', 0));
213
-	}
214
-
215
-	/**
216
-	 * sets the new offset for the next run
217
-	 * @param bool $reset whether the offset should be set to 0
218
-	 */
219
-	public function setOffset($reset = false) {
220
-		$newOffset = $reset ? 0 :
221
-			$this->getOffset() + $this->limit;
222
-		$this->ocConfig->setAppValue('user_ldap', 'cleanUpJobOffset', $newOffset);
223
-	}
224
-
225
-	/**
226
-	 * returns the chunk size (limit in DB speak)
227
-	 * @return int
228
-	 */
229
-	public function getChunkSize() {
230
-		return $this->limit;
231
-	}
43
+    /** @var int $limit amount of users that should be checked per run */
44
+    protected $limit = 50;
45
+
46
+    /** @var int $defaultIntervalMin default interval in minutes */
47
+    protected $defaultIntervalMin = 51;
48
+
49
+    /** @var User_LDAP|User_Proxy $userBackend */
50
+    protected $userBackend;
51
+
52
+    /** @var \OCP\IConfig $ocConfig */
53
+    protected $ocConfig;
54
+
55
+    /** @var \OCP\IDBConnection $db */
56
+    protected $db;
57
+
58
+    /** @var Helper $ldapHelper */
59
+    protected $ldapHelper;
60
+
61
+    /** @var \OCA\User_LDAP\Mapping\UserMapping */
62
+    protected $mapping;
63
+
64
+    /** @var \OCA\User_LDAP\User\DeletedUsersIndex */
65
+    protected $dui;
66
+
67
+    public function __construct() {
68
+        $minutes = \OC::$server->getConfig()->getSystemValue(
69
+            'ldapUserCleanupInterval', strval($this->defaultIntervalMin));
70
+        $this->setInterval(intval($minutes) * 60);
71
+    }
72
+
73
+    /**
74
+     * assigns the instances passed to run() to the class properties
75
+     * @param array $arguments
76
+     */
77
+    public function setArguments($arguments) {
78
+        //Dependency Injection is not possible, because the constructor will
79
+        //only get values that are serialized to JSON. I.e. whatever we would
80
+        //pass in app.php we do add here, except something else is passed e.g.
81
+        //in tests.
82
+
83
+        if(isset($arguments['helper'])) {
84
+            $this->ldapHelper = $arguments['helper'];
85
+        } else {
86
+            $this->ldapHelper = new Helper(\OC::$server->getConfig());
87
+        }
88
+
89
+        if(isset($arguments['ocConfig'])) {
90
+            $this->ocConfig = $arguments['ocConfig'];
91
+        } else {
92
+            $this->ocConfig = \OC::$server->getConfig();
93
+        }
94
+
95
+        if(isset($arguments['userBackend'])) {
96
+            $this->userBackend = $arguments['userBackend'];
97
+        } else {
98
+            $this->userBackend =  new User_Proxy(
99
+                $this->ldapHelper->getServerConfigurationPrefixes(true),
100
+                new LDAP(),
101
+                $this->ocConfig
102
+            );
103
+        }
104
+
105
+        if(isset($arguments['db'])) {
106
+            $this->db = $arguments['db'];
107
+        } else {
108
+            $this->db = \OC::$server->getDatabaseConnection();
109
+        }
110
+
111
+        if(isset($arguments['mapping'])) {
112
+            $this->mapping = $arguments['mapping'];
113
+        } else {
114
+            $this->mapping = new UserMapping($this->db);
115
+        }
116
+
117
+        if(isset($arguments['deletedUsersIndex'])) {
118
+            $this->dui = $arguments['deletedUsersIndex'];
119
+        } else {
120
+            $this->dui = new DeletedUsersIndex(
121
+                $this->ocConfig, $this->db, $this->mapping);
122
+        }
123
+    }
124
+
125
+    /**
126
+     * makes the background job do its work
127
+     * @param array $argument
128
+     */
129
+    public function run($argument) {
130
+        $this->setArguments($argument);
131
+
132
+        if(!$this->isCleanUpAllowed()) {
133
+            return;
134
+        }
135
+        $users = $this->mapping->getList($this->getOffset(), $this->limit);
136
+        if(!is_array($users)) {
137
+            //something wrong? Let's start from the beginning next time and
138
+            //abort
139
+            $this->setOffset(true);
140
+            return;
141
+        }
142
+        $resetOffset = $this->isOffsetResetNecessary(count($users));
143
+        $this->checkUsers($users);
144
+        $this->setOffset($resetOffset);
145
+    }
146
+
147
+    /**
148
+     * checks whether next run should start at 0 again
149
+     * @param int $resultCount
150
+     * @return bool
151
+     */
152
+    public function isOffsetResetNecessary($resultCount) {
153
+        return ($resultCount < $this->limit) ? true : false;
154
+    }
155
+
156
+    /**
157
+     * checks whether cleaning up LDAP users is allowed
158
+     * @return bool
159
+     */
160
+    public function isCleanUpAllowed() {
161
+        try {
162
+            if($this->ldapHelper->haveDisabledConfigurations()) {
163
+                return false;
164
+            }
165
+        } catch (\Exception $e) {
166
+            return false;
167
+        }
168
+
169
+        $enabled = $this->isCleanUpEnabled();
170
+
171
+        return $enabled;
172
+    }
173
+
174
+    /**
175
+     * checks whether clean up is enabled by configuration
176
+     * @return bool
177
+     */
178
+    private function isCleanUpEnabled() {
179
+        return (bool)$this->ocConfig->getSystemValue(
180
+            'ldapUserCleanupInterval', strval($this->defaultIntervalMin));
181
+    }
182
+
183
+    /**
184
+     * checks users whether they are still existing
185
+     * @param array $users result from getMappedUsers()
186
+     */
187
+    private function checkUsers(array $users) {
188
+        foreach($users as $user) {
189
+            $this->checkUser($user);
190
+        }
191
+    }
192
+
193
+    /**
194
+     * checks whether a user is still existing in LDAP
195
+     * @param string[] $user
196
+     */
197
+    private function checkUser(array $user) {
198
+        if($this->userBackend->userExistsOnLDAP($user['name'])) {
199
+            //still available, all good
200
+
201
+            return;
202
+        }
203
+
204
+        $this->dui->markUser($user['name']);
205
+    }
206
+
207
+    /**
208
+     * gets the offset to fetch users from the mappings table
209
+     * @return int
210
+     */
211
+    private function getOffset() {
212
+        return intval($this->ocConfig->getAppValue('user_ldap', 'cleanUpJobOffset', 0));
213
+    }
214
+
215
+    /**
216
+     * sets the new offset for the next run
217
+     * @param bool $reset whether the offset should be set to 0
218
+     */
219
+    public function setOffset($reset = false) {
220
+        $newOffset = $reset ? 0 :
221
+            $this->getOffset() + $this->limit;
222
+        $this->ocConfig->setAppValue('user_ldap', 'cleanUpJobOffset', $newOffset);
223
+    }
224
+
225
+    /**
226
+     * returns the chunk size (limit in DB speak)
227
+     * @return int
228
+     */
229
+    public function getChunkSize() {
230
+        return $this->limit;
231
+    }
232 232
 
233 233
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -15 removed lines patch added patch discarded remove patch
@@ -80,41 +80,41 @@  discard block
 block discarded – undo
80 80
 		//pass in app.php we do add here, except something else is passed e.g.
81 81
 		//in tests.
82 82
 
83
-		if(isset($arguments['helper'])) {
83
+		if (isset($arguments['helper'])) {
84 84
 			$this->ldapHelper = $arguments['helper'];
85 85
 		} else {
86 86
 			$this->ldapHelper = new Helper(\OC::$server->getConfig());
87 87
 		}
88 88
 
89
-		if(isset($arguments['ocConfig'])) {
89
+		if (isset($arguments['ocConfig'])) {
90 90
 			$this->ocConfig = $arguments['ocConfig'];
91 91
 		} else {
92 92
 			$this->ocConfig = \OC::$server->getConfig();
93 93
 		}
94 94
 
95
-		if(isset($arguments['userBackend'])) {
95
+		if (isset($arguments['userBackend'])) {
96 96
 			$this->userBackend = $arguments['userBackend'];
97 97
 		} else {
98
-			$this->userBackend =  new User_Proxy(
98
+			$this->userBackend = new User_Proxy(
99 99
 				$this->ldapHelper->getServerConfigurationPrefixes(true),
100 100
 				new LDAP(),
101 101
 				$this->ocConfig
102 102
 			);
103 103
 		}
104 104
 
105
-		if(isset($arguments['db'])) {
105
+		if (isset($arguments['db'])) {
106 106
 			$this->db = $arguments['db'];
107 107
 		} else {
108 108
 			$this->db = \OC::$server->getDatabaseConnection();
109 109
 		}
110 110
 
111
-		if(isset($arguments['mapping'])) {
111
+		if (isset($arguments['mapping'])) {
112 112
 			$this->mapping = $arguments['mapping'];
113 113
 		} else {
114 114
 			$this->mapping = new UserMapping($this->db);
115 115
 		}
116 116
 
117
-		if(isset($arguments['deletedUsersIndex'])) {
117
+		if (isset($arguments['deletedUsersIndex'])) {
118 118
 			$this->dui = $arguments['deletedUsersIndex'];
119 119
 		} else {
120 120
 			$this->dui = new DeletedUsersIndex(
@@ -129,11 +129,11 @@  discard block
 block discarded – undo
129 129
 	public function run($argument) {
130 130
 		$this->setArguments($argument);
131 131
 
132
-		if(!$this->isCleanUpAllowed()) {
132
+		if (!$this->isCleanUpAllowed()) {
133 133
 			return;
134 134
 		}
135 135
 		$users = $this->mapping->getList($this->getOffset(), $this->limit);
136
-		if(!is_array($users)) {
136
+		if (!is_array($users)) {
137 137
 			//something wrong? Let's start from the beginning next time and
138 138
 			//abort
139 139
 			$this->setOffset(true);
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 */
160 160
 	public function isCleanUpAllowed() {
161 161
 		try {
162
-			if($this->ldapHelper->haveDisabledConfigurations()) {
162
+			if ($this->ldapHelper->haveDisabledConfigurations()) {
163 163
 				return false;
164 164
 			}
165 165
 		} catch (\Exception $e) {
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 	 * @return bool
177 177
 	 */
178 178
 	private function isCleanUpEnabled() {
179
-		return (bool)$this->ocConfig->getSystemValue(
179
+		return (bool) $this->ocConfig->getSystemValue(
180 180
 			'ldapUserCleanupInterval', strval($this->defaultIntervalMin));
181 181
 	}
182 182
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 	 * @param array $users result from getMappedUsers()
186 186
 	 */
187 187
 	private function checkUsers(array $users) {
188
-		foreach($users as $user) {
188
+		foreach ($users as $user) {
189 189
 			$this->checkUser($user);
190 190
 		}
191 191
 	}
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	 * @param string[] $user
196 196
 	 */
197 197
 	private function checkUser(array $user) {
198
-		if($this->userBackend->userExistsOnLDAP($user['name'])) {
198
+		if ($this->userBackend->userExistsOnLDAP($user['name'])) {
199 199
 			//still available, all good
200 200
 
201 201
 			return;
@@ -217,8 +217,7 @@  discard block
 block discarded – undo
217 217
 	 * @param bool $reset whether the offset should be set to 0
218 218
 	 */
219 219
 	public function setOffset($reset = false) {
220
-		$newOffset = $reset ? 0 :
221
-			$this->getOffset() + $this->limit;
220
+		$newOffset = $reset ? 0 : $this->getOffset() + $this->limit;
222 221
 		$this->ocConfig->setAppValue('user_ldap', 'cleanUpJobOffset', $newOffset);
223 222
 	}
224 223
 
Please login to merge, or discard this patch.
apps/user_ldap/lib/BackendUtility.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,13 +27,13 @@
 block discarded – undo
27 27
 
28 28
 
29 29
 abstract class BackendUtility {
30
-	protected $access;
30
+    protected $access;
31 31
 
32
-	/**
33
-	 * constructor, make sure the subclasses call this one!
34
-	 * @param Access $access an instance of Access for LDAP interaction
35
-	 */
36
-	public function __construct(Access $access) {
37
-		$this->access = $access;
38
-	}
32
+    /**
33
+     * constructor, make sure the subclasses call this one!
34
+     * @param Access $access an instance of Access for LDAP interaction
35
+     */
36
+    public function __construct(Access $access) {
37
+        $this->access = $access;
38
+    }
39 39
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/WizardResult.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -28,52 +28,52 @@
 block discarded – undo
28 28
 namespace OCA\User_LDAP;
29 29
 
30 30
 class WizardResult {
31
-	protected $changes = array();
32
-	protected $options = array();
33
-	protected $markedChange = false;
31
+    protected $changes = array();
32
+    protected $options = array();
33
+    protected $markedChange = false;
34 34
 
35
-	/**
36
-	 * @param string $key
37
-	 * @param mixed $value
38
-	 */
39
-	public function addChange($key, $value) {
40
-		$this->changes[$key] = $value;
41
-	}
35
+    /**
36
+     * @param string $key
37
+     * @param mixed $value
38
+     */
39
+    public function addChange($key, $value) {
40
+        $this->changes[$key] = $value;
41
+    }
42 42
 
43
-	/**
44
-	 *
45
-	 */
46
-	public function markChange() {
47
-		$this->markedChange = true;
48
-	}
43
+    /**
44
+     *
45
+     */
46
+    public function markChange() {
47
+        $this->markedChange = true;
48
+    }
49 49
 
50
-	/**
51
-	 * @param string $key
52
-	 * @param array|string $values
53
-	 */
54
-	public function addOptions($key, $values) {
55
-		if(!is_array($values)) {
56
-			$values = array($values);
57
-		}
58
-		$this->options[$key] = $values;
59
-	}
50
+    /**
51
+     * @param string $key
52
+     * @param array|string $values
53
+     */
54
+    public function addOptions($key, $values) {
55
+        if(!is_array($values)) {
56
+            $values = array($values);
57
+        }
58
+        $this->options[$key] = $values;
59
+    }
60 60
 
61
-	/**
62
-	 * @return bool
63
-	 */
64
-	public function hasChanges() {
65
-		return (count($this->changes) > 0 || $this->markedChange);
66
-	}
61
+    /**
62
+     * @return bool
63
+     */
64
+    public function hasChanges() {
65
+        return (count($this->changes) > 0 || $this->markedChange);
66
+    }
67 67
 
68
-	/**
69
-	 * @return array
70
-	 */
71
-	public function getResultArray() {
72
-		$result = array();
73
-		$result['changes'] = $this->changes;
74
-		if(count($this->options) > 0) {
75
-			$result['options'] = $this->options;
76
-		}
77
-		return $result;
78
-	}
68
+    /**
69
+     * @return array
70
+     */
71
+    public function getResultArray() {
72
+        $result = array();
73
+        $result['changes'] = $this->changes;
74
+        if(count($this->options) > 0) {
75
+            $result['options'] = $this->options;
76
+        }
77
+        return $result;
78
+    }
79 79
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 * @param array|string $values
53 53
 	 */
54 54
 	public function addOptions($key, $values) {
55
-		if(!is_array($values)) {
55
+		if (!is_array($values)) {
56 56
 			$values = array($values);
57 57
 		}
58 58
 		$this->options[$key] = $values;
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	public function getResultArray() {
72 72
 		$result = array();
73 73
 		$result['changes'] = $this->changes;
74
-		if(count($this->options) > 0) {
74
+		if (count($this->options) > 0) {
75 75
 			$result['options'] = $this->options;
76 76
 		}
77 77
 		return $result;
Please login to merge, or discard this patch.
apps/user_ldap/lib/Proxy.php 2 patches
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -35,174 +35,174 @@
 block discarded – undo
35 35
 use OCA\User_LDAP\User\Manager;
36 36
 
37 37
 abstract class Proxy {
38
-	static private $accesses = array();
39
-	private $ldap = null;
40
-
41
-	/** @var \OCP\ICache|null */
42
-	private $cache;
43
-
44
-	/**
45
-	 * @param ILDAPWrapper $ldap
46
-	 */
47
-	public function __construct(ILDAPWrapper $ldap) {
48
-		$this->ldap = $ldap;
49
-		$memcache = \OC::$server->getMemCacheFactory();
50
-		if($memcache->isAvailable()) {
51
-			$this->cache = $memcache->create();
52
-		}
53
-	}
54
-
55
-	/**
56
-	 * @param string $configPrefix
57
-	 */
58
-	private function addAccess($configPrefix) {
59
-		static $ocConfig;
60
-		static $fs;
61
-		static $log;
62
-		static $avatarM;
63
-		static $userMap;
64
-		static $groupMap;
65
-		static $db;
66
-		static $coreUserManager;
67
-		if(is_null($fs)) {
68
-			$ocConfig = \OC::$server->getConfig();
69
-			$fs       = new FilesystemHelper();
70
-			$log      = new LogWrapper();
71
-			$avatarM  = \OC::$server->getAvatarManager();
72
-			$db       = \OC::$server->getDatabaseConnection();
73
-			$userMap  = new UserMapping($db);
74
-			$groupMap = new GroupMapping($db);
75
-			$coreUserManager = \OC::$server->getUserManager();
76
-		}
77
-		$userManager =
78
-			new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db, $coreUserManager);
79
-		$connector = new Connection($this->ldap, $configPrefix);
80
-		$access = new Access($connector, $this->ldap, $userManager, new Helper(\OC::$server->getConfig()));
81
-		$access->setUserMapper($userMap);
82
-		$access->setGroupMapper($groupMap);
83
-		self::$accesses[$configPrefix] = $access;
84
-	}
85
-
86
-	/**
87
-	 * @param string $configPrefix
88
-	 * @return mixed
89
-	 */
90
-	protected function getAccess($configPrefix) {
91
-		if(!isset(self::$accesses[$configPrefix])) {
92
-			$this->addAccess($configPrefix);
93
-		}
94
-		return self::$accesses[$configPrefix];
95
-	}
96
-
97
-	/**
98
-	 * @param string $uid
99
-	 * @return string
100
-	 */
101
-	protected function getUserCacheKey($uid) {
102
-		return 'user-'.$uid.'-lastSeenOn';
103
-	}
104
-
105
-	/**
106
-	 * @param string $gid
107
-	 * @return string
108
-	 */
109
-	protected function getGroupCacheKey($gid) {
110
-		return 'group-'.$gid.'-lastSeenOn';
111
-	}
112
-
113
-	/**
114
-	 * @param string $id
115
-	 * @param string $method
116
-	 * @param array $parameters
117
-	 * @param bool $passOnWhen
118
-	 * @return mixed
119
-	 */
120
-	abstract protected function callOnLastSeenOn($id, $method, $parameters, $passOnWhen);
121
-
122
-	/**
123
-	 * @param string $id
124
-	 * @param string $method
125
-	 * @param array $parameters
126
-	 * @return mixed
127
-	 */
128
-	abstract protected function walkBackends($id, $method, $parameters);
129
-
130
-	/**
131
-	 * @param string $id
132
-	 * @return Access
133
-	 */
134
-	abstract public function getLDAPAccess($id);
135
-
136
-	/**
137
-	 * Takes care of the request to the User backend
138
-	 * @param string $id
139
-	 * @param string $method string, the method of the user backend that shall be called
140
-	 * @param array $parameters an array of parameters to be passed
141
-	 * @param bool $passOnWhen
142
-	 * @return mixed, the result of the specified method
143
-	 */
144
-	protected function handleRequest($id, $method, $parameters, $passOnWhen = false) {
145
-		$result = $this->callOnLastSeenOn($id,  $method, $parameters, $passOnWhen);
146
-		if($result === $passOnWhen) {
147
-			$result = $this->walkBackends($id, $method, $parameters);
148
-		}
149
-		return $result;
150
-	}
151
-
152
-	/**
153
-	 * @param string|null $key
154
-	 * @return string
155
-	 */
156
-	private function getCacheKey($key) {
157
-		$prefix = 'LDAP-Proxy-';
158
-		if(is_null($key)) {
159
-			return $prefix;
160
-		}
161
-		return $prefix.md5($key);
162
-	}
163
-
164
-	/**
165
-	 * @param string $key
166
-	 * @return mixed|null
167
-	 */
168
-	public function getFromCache($key) {
169
-		if(is_null($this->cache) || !$this->isCached($key)) {
170
-			return null;
171
-		}
172
-		$key = $this->getCacheKey($key);
173
-
174
-		return json_decode(base64_decode($this->cache->get($key)));
175
-	}
176
-
177
-	/**
178
-	 * @param string $key
179
-	 * @return bool
180
-	 */
181
-	public function isCached($key) {
182
-		if(is_null($this->cache)) {
183
-			return false;
184
-		}
185
-		$key = $this->getCacheKey($key);
186
-		return $this->cache->hasKey($key);
187
-	}
188
-
189
-	/**
190
-	 * @param string $key
191
-	 * @param mixed $value
192
-	 */
193
-	public function writeToCache($key, $value) {
194
-		if(is_null($this->cache)) {
195
-			return;
196
-		}
197
-		$key   = $this->getCacheKey($key);
198
-		$value = base64_encode(json_encode($value));
199
-		$this->cache->set($key, $value, '2592000');
200
-	}
201
-
202
-	public function clearCache() {
203
-		if(is_null($this->cache)) {
204
-			return;
205
-		}
206
-		$this->cache->clear($this->getCacheKey(null));
207
-	}
38
+    static private $accesses = array();
39
+    private $ldap = null;
40
+
41
+    /** @var \OCP\ICache|null */
42
+    private $cache;
43
+
44
+    /**
45
+     * @param ILDAPWrapper $ldap
46
+     */
47
+    public function __construct(ILDAPWrapper $ldap) {
48
+        $this->ldap = $ldap;
49
+        $memcache = \OC::$server->getMemCacheFactory();
50
+        if($memcache->isAvailable()) {
51
+            $this->cache = $memcache->create();
52
+        }
53
+    }
54
+
55
+    /**
56
+     * @param string $configPrefix
57
+     */
58
+    private function addAccess($configPrefix) {
59
+        static $ocConfig;
60
+        static $fs;
61
+        static $log;
62
+        static $avatarM;
63
+        static $userMap;
64
+        static $groupMap;
65
+        static $db;
66
+        static $coreUserManager;
67
+        if(is_null($fs)) {
68
+            $ocConfig = \OC::$server->getConfig();
69
+            $fs       = new FilesystemHelper();
70
+            $log      = new LogWrapper();
71
+            $avatarM  = \OC::$server->getAvatarManager();
72
+            $db       = \OC::$server->getDatabaseConnection();
73
+            $userMap  = new UserMapping($db);
74
+            $groupMap = new GroupMapping($db);
75
+            $coreUserManager = \OC::$server->getUserManager();
76
+        }
77
+        $userManager =
78
+            new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db, $coreUserManager);
79
+        $connector = new Connection($this->ldap, $configPrefix);
80
+        $access = new Access($connector, $this->ldap, $userManager, new Helper(\OC::$server->getConfig()));
81
+        $access->setUserMapper($userMap);
82
+        $access->setGroupMapper($groupMap);
83
+        self::$accesses[$configPrefix] = $access;
84
+    }
85
+
86
+    /**
87
+     * @param string $configPrefix
88
+     * @return mixed
89
+     */
90
+    protected function getAccess($configPrefix) {
91
+        if(!isset(self::$accesses[$configPrefix])) {
92
+            $this->addAccess($configPrefix);
93
+        }
94
+        return self::$accesses[$configPrefix];
95
+    }
96
+
97
+    /**
98
+     * @param string $uid
99
+     * @return string
100
+     */
101
+    protected function getUserCacheKey($uid) {
102
+        return 'user-'.$uid.'-lastSeenOn';
103
+    }
104
+
105
+    /**
106
+     * @param string $gid
107
+     * @return string
108
+     */
109
+    protected function getGroupCacheKey($gid) {
110
+        return 'group-'.$gid.'-lastSeenOn';
111
+    }
112
+
113
+    /**
114
+     * @param string $id
115
+     * @param string $method
116
+     * @param array $parameters
117
+     * @param bool $passOnWhen
118
+     * @return mixed
119
+     */
120
+    abstract protected function callOnLastSeenOn($id, $method, $parameters, $passOnWhen);
121
+
122
+    /**
123
+     * @param string $id
124
+     * @param string $method
125
+     * @param array $parameters
126
+     * @return mixed
127
+     */
128
+    abstract protected function walkBackends($id, $method, $parameters);
129
+
130
+    /**
131
+     * @param string $id
132
+     * @return Access
133
+     */
134
+    abstract public function getLDAPAccess($id);
135
+
136
+    /**
137
+     * Takes care of the request to the User backend
138
+     * @param string $id
139
+     * @param string $method string, the method of the user backend that shall be called
140
+     * @param array $parameters an array of parameters to be passed
141
+     * @param bool $passOnWhen
142
+     * @return mixed, the result of the specified method
143
+     */
144
+    protected function handleRequest($id, $method, $parameters, $passOnWhen = false) {
145
+        $result = $this->callOnLastSeenOn($id,  $method, $parameters, $passOnWhen);
146
+        if($result === $passOnWhen) {
147
+            $result = $this->walkBackends($id, $method, $parameters);
148
+        }
149
+        return $result;
150
+    }
151
+
152
+    /**
153
+     * @param string|null $key
154
+     * @return string
155
+     */
156
+    private function getCacheKey($key) {
157
+        $prefix = 'LDAP-Proxy-';
158
+        if(is_null($key)) {
159
+            return $prefix;
160
+        }
161
+        return $prefix.md5($key);
162
+    }
163
+
164
+    /**
165
+     * @param string $key
166
+     * @return mixed|null
167
+     */
168
+    public function getFromCache($key) {
169
+        if(is_null($this->cache) || !$this->isCached($key)) {
170
+            return null;
171
+        }
172
+        $key = $this->getCacheKey($key);
173
+
174
+        return json_decode(base64_decode($this->cache->get($key)));
175
+    }
176
+
177
+    /**
178
+     * @param string $key
179
+     * @return bool
180
+     */
181
+    public function isCached($key) {
182
+        if(is_null($this->cache)) {
183
+            return false;
184
+        }
185
+        $key = $this->getCacheKey($key);
186
+        return $this->cache->hasKey($key);
187
+    }
188
+
189
+    /**
190
+     * @param string $key
191
+     * @param mixed $value
192
+     */
193
+    public function writeToCache($key, $value) {
194
+        if(is_null($this->cache)) {
195
+            return;
196
+        }
197
+        $key   = $this->getCacheKey($key);
198
+        $value = base64_encode(json_encode($value));
199
+        $this->cache->set($key, $value, '2592000');
200
+    }
201
+
202
+    public function clearCache() {
203
+        if(is_null($this->cache)) {
204
+            return;
205
+        }
206
+        $this->cache->clear($this->getCacheKey(null));
207
+    }
208 208
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	public function __construct(ILDAPWrapper $ldap) {
48 48
 		$this->ldap = $ldap;
49 49
 		$memcache = \OC::$server->getMemCacheFactory();
50
-		if($memcache->isAvailable()) {
50
+		if ($memcache->isAvailable()) {
51 51
 			$this->cache = $memcache->create();
52 52
 		}
53 53
 	}
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		static $groupMap;
65 65
 		static $db;
66 66
 		static $coreUserManager;
67
-		if(is_null($fs)) {
67
+		if (is_null($fs)) {
68 68
 			$ocConfig = \OC::$server->getConfig();
69 69
 			$fs       = new FilesystemHelper();
70 70
 			$log      = new LogWrapper();
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	 * @return mixed
89 89
 	 */
90 90
 	protected function getAccess($configPrefix) {
91
-		if(!isset(self::$accesses[$configPrefix])) {
91
+		if (!isset(self::$accesses[$configPrefix])) {
92 92
 			$this->addAccess($configPrefix);
93 93
 		}
94 94
 		return self::$accesses[$configPrefix];
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
 	 * @return mixed, the result of the specified method
143 143
 	 */
144 144
 	protected function handleRequest($id, $method, $parameters, $passOnWhen = false) {
145
-		$result = $this->callOnLastSeenOn($id,  $method, $parameters, $passOnWhen);
146
-		if($result === $passOnWhen) {
145
+		$result = $this->callOnLastSeenOn($id, $method, $parameters, $passOnWhen);
146
+		if ($result === $passOnWhen) {
147 147
 			$result = $this->walkBackends($id, $method, $parameters);
148 148
 		}
149 149
 		return $result;
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	 */
156 156
 	private function getCacheKey($key) {
157 157
 		$prefix = 'LDAP-Proxy-';
158
-		if(is_null($key)) {
158
+		if (is_null($key)) {
159 159
 			return $prefix;
160 160
 		}
161 161
 		return $prefix.md5($key);
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 	 * @return mixed|null
167 167
 	 */
168 168
 	public function getFromCache($key) {
169
-		if(is_null($this->cache) || !$this->isCached($key)) {
169
+		if (is_null($this->cache) || !$this->isCached($key)) {
170 170
 			return null;
171 171
 		}
172 172
 		$key = $this->getCacheKey($key);
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	 * @return bool
180 180
 	 */
181 181
 	public function isCached($key) {
182
-		if(is_null($this->cache)) {
182
+		if (is_null($this->cache)) {
183 183
 			return false;
184 184
 		}
185 185
 		$key = $this->getCacheKey($key);
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 	 * @param mixed $value
192 192
 	 */
193 193
 	public function writeToCache($key, $value) {
194
-		if(is_null($this->cache)) {
194
+		if (is_null($this->cache)) {
195 195
 			return;
196 196
 		}
197 197
 		$key   = $this->getCacheKey($key);
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 	}
201 201
 
202 202
 	public function clearCache() {
203
-		if(is_null($this->cache)) {
203
+		if (is_null($this->cache)) {
204 204
 			return;
205 205
 		}
206 206
 		$this->cache->clear($this->getCacheKey(null));
Please login to merge, or discard this patch.