Completed
Push — master ( eba447...1a7516 )
by Blizzz
18:31
created
settings/Controller/AdminSettingsController.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	protected function getSettings($section) {
78 78
 		$settings = $this->settingsManager->getAdminSettings($section);
79 79
 		$formatted = $this->formatSettings($settings);
80
-		if($section === 'additional') {
80
+		if ($section === 'additional') {
81 81
 			$formatted['content'] .= $this->getLegacyForms();
82 82
 		}
83 83
 		return $formatted;
@@ -89,9 +89,9 @@  discard block
 block discarded – undo
89 89
 	private function getLegacyForms() {
90 90
 		$forms = \OC_App::getForms('admin');
91 91
 
92
-		$forms = array_map(function ($form) {
92
+		$forms = array_map(function($form) {
93 93
 			if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
94
-				$sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
94
+				$sectionName = str_replace('<h2'.$regs['class'].'>', '', $regs[0]);
95 95
 				$sectionName = str_replace('</h2>', '', $sectionName);
96 96
 				$anchor = strtolower($sectionName);
97 97
 				$anchor = str_replace(' ', '-', $anchor);
Please login to merge, or discard this patch.
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -36,77 +36,77 @@
 block discarded – undo
36 36
  * @package OC\Settings\Controller
37 37
  */
38 38
 class AdminSettingsController extends Controller {
39
-	use CommonSettingsTrait;
39
+    use CommonSettingsTrait;
40 40
 
41
-	/**
42
-	 * @param string $appName
43
-	 * @param IRequest $request
44
-	 * @param INavigationManager $navigationManager
45
-	 * @param ISettingsManager $settingsManager
46
-	 */
47
-	public function __construct(
48
-		$appName,
49
-		IRequest $request,
50
-		INavigationManager $navigationManager,
51
-		ISettingsManager $settingsManager
52
-	) {
53
-		parent::__construct($appName, $request);
54
-		$this->navigationManager = $navigationManager;
55
-		$this->settingsManager = $settingsManager;
56
-	}
41
+    /**
42
+     * @param string $appName
43
+     * @param IRequest $request
44
+     * @param INavigationManager $navigationManager
45
+     * @param ISettingsManager $settingsManager
46
+     */
47
+    public function __construct(
48
+        $appName,
49
+        IRequest $request,
50
+        INavigationManager $navigationManager,
51
+        ISettingsManager $settingsManager
52
+    ) {
53
+        parent::__construct($appName, $request);
54
+        $this->navigationManager = $navigationManager;
55
+        $this->settingsManager = $settingsManager;
56
+    }
57 57
 
58
-	/**
59
-	 * @param string $section
60
-	 * @return TemplateResponse
61
-	 *
62
-	 * @NoCSRFRequired
63
-	 */
64
-	public function index($section) {
65
-		return $this->getIndexResponse('admin', $section);
66
-	}
58
+    /**
59
+     * @param string $section
60
+     * @return TemplateResponse
61
+     *
62
+     * @NoCSRFRequired
63
+     */
64
+    public function index($section) {
65
+        return $this->getIndexResponse('admin', $section);
66
+    }
67 67
 
68
-	/**
69
-	 * @param string $section
70
-	 * @return array
71
-	 */
72
-	protected function getSettings($section) {
73
-		$settings = $this->settingsManager->getAdminSettings($section);
74
-		$formatted = $this->formatSettings($settings);
75
-		if($section === 'additional') {
76
-			$formatted['content'] .= $this->getLegacyForms();
77
-		}
78
-		return $formatted;
79
-	}
68
+    /**
69
+     * @param string $section
70
+     * @return array
71
+     */
72
+    protected function getSettings($section) {
73
+        $settings = $this->settingsManager->getAdminSettings($section);
74
+        $formatted = $this->formatSettings($settings);
75
+        if($section === 'additional') {
76
+            $formatted['content'] .= $this->getLegacyForms();
77
+        }
78
+        return $formatted;
79
+    }
80 80
 
81
-	/**
82
-	 * @return bool|string
83
-	 */
84
-	private function getLegacyForms() {
85
-		$forms = \OC_App::getForms('admin');
81
+    /**
82
+     * @return bool|string
83
+     */
84
+    private function getLegacyForms() {
85
+        $forms = \OC_App::getForms('admin');
86 86
 
87
-		$forms = array_map(function ($form) {
88
-			if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
89
-				$sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
90
-				$sectionName = str_replace('</h2>', '', $sectionName);
91
-				$anchor = strtolower($sectionName);
92
-				$anchor = str_replace(' ', '-', $anchor);
87
+        $forms = array_map(function ($form) {
88
+            if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
89
+                $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
90
+                $sectionName = str_replace('</h2>', '', $sectionName);
91
+                $anchor = strtolower($sectionName);
92
+                $anchor = str_replace(' ', '-', $anchor);
93 93
 
94
-				return array(
95
-					'anchor' => $anchor,
96
-					'section-name' => $sectionName,
97
-					'form' => $form
98
-				);
99
-			}
100
-			return array(
101
-				'form' => $form
102
-			);
103
-		}, $forms);
94
+                return array(
95
+                    'anchor' => $anchor,
96
+                    'section-name' => $sectionName,
97
+                    'form' => $form
98
+                );
99
+            }
100
+            return array(
101
+                'form' => $form
102
+            );
103
+        }, $forms);
104 104
 
105
-		$out = new Template('settings', 'settings/additional');
106
-		$out->assign('forms', $forms);
105
+        $out = new Template('settings', 'settings/additional');
106
+        $out->assign('forms', $forms);
107 107
 
108
-		return $out->fetchPage();
109
-	}
108
+        return $out->fetchPage();
109
+    }
110 110
 
111 111
 
112 112
 }
Please login to merge, or discard this patch.
lib/private/User/User.php 3 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 		$this->uid = $uid;
85 85
 		$this->backend = $backend;
86 86
 		$this->emitter = $emitter;
87
-		if(is_null($config)) {
87
+		if (is_null($config)) {
88 88
 			$config = \OC::$server->getConfig();
89 89
 		}
90 90
 		$this->config = $config;
@@ -160,12 +160,12 @@  discard block
 block discarded – undo
160 160
 	 */
161 161
 	public function setEMailAddress($mailAddress) {
162 162
 		$oldMailAddress = $this->getEMailAddress();
163
-		if($mailAddress === '') {
163
+		if ($mailAddress === '') {
164 164
 			$this->config->deleteUserValue($this->uid, 'settings', 'email');
165 165
 		} else {
166 166
 			$this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress);
167 167
 		}
168
-		if($oldMailAddress !== $mailAddress) {
168
+		if ($oldMailAddress !== $mailAddress) {
169 169
 			$this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress);
170 170
 		}
171 171
 	}
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 			}
230 230
 
231 231
 			// Delete the users entry in the storage table
232
-			Storage::remove('home::' . $this->uid);
232
+			Storage::remove('home::'.$this->uid);
233 233
 
234 234
 			\OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid);
235 235
 			\OC::$server->getCommentsManager()->deleteReadMarksFromUser($this);
@@ -281,9 +281,9 @@  discard block
 block discarded – undo
281 281
 			if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) {
282 282
 				$this->home = $home;
283 283
 			} elseif ($this->config) {
284
-				$this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid;
284
+				$this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/'.$this->uid;
285 285
 			} else {
286
-				$this->home = \OC::$SERVERROOT . '/data/' . $this->uid;
286
+				$this->home = \OC::$SERVERROOT.'/data/'.$this->uid;
287 287
 			}
288 288
 		}
289 289
 		return $this->home;
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 	 * @return string
296 296
 	 */
297 297
 	public function getBackendClassName() {
298
-		if($this->backend instanceof IUserBackend) {
298
+		if ($this->backend instanceof IUserBackend) {
299 299
 			return $this->backend->getBackendName();
300 300
 		}
301 301
 		return get_class($this->backend);
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
 	 */
377 377
 	public function getQuota() {
378 378
 		$quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default');
379
-		if($quota === 'default') {
379
+		if ($quota === 'default') {
380 380
 			$quota = $this->config->getAppValue('files', 'default_quota', 'none');
381 381
 		}
382 382
 		return $quota;
@@ -391,12 +391,12 @@  discard block
 block discarded – undo
391 391
 	 */
392 392
 	public function setQuota($quota) {
393 393
 		$oldQuota = $this->config->getUserValue($this->uid, 'files', 'quota', '');
394
-		if($quota !== 'none' and $quota !== 'default') {
394
+		if ($quota !== 'none' and $quota !== 'default') {
395 395
 			$quota = OC_Helper::computerFileSize($quota);
396 396
 			$quota = OC_Helper::humanFileSize($quota);
397 397
 		}
398 398
 		$this->config->setUserValue($this->uid, 'files', 'quota', $quota);
399
-		if($quota !== $oldQuota) {
399
+		if ($quota !== $oldQuota) {
400 400
 			$this->triggerChange('quota', $quota);
401 401
 		}
402 402
 	}
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 	public function getCloudId() {
433 433
 		$uid = $this->getUID();
434 434
 		$server = $this->urlGenerator->getAbsoluteURL('/');
435
-		$server =  rtrim( $this->removeProtocolFromUrl($server), '/');
435
+		$server = rtrim($this->removeProtocolFromUrl($server), '/');
436 436
 		return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId();
437 437
 	}
438 438
 
Please login to merge, or discard this patch.
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -450,6 +450,10 @@
 block discarded – undo
450 450
 		return $url;
451 451
 	}
452 452
 
453
+	/**
454
+	 * @param string $feature
455
+	 * @param string $oldValue
456
+	 */
453 457
 	public function triggerChange($feature, $value = null, $oldValue = null) {
454 458
 		if ($this->emitter) {
455 459
 			$this->emitter->emit('\OC\User', 'changeUser', array($this, $feature, $value, $oldValue));
Please login to merge, or discard this patch.
Indentation   +411 added lines, -411 removed lines patch added patch discarded remove patch
@@ -44,415 +44,415 @@
 block discarded – undo
44 44
 use \OCP\IUserBackend;
45 45
 
46 46
 class User implements IUser {
47
-	/** @var string $uid */
48
-	private $uid;
49
-
50
-	/** @var string $displayName */
51
-	private $displayName;
52
-
53
-	/** @var UserInterface $backend */
54
-	private $backend;
55
-
56
-	/** @var bool $enabled */
57
-	private $enabled;
58
-
59
-	/** @var Emitter|Manager $emitter */
60
-	private $emitter;
61
-
62
-	/** @var string $home */
63
-	private $home;
64
-
65
-	/** @var int $lastLogin */
66
-	private $lastLogin;
67
-
68
-	/** @var \OCP\IConfig $config */
69
-	private $config;
70
-
71
-	/** @var IAvatarManager */
72
-	private $avatarManager;
73
-
74
-	/** @var IURLGenerator */
75
-	private $urlGenerator;
76
-
77
-	/**
78
-	 * @param string $uid
79
-	 * @param UserInterface $backend
80
-	 * @param \OC\Hooks\Emitter $emitter
81
-	 * @param IConfig|null $config
82
-	 * @param IURLGenerator $urlGenerator
83
-	 */
84
-	public function __construct($uid, $backend, $emitter = null, IConfig $config = null, $urlGenerator = null) {
85
-		$this->uid = $uid;
86
-		$this->backend = $backend;
87
-		$this->emitter = $emitter;
88
-		if(is_null($config)) {
89
-			$config = \OC::$server->getConfig();
90
-		}
91
-		$this->config = $config;
92
-		$this->urlGenerator = $urlGenerator;
93
-		$enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true');
94
-		$this->enabled = ($enabled === 'true');
95
-		$this->lastLogin = $this->config->getUserValue($uid, 'login', 'lastLogin', 0);
96
-		if (is_null($this->urlGenerator)) {
97
-			$this->urlGenerator = \OC::$server->getURLGenerator();
98
-		}
99
-	}
100
-
101
-	/**
102
-	 * get the user id
103
-	 *
104
-	 * @return string
105
-	 */
106
-	public function getUID() {
107
-		return $this->uid;
108
-	}
109
-
110
-	/**
111
-	 * get the display name for the user, if no specific display name is set it will fallback to the user id
112
-	 *
113
-	 * @return string
114
-	 */
115
-	public function getDisplayName() {
116
-		if (!isset($this->displayName)) {
117
-			$displayName = '';
118
-			if ($this->backend and $this->backend->implementsActions(Backend::GET_DISPLAYNAME)) {
119
-				// get display name and strip whitespace from the beginning and end of it
120
-				$backendDisplayName = $this->backend->getDisplayName($this->uid);
121
-				if (is_string($backendDisplayName)) {
122
-					$displayName = trim($backendDisplayName);
123
-				}
124
-			}
125
-
126
-			if (!empty($displayName)) {
127
-				$this->displayName = $displayName;
128
-			} else {
129
-				$this->displayName = $this->uid;
130
-			}
131
-		}
132
-		return $this->displayName;
133
-	}
134
-
135
-	/**
136
-	 * set the displayname for the user
137
-	 *
138
-	 * @param string $displayName
139
-	 * @return bool
140
-	 */
141
-	public function setDisplayName($displayName) {
142
-		$displayName = trim($displayName);
143
-		if ($this->backend->implementsActions(Backend::SET_DISPLAYNAME) && !empty($displayName)) {
144
-			$result = $this->backend->setDisplayName($this->uid, $displayName);
145
-			if ($result) {
146
-				$this->displayName = $displayName;
147
-				$this->triggerChange('displayName', $displayName);
148
-			}
149
-			return $result !== false;
150
-		} else {
151
-			return false;
152
-		}
153
-	}
154
-
155
-	/**
156
-	 * set the email address of the user
157
-	 *
158
-	 * @param string|null $mailAddress
159
-	 * @return void
160
-	 * @since 9.0.0
161
-	 */
162
-	public function setEMailAddress($mailAddress) {
163
-		$oldMailAddress = $this->getEMailAddress();
164
-		if($mailAddress === '') {
165
-			$this->config->deleteUserValue($this->uid, 'settings', 'email');
166
-		} else {
167
-			$this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress);
168
-		}
169
-		if($oldMailAddress !== $mailAddress) {
170
-			$this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress);
171
-		}
172
-	}
173
-
174
-	/**
175
-	 * returns the timestamp of the user's last login or 0 if the user did never
176
-	 * login
177
-	 *
178
-	 * @return int
179
-	 */
180
-	public function getLastLogin() {
181
-		return $this->lastLogin;
182
-	}
183
-
184
-	/**
185
-	 * updates the timestamp of the most recent login of this user
186
-	 */
187
-	public function updateLastLoginTimestamp() {
188
-		$firstTimeLogin = ($this->lastLogin === 0);
189
-		$this->lastLogin = time();
190
-		$this->config->setUserValue(
191
-			$this->uid, 'login', 'lastLogin', $this->lastLogin);
192
-
193
-		return $firstTimeLogin;
194
-	}
195
-
196
-	/**
197
-	 * Delete the user
198
-	 *
199
-	 * @return bool
200
-	 */
201
-	public function delete() {
202
-		if ($this->emitter) {
203
-			$this->emitter->emit('\OC\User', 'preDelete', array($this));
204
-		}
205
-		// get the home now because it won't return it after user deletion
206
-		$homePath = $this->getHome();
207
-		$result = $this->backend->deleteUser($this->uid);
208
-		if ($result) {
209
-
210
-			// FIXME: Feels like an hack - suggestions?
211
-
212
-			$groupManager = \OC::$server->getGroupManager();
213
-			// We have to delete the user from all groups
214
-			foreach ($groupManager->getUserGroupIds($this) as $groupId) {
215
-				$group = $groupManager->get($groupId);
216
-				if ($group) {
217
-					\OC_Hook::emit("OC_Group", "pre_removeFromGroup", ["run" => true, "uid" => $this->uid, "gid" => $groupId]);
218
-					$group->removeUser($this);
219
-					\OC_Hook::emit("OC_User", "post_removeFromGroup", ["uid" => $this->uid, "gid" => $groupId]);
220
-				}
221
-			}
222
-			// Delete the user's keys in preferences
223
-			\OC::$server->getConfig()->deleteAllUserValues($this->uid);
224
-
225
-			// Delete user files in /data/
226
-			if ($homePath !== false) {
227
-				// FIXME: this operates directly on FS, should use View instead...
228
-				// also this is not testable/mockable...
229
-				\OC_Helper::rmdirr($homePath);
230
-			}
231
-
232
-			// Delete the users entry in the storage table
233
-			Storage::remove('home::' . $this->uid);
234
-
235
-			\OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid);
236
-			\OC::$server->getCommentsManager()->deleteReadMarksFromUser($this);
237
-
238
-			$notification = \OC::$server->getNotificationManager()->createNotification();
239
-			$notification->setUser($this->uid);
240
-			\OC::$server->getNotificationManager()->markProcessed($notification);
241
-
242
-			/** @var AccountManager $accountManager */
243
-			$accountManager = \OC::$server->query(AccountManager::class);
244
-			$accountManager->deleteUser($this);
245
-
246
-			if ($this->emitter) {
247
-				$this->emitter->emit('\OC\User', 'postDelete', array($this));
248
-			}
249
-		}
250
-		return !($result === false);
251
-	}
252
-
253
-	/**
254
-	 * Set the password of the user
255
-	 *
256
-	 * @param string $password
257
-	 * @param string $recoveryPassword for the encryption app to reset encryption keys
258
-	 * @return bool
259
-	 */
260
-	public function setPassword($password, $recoveryPassword = null) {
261
-		if ($this->emitter) {
262
-			$this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword));
263
-		}
264
-		if ($this->backend->implementsActions(Backend::SET_PASSWORD)) {
265
-			$result = $this->backend->setPassword($this->uid, $password);
266
-			if ($this->emitter) {
267
-				$this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword));
268
-			}
269
-			return !($result === false);
270
-		} else {
271
-			return false;
272
-		}
273
-	}
274
-
275
-	/**
276
-	 * get the users home folder to mount
277
-	 *
278
-	 * @return string
279
-	 */
280
-	public function getHome() {
281
-		if (!$this->home) {
282
-			if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) {
283
-				$this->home = $home;
284
-			} elseif ($this->config) {
285
-				$this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid;
286
-			} else {
287
-				$this->home = \OC::$SERVERROOT . '/data/' . $this->uid;
288
-			}
289
-		}
290
-		return $this->home;
291
-	}
292
-
293
-	/**
294
-	 * Get the name of the backend class the user is connected with
295
-	 *
296
-	 * @return string
297
-	 */
298
-	public function getBackendClassName() {
299
-		if($this->backend instanceof IUserBackend) {
300
-			return $this->backend->getBackendName();
301
-		}
302
-		return get_class($this->backend);
303
-	}
304
-
305
-	/**
306
-	 * check if the backend allows the user to change his avatar on Personal page
307
-	 *
308
-	 * @return bool
309
-	 */
310
-	public function canChangeAvatar() {
311
-		if ($this->backend->implementsActions(Backend::PROVIDE_AVATAR)) {
312
-			return $this->backend->canChangeAvatar($this->uid);
313
-		}
314
-		return true;
315
-	}
316
-
317
-	/**
318
-	 * check if the backend supports changing passwords
319
-	 *
320
-	 * @return bool
321
-	 */
322
-	public function canChangePassword() {
323
-		return $this->backend->implementsActions(Backend::SET_PASSWORD);
324
-	}
325
-
326
-	/**
327
-	 * check if the backend supports changing display names
328
-	 *
329
-	 * @return bool
330
-	 */
331
-	public function canChangeDisplayName() {
332
-		if ($this->config->getSystemValue('allow_user_to_change_display_name') === false) {
333
-			return false;
334
-		}
335
-		return $this->backend->implementsActions(Backend::SET_DISPLAYNAME);
336
-	}
337
-
338
-	/**
339
-	 * check if the user is enabled
340
-	 *
341
-	 * @return bool
342
-	 */
343
-	public function isEnabled() {
344
-		return $this->enabled;
345
-	}
346
-
347
-	/**
348
-	 * set the enabled status for the user
349
-	 *
350
-	 * @param bool $enabled
351
-	 */
352
-	public function setEnabled(bool $enabled = true) {
353
-		$oldStatus = $this->isEnabled();
354
-		$this->enabled = $enabled;
355
-		if ($oldStatus !== $this->enabled) {
356
-			$this->triggerChange('enabled', $enabled);
357
-			$this->config->setUserValue($this->uid, 'core', 'enabled', $enabled ? 'true' : 'false');
358
-		}
359
-	}
360
-
361
-	/**
362
-	 * get the users email address
363
-	 *
364
-	 * @return string|null
365
-	 * @since 9.0.0
366
-	 */
367
-	public function getEMailAddress() {
368
-		return $this->config->getUserValue($this->uid, 'settings', 'email', null);
369
-	}
370
-
371
-	/**
372
-	 * get the users' quota
373
-	 *
374
-	 * @return string
375
-	 * @since 9.0.0
376
-	 */
377
-	public function getQuota() {
378
-		$quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default');
379
-		if($quota === 'default') {
380
-			$quota = $this->config->getAppValue('files', 'default_quota', 'none');
381
-		}
382
-		return $quota;
383
-	}
384
-
385
-	/**
386
-	 * set the users' quota
387
-	 *
388
-	 * @param string $quota
389
-	 * @return void
390
-	 * @since 9.0.0
391
-	 */
392
-	public function setQuota($quota) {
393
-		$oldQuota = $this->config->getUserValue($this->uid, 'files', 'quota', '');
394
-		if($quota !== 'none' and $quota !== 'default') {
395
-			$quota = OC_Helper::computerFileSize($quota);
396
-			$quota = OC_Helper::humanFileSize($quota);
397
-		}
398
-		$this->config->setUserValue($this->uid, 'files', 'quota', $quota);
399
-		if($quota !== $oldQuota) {
400
-			$this->triggerChange('quota', $quota);
401
-		}
402
-	}
403
-
404
-	/**
405
-	 * get the avatar image if it exists
406
-	 *
407
-	 * @param int $size
408
-	 * @return IImage|null
409
-	 * @since 9.0.0
410
-	 */
411
-	public function getAvatarImage($size) {
412
-		// delay the initialization
413
-		if (is_null($this->avatarManager)) {
414
-			$this->avatarManager = \OC::$server->getAvatarManager();
415
-		}
416
-
417
-		$avatar = $this->avatarManager->getAvatar($this->uid);
418
-		$image = $avatar->get(-1);
419
-		if ($image) {
420
-			return $image;
421
-		}
422
-
423
-		return null;
424
-	}
425
-
426
-	/**
427
-	 * get the federation cloud id
428
-	 *
429
-	 * @return string
430
-	 * @since 9.0.0
431
-	 */
432
-	public function getCloudId() {
433
-		$uid = $this->getUID();
434
-		$server = $this->urlGenerator->getAbsoluteURL('/');
435
-		$server =  rtrim( $this->removeProtocolFromUrl($server), '/');
436
-		return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId();
437
-	}
438
-
439
-	/**
440
-	 * @param string $url
441
-	 * @return string
442
-	 */
443
-	private function removeProtocolFromUrl($url) {
444
-		if (strpos($url, 'https://') === 0) {
445
-			return substr($url, strlen('https://'));
446
-		} else if (strpos($url, 'http://') === 0) {
447
-			return substr($url, strlen('http://'));
448
-		}
449
-
450
-		return $url;
451
-	}
452
-
453
-	public function triggerChange($feature, $value = null, $oldValue = null) {
454
-		if ($this->emitter) {
455
-			$this->emitter->emit('\OC\User', 'changeUser', array($this, $feature, $value, $oldValue));
456
-		}
457
-	}
47
+    /** @var string $uid */
48
+    private $uid;
49
+
50
+    /** @var string $displayName */
51
+    private $displayName;
52
+
53
+    /** @var UserInterface $backend */
54
+    private $backend;
55
+
56
+    /** @var bool $enabled */
57
+    private $enabled;
58
+
59
+    /** @var Emitter|Manager $emitter */
60
+    private $emitter;
61
+
62
+    /** @var string $home */
63
+    private $home;
64
+
65
+    /** @var int $lastLogin */
66
+    private $lastLogin;
67
+
68
+    /** @var \OCP\IConfig $config */
69
+    private $config;
70
+
71
+    /** @var IAvatarManager */
72
+    private $avatarManager;
73
+
74
+    /** @var IURLGenerator */
75
+    private $urlGenerator;
76
+
77
+    /**
78
+     * @param string $uid
79
+     * @param UserInterface $backend
80
+     * @param \OC\Hooks\Emitter $emitter
81
+     * @param IConfig|null $config
82
+     * @param IURLGenerator $urlGenerator
83
+     */
84
+    public function __construct($uid, $backend, $emitter = null, IConfig $config = null, $urlGenerator = null) {
85
+        $this->uid = $uid;
86
+        $this->backend = $backend;
87
+        $this->emitter = $emitter;
88
+        if(is_null($config)) {
89
+            $config = \OC::$server->getConfig();
90
+        }
91
+        $this->config = $config;
92
+        $this->urlGenerator = $urlGenerator;
93
+        $enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true');
94
+        $this->enabled = ($enabled === 'true');
95
+        $this->lastLogin = $this->config->getUserValue($uid, 'login', 'lastLogin', 0);
96
+        if (is_null($this->urlGenerator)) {
97
+            $this->urlGenerator = \OC::$server->getURLGenerator();
98
+        }
99
+    }
100
+
101
+    /**
102
+     * get the user id
103
+     *
104
+     * @return string
105
+     */
106
+    public function getUID() {
107
+        return $this->uid;
108
+    }
109
+
110
+    /**
111
+     * get the display name for the user, if no specific display name is set it will fallback to the user id
112
+     *
113
+     * @return string
114
+     */
115
+    public function getDisplayName() {
116
+        if (!isset($this->displayName)) {
117
+            $displayName = '';
118
+            if ($this->backend and $this->backend->implementsActions(Backend::GET_DISPLAYNAME)) {
119
+                // get display name and strip whitespace from the beginning and end of it
120
+                $backendDisplayName = $this->backend->getDisplayName($this->uid);
121
+                if (is_string($backendDisplayName)) {
122
+                    $displayName = trim($backendDisplayName);
123
+                }
124
+            }
125
+
126
+            if (!empty($displayName)) {
127
+                $this->displayName = $displayName;
128
+            } else {
129
+                $this->displayName = $this->uid;
130
+            }
131
+        }
132
+        return $this->displayName;
133
+    }
134
+
135
+    /**
136
+     * set the displayname for the user
137
+     *
138
+     * @param string $displayName
139
+     * @return bool
140
+     */
141
+    public function setDisplayName($displayName) {
142
+        $displayName = trim($displayName);
143
+        if ($this->backend->implementsActions(Backend::SET_DISPLAYNAME) && !empty($displayName)) {
144
+            $result = $this->backend->setDisplayName($this->uid, $displayName);
145
+            if ($result) {
146
+                $this->displayName = $displayName;
147
+                $this->triggerChange('displayName', $displayName);
148
+            }
149
+            return $result !== false;
150
+        } else {
151
+            return false;
152
+        }
153
+    }
154
+
155
+    /**
156
+     * set the email address of the user
157
+     *
158
+     * @param string|null $mailAddress
159
+     * @return void
160
+     * @since 9.0.0
161
+     */
162
+    public function setEMailAddress($mailAddress) {
163
+        $oldMailAddress = $this->getEMailAddress();
164
+        if($mailAddress === '') {
165
+            $this->config->deleteUserValue($this->uid, 'settings', 'email');
166
+        } else {
167
+            $this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress);
168
+        }
169
+        if($oldMailAddress !== $mailAddress) {
170
+            $this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress);
171
+        }
172
+    }
173
+
174
+    /**
175
+     * returns the timestamp of the user's last login or 0 if the user did never
176
+     * login
177
+     *
178
+     * @return int
179
+     */
180
+    public function getLastLogin() {
181
+        return $this->lastLogin;
182
+    }
183
+
184
+    /**
185
+     * updates the timestamp of the most recent login of this user
186
+     */
187
+    public function updateLastLoginTimestamp() {
188
+        $firstTimeLogin = ($this->lastLogin === 0);
189
+        $this->lastLogin = time();
190
+        $this->config->setUserValue(
191
+            $this->uid, 'login', 'lastLogin', $this->lastLogin);
192
+
193
+        return $firstTimeLogin;
194
+    }
195
+
196
+    /**
197
+     * Delete the user
198
+     *
199
+     * @return bool
200
+     */
201
+    public function delete() {
202
+        if ($this->emitter) {
203
+            $this->emitter->emit('\OC\User', 'preDelete', array($this));
204
+        }
205
+        // get the home now because it won't return it after user deletion
206
+        $homePath = $this->getHome();
207
+        $result = $this->backend->deleteUser($this->uid);
208
+        if ($result) {
209
+
210
+            // FIXME: Feels like an hack - suggestions?
211
+
212
+            $groupManager = \OC::$server->getGroupManager();
213
+            // We have to delete the user from all groups
214
+            foreach ($groupManager->getUserGroupIds($this) as $groupId) {
215
+                $group = $groupManager->get($groupId);
216
+                if ($group) {
217
+                    \OC_Hook::emit("OC_Group", "pre_removeFromGroup", ["run" => true, "uid" => $this->uid, "gid" => $groupId]);
218
+                    $group->removeUser($this);
219
+                    \OC_Hook::emit("OC_User", "post_removeFromGroup", ["uid" => $this->uid, "gid" => $groupId]);
220
+                }
221
+            }
222
+            // Delete the user's keys in preferences
223
+            \OC::$server->getConfig()->deleteAllUserValues($this->uid);
224
+
225
+            // Delete user files in /data/
226
+            if ($homePath !== false) {
227
+                // FIXME: this operates directly on FS, should use View instead...
228
+                // also this is not testable/mockable...
229
+                \OC_Helper::rmdirr($homePath);
230
+            }
231
+
232
+            // Delete the users entry in the storage table
233
+            Storage::remove('home::' . $this->uid);
234
+
235
+            \OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid);
236
+            \OC::$server->getCommentsManager()->deleteReadMarksFromUser($this);
237
+
238
+            $notification = \OC::$server->getNotificationManager()->createNotification();
239
+            $notification->setUser($this->uid);
240
+            \OC::$server->getNotificationManager()->markProcessed($notification);
241
+
242
+            /** @var AccountManager $accountManager */
243
+            $accountManager = \OC::$server->query(AccountManager::class);
244
+            $accountManager->deleteUser($this);
245
+
246
+            if ($this->emitter) {
247
+                $this->emitter->emit('\OC\User', 'postDelete', array($this));
248
+            }
249
+        }
250
+        return !($result === false);
251
+    }
252
+
253
+    /**
254
+     * Set the password of the user
255
+     *
256
+     * @param string $password
257
+     * @param string $recoveryPassword for the encryption app to reset encryption keys
258
+     * @return bool
259
+     */
260
+    public function setPassword($password, $recoveryPassword = null) {
261
+        if ($this->emitter) {
262
+            $this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword));
263
+        }
264
+        if ($this->backend->implementsActions(Backend::SET_PASSWORD)) {
265
+            $result = $this->backend->setPassword($this->uid, $password);
266
+            if ($this->emitter) {
267
+                $this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword));
268
+            }
269
+            return !($result === false);
270
+        } else {
271
+            return false;
272
+        }
273
+    }
274
+
275
+    /**
276
+     * get the users home folder to mount
277
+     *
278
+     * @return string
279
+     */
280
+    public function getHome() {
281
+        if (!$this->home) {
282
+            if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) {
283
+                $this->home = $home;
284
+            } elseif ($this->config) {
285
+                $this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid;
286
+            } else {
287
+                $this->home = \OC::$SERVERROOT . '/data/' . $this->uid;
288
+            }
289
+        }
290
+        return $this->home;
291
+    }
292
+
293
+    /**
294
+     * Get the name of the backend class the user is connected with
295
+     *
296
+     * @return string
297
+     */
298
+    public function getBackendClassName() {
299
+        if($this->backend instanceof IUserBackend) {
300
+            return $this->backend->getBackendName();
301
+        }
302
+        return get_class($this->backend);
303
+    }
304
+
305
+    /**
306
+     * check if the backend allows the user to change his avatar on Personal page
307
+     *
308
+     * @return bool
309
+     */
310
+    public function canChangeAvatar() {
311
+        if ($this->backend->implementsActions(Backend::PROVIDE_AVATAR)) {
312
+            return $this->backend->canChangeAvatar($this->uid);
313
+        }
314
+        return true;
315
+    }
316
+
317
+    /**
318
+     * check if the backend supports changing passwords
319
+     *
320
+     * @return bool
321
+     */
322
+    public function canChangePassword() {
323
+        return $this->backend->implementsActions(Backend::SET_PASSWORD);
324
+    }
325
+
326
+    /**
327
+     * check if the backend supports changing display names
328
+     *
329
+     * @return bool
330
+     */
331
+    public function canChangeDisplayName() {
332
+        if ($this->config->getSystemValue('allow_user_to_change_display_name') === false) {
333
+            return false;
334
+        }
335
+        return $this->backend->implementsActions(Backend::SET_DISPLAYNAME);
336
+    }
337
+
338
+    /**
339
+     * check if the user is enabled
340
+     *
341
+     * @return bool
342
+     */
343
+    public function isEnabled() {
344
+        return $this->enabled;
345
+    }
346
+
347
+    /**
348
+     * set the enabled status for the user
349
+     *
350
+     * @param bool $enabled
351
+     */
352
+    public function setEnabled(bool $enabled = true) {
353
+        $oldStatus = $this->isEnabled();
354
+        $this->enabled = $enabled;
355
+        if ($oldStatus !== $this->enabled) {
356
+            $this->triggerChange('enabled', $enabled);
357
+            $this->config->setUserValue($this->uid, 'core', 'enabled', $enabled ? 'true' : 'false');
358
+        }
359
+    }
360
+
361
+    /**
362
+     * get the users email address
363
+     *
364
+     * @return string|null
365
+     * @since 9.0.0
366
+     */
367
+    public function getEMailAddress() {
368
+        return $this->config->getUserValue($this->uid, 'settings', 'email', null);
369
+    }
370
+
371
+    /**
372
+     * get the users' quota
373
+     *
374
+     * @return string
375
+     * @since 9.0.0
376
+     */
377
+    public function getQuota() {
378
+        $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default');
379
+        if($quota === 'default') {
380
+            $quota = $this->config->getAppValue('files', 'default_quota', 'none');
381
+        }
382
+        return $quota;
383
+    }
384
+
385
+    /**
386
+     * set the users' quota
387
+     *
388
+     * @param string $quota
389
+     * @return void
390
+     * @since 9.0.0
391
+     */
392
+    public function setQuota($quota) {
393
+        $oldQuota = $this->config->getUserValue($this->uid, 'files', 'quota', '');
394
+        if($quota !== 'none' and $quota !== 'default') {
395
+            $quota = OC_Helper::computerFileSize($quota);
396
+            $quota = OC_Helper::humanFileSize($quota);
397
+        }
398
+        $this->config->setUserValue($this->uid, 'files', 'quota', $quota);
399
+        if($quota !== $oldQuota) {
400
+            $this->triggerChange('quota', $quota);
401
+        }
402
+    }
403
+
404
+    /**
405
+     * get the avatar image if it exists
406
+     *
407
+     * @param int $size
408
+     * @return IImage|null
409
+     * @since 9.0.0
410
+     */
411
+    public function getAvatarImage($size) {
412
+        // delay the initialization
413
+        if (is_null($this->avatarManager)) {
414
+            $this->avatarManager = \OC::$server->getAvatarManager();
415
+        }
416
+
417
+        $avatar = $this->avatarManager->getAvatar($this->uid);
418
+        $image = $avatar->get(-1);
419
+        if ($image) {
420
+            return $image;
421
+        }
422
+
423
+        return null;
424
+    }
425
+
426
+    /**
427
+     * get the federation cloud id
428
+     *
429
+     * @return string
430
+     * @since 9.0.0
431
+     */
432
+    public function getCloudId() {
433
+        $uid = $this->getUID();
434
+        $server = $this->urlGenerator->getAbsoluteURL('/');
435
+        $server =  rtrim( $this->removeProtocolFromUrl($server), '/');
436
+        return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId();
437
+    }
438
+
439
+    /**
440
+     * @param string $url
441
+     * @return string
442
+     */
443
+    private function removeProtocolFromUrl($url) {
444
+        if (strpos($url, 'https://') === 0) {
445
+            return substr($url, strlen('https://'));
446
+        } else if (strpos($url, 'http://') === 0) {
447
+            return substr($url, strlen('http://'));
448
+        }
449
+
450
+        return $url;
451
+    }
452
+
453
+    public function triggerChange($feature, $value = null, $oldValue = null) {
454
+        if ($this->emitter) {
455
+            $this->emitter->emit('\OC\User', 'changeUser', array($this, $feature, $value, $oldValue));
456
+        }
457
+    }
458 458
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Settings/Personal.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -32,72 +32,72 @@
 block discarded – undo
32 32
 
33 33
 class Personal implements ISettings {
34 34
 
35
-	/** @var IManager */
36
-	private $encryptionManager;
35
+    /** @var IManager */
36
+    private $encryptionManager;
37 37
 
38
-	/** @var UserGlobalStoragesService */
39
-	private $userGlobalStoragesService;
38
+    /** @var UserGlobalStoragesService */
39
+    private $userGlobalStoragesService;
40 40
 
41
-	/** @var BackendService */
42
-	private $backendService;
41
+    /** @var BackendService */
42
+    private $backendService;
43 43
 
44
-	/** @var GlobalAuth	 */
45
-	private $globalAuth;
44
+    /** @var GlobalAuth	 */
45
+    private $globalAuth;
46 46
 
47
-	/** @var IUserSession */
48
-	private $userSession;
47
+    /** @var IUserSession */
48
+    private $userSession;
49 49
 
50
-	public function __construct(
51
-		IManager $encryptionManager,
52
-		UserGlobalStoragesService $userGlobalStoragesService,
53
-		BackendService $backendService,
54
-		GlobalAuth $globalAuth,
55
-		IUserSession $userSession
56
-	) {
57
-		$this->encryptionManager = $encryptionManager;
58
-		$this->userGlobalStoragesService = $userGlobalStoragesService;
59
-		$this->backendService = $backendService;
60
-		$this->globalAuth = $globalAuth;
61
-		$this->userSession = $userSession;
62
-	}
50
+    public function __construct(
51
+        IManager $encryptionManager,
52
+        UserGlobalStoragesService $userGlobalStoragesService,
53
+        BackendService $backendService,
54
+        GlobalAuth $globalAuth,
55
+        IUserSession $userSession
56
+    ) {
57
+        $this->encryptionManager = $encryptionManager;
58
+        $this->userGlobalStoragesService = $userGlobalStoragesService;
59
+        $this->backendService = $backendService;
60
+        $this->globalAuth = $globalAuth;
61
+        $this->userSession = $userSession;
62
+    }
63 63
 
64
-	/**
65
-	 * @return TemplateResponse
66
-	 */
67
-	public function getForm() {
68
-		$uid = $this->userSession->getUser()->getUID();
64
+    /**
65
+     * @return TemplateResponse
66
+     */
67
+    public function getForm() {
68
+        $uid = $this->userSession->getUser()->getUID();
69 69
 
70
-		$parameters = [
71
-			'encryptionEnabled'    => $this->encryptionManager->isEnabled(),
72
-			'visibilityType'       => BackendService::VISIBILITY_PERSONAL,
73
-			'storages'             => $this->userGlobalStoragesService->getStorages(),
74
-			'backends'             => $this->backendService->getAvailableBackends(),
75
-			'authMechanisms'       => $this->backendService->getAuthMechanisms(),
76
-			'dependencies'         => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()),
77
-			'allowUserMounting'    => $this->backendService->isUserMountingAllowed(),
78
-			'globalCredentials'    => $this->globalAuth->getAuth($uid),
79
-			'globalCredentialsUid' => $uid,
80
-		];
70
+        $parameters = [
71
+            'encryptionEnabled'    => $this->encryptionManager->isEnabled(),
72
+            'visibilityType'       => BackendService::VISIBILITY_PERSONAL,
73
+            'storages'             => $this->userGlobalStoragesService->getStorages(),
74
+            'backends'             => $this->backendService->getAvailableBackends(),
75
+            'authMechanisms'       => $this->backendService->getAuthMechanisms(),
76
+            'dependencies'         => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()),
77
+            'allowUserMounting'    => $this->backendService->isUserMountingAllowed(),
78
+            'globalCredentials'    => $this->globalAuth->getAuth($uid),
79
+            'globalCredentialsUid' => $uid,
80
+        ];
81 81
 
82
-		return new TemplateResponse('files_external', 'settings', $parameters, '');
83
-	}
82
+        return new TemplateResponse('files_external', 'settings', $parameters, '');
83
+    }
84 84
 
85
-	/**
86
-	 * @return string the section ID, e.g. 'sharing'
87
-	 */
88
-	public function getSection() {
89
-		return 'externalstorages';
90
-	}
85
+    /**
86
+     * @return string the section ID, e.g. 'sharing'
87
+     */
88
+    public function getSection() {
89
+        return 'externalstorages';
90
+    }
91 91
 
92
-	/**
93
-	 * @return int whether the form should be rather on the top or bottom of
94
-	 * the admin section. The forms are arranged in ascending order of the
95
-	 * priority values. It is required to return a value between 0 and 100.
96
-	 *
97
-	 * E.g.: 70
98
-	 */
99
-	public function getPriority() {
100
-		return 40;
101
-	}
92
+    /**
93
+     * @return int whether the form should be rather on the top or bottom of
94
+     * the admin section. The forms are arranged in ascending order of the
95
+     * priority values. It is required to return a value between 0 and 100.
96
+     *
97
+     * E.g.: 70
98
+     */
99
+    public function getPriority() {
100
+        return 40;
101
+    }
102 102
 
103 103
 }
Please login to merge, or discard this patch.
apps/files_external/appinfo/app.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,13 +29,13 @@
 block discarded – undo
29 29
 
30 30
 OC::$CLASSPATH['OC_Mount_Config'] = 'files_external/lib/config.php';
31 31
 
32
-require_once __DIR__ . '/../3rdparty/autoload.php';
32
+require_once __DIR__.'/../3rdparty/autoload.php';
33 33
 
34 34
 // register Application object singleton
35 35
 \OC_Mount_Config::$app = new \OCA\Files_External\AppInfo\Application();
36 36
 $appContainer = \OC_Mount_Config::$app->getContainer();
37 37
 
38
-\OCA\Files\App::getNavigationManager()->add(function () {
38
+\OCA\Files\App::getNavigationManager()->add(function() {
39 39
 	$l = \OC::$server->getL10N('files_external');
40 40
 	return [
41 41
 		'id' => 'extstoragemounts',
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -37,14 +37,14 @@
 block discarded – undo
37 37
 $appContainer = \OC_Mount_Config::$app->getContainer();
38 38
 
39 39
 \OCA\Files\App::getNavigationManager()->add(function () {
40
-	$l = \OC::$server->getL10N('files_external');
41
-	return [
42
-		'id' => 'extstoragemounts',
43
-		'appname' => 'files_external',
44
-		'script' => 'list.php',
45
-		'order' => 30,
46
-		'name' => $l->t('External storages'),
47
-	];
40
+    $l = \OC::$server->getL10N('files_external');
41
+    return [
42
+        'id' => 'extstoragemounts',
43
+        'appname' => 'files_external',
44
+        'script' => 'list.php',
45
+        'order' => 30,
46
+        'name' => $l->t('External storages'),
47
+    ];
48 48
 });
49 49
 
50 50
 $mountProvider = $appContainer->query(ConfigAdapter::class);
Please login to merge, or discard this patch.
core/Command/Db/Migrations/ExecuteCommand.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@
 block discarded – undo
78 78
 			$olderVersions = $ms->getMigratedVersions();
79 79
 			$olderVersions[] = '0';
80 80
 			$olderVersions[] = 'prev';
81
-			if (in_array($version,  $olderVersions, true)) {
81
+			if (in_array($version, $olderVersions, true)) {
82 82
 				$output->writeln('<error>Can not go back to previous migration without debug enabled</error>');
83 83
 				return 1;
84 84
 			}
Please login to merge, or discard this patch.
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -38,95 +38,95 @@
 block discarded – undo
38 38
 
39 39
 class ExecuteCommand extends Command implements CompletionAwareInterface {
40 40
 
41
-	/** @var IDBConnection */
42
-	private $connection;
43
-
44
-	/** @var IConfig */
45
-	private $config;
46
-
47
-	/** @var IAppManager */
48
-	protected $appManager;
49
-
50
-	/**
51
-	 * ExecuteCommand constructor.
52
-	 *
53
-	 * @param IDBConnection $connection
54
-	 * @param IConfig $config
55
-	 * @param IAppManager $appManager
56
-	 */
57
-	public function __construct(IDBConnection $connection, IAppManager $appManager, IConfig $config) {
58
-		$this->connection = $connection;
59
-		$this->config = $config;
60
-
61
-		parent::__construct();
62
-	}
63
-
64
-	protected function configure() {
65
-		$this
66
-			->setName('migrations:execute')
67
-			->setDescription('Execute a single migration version manually.')
68
-			->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on')
69
-			->addArgument('version', InputArgument::REQUIRED, 'The version to execute.', null);
70
-
71
-		parent::configure();
72
-	}
73
-
74
-	/**
75
-	 * @param InputInterface $input
76
-	 * @param OutputInterface $output
77
-	 * @return int
78
-	 */
79
-	public function execute(InputInterface $input, OutputInterface $output) {
80
-		$appName = $input->getArgument('app');
81
-		$ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
82
-		$version = $input->getArgument('version');
83
-
84
-		if ($this->config->getSystemValue('debug', false) === false) {
85
-			$olderVersions = $ms->getMigratedVersions();
86
-			$olderVersions[] = '0';
87
-			$olderVersions[] = 'prev';
88
-			if (in_array($version,  $olderVersions, true)) {
89
-				$output->writeln('<error>Can not go back to previous migration without debug enabled</error>');
90
-				return 1;
91
-			}
92
-		}
93
-
94
-
95
-		$ms->executeStep($version);
96
-		return 0;
97
-	}
98
-
99
-	/**
100
-	 * @param string $optionName
101
-	 * @param CompletionContext $context
102
-	 * @return string[]
103
-	 */
104
-	public function completeOptionValues($optionName, CompletionContext $context) {
105
-		return [];
106
-	}
107
-
108
-	/**
109
-	 * @param string $argumentName
110
-	 * @param CompletionContext $context
111
-	 * @return string[]
112
-	 */
113
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
114
-		if ($argumentName === 'app') {
115
-			$allApps = \OC_App::getAllApps();
116
-			return array_diff($allApps, \OC_App::getEnabledApps(true, true));
117
-		}
118
-
119
-		if ($argumentName === 'version') {
120
-			$appName = $context->getWordAtIndex($context->getWordIndex() - 1);
121
-
122
-			$ms = new MigrationService($appName, $this->connection);
123
-			$migrations = $ms->getAvailableVersions();
124
-
125
-			array_unshift($migrations, 'next', 'latest');
126
-			return $migrations;
127
-		}
128
-
129
-		return [];
130
-	}
41
+    /** @var IDBConnection */
42
+    private $connection;
43
+
44
+    /** @var IConfig */
45
+    private $config;
46
+
47
+    /** @var IAppManager */
48
+    protected $appManager;
49
+
50
+    /**
51
+     * ExecuteCommand constructor.
52
+     *
53
+     * @param IDBConnection $connection
54
+     * @param IConfig $config
55
+     * @param IAppManager $appManager
56
+     */
57
+    public function __construct(IDBConnection $connection, IAppManager $appManager, IConfig $config) {
58
+        $this->connection = $connection;
59
+        $this->config = $config;
60
+
61
+        parent::__construct();
62
+    }
63
+
64
+    protected function configure() {
65
+        $this
66
+            ->setName('migrations:execute')
67
+            ->setDescription('Execute a single migration version manually.')
68
+            ->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on')
69
+            ->addArgument('version', InputArgument::REQUIRED, 'The version to execute.', null);
70
+
71
+        parent::configure();
72
+    }
73
+
74
+    /**
75
+     * @param InputInterface $input
76
+     * @param OutputInterface $output
77
+     * @return int
78
+     */
79
+    public function execute(InputInterface $input, OutputInterface $output) {
80
+        $appName = $input->getArgument('app');
81
+        $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
82
+        $version = $input->getArgument('version');
83
+
84
+        if ($this->config->getSystemValue('debug', false) === false) {
85
+            $olderVersions = $ms->getMigratedVersions();
86
+            $olderVersions[] = '0';
87
+            $olderVersions[] = 'prev';
88
+            if (in_array($version,  $olderVersions, true)) {
89
+                $output->writeln('<error>Can not go back to previous migration without debug enabled</error>');
90
+                return 1;
91
+            }
92
+        }
93
+
94
+
95
+        $ms->executeStep($version);
96
+        return 0;
97
+    }
98
+
99
+    /**
100
+     * @param string $optionName
101
+     * @param CompletionContext $context
102
+     * @return string[]
103
+     */
104
+    public function completeOptionValues($optionName, CompletionContext $context) {
105
+        return [];
106
+    }
107
+
108
+    /**
109
+     * @param string $argumentName
110
+     * @param CompletionContext $context
111
+     * @return string[]
112
+     */
113
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
114
+        if ($argumentName === 'app') {
115
+            $allApps = \OC_App::getAllApps();
116
+            return array_diff($allApps, \OC_App::getEnabledApps(true, true));
117
+        }
118
+
119
+        if ($argumentName === 'version') {
120
+            $appName = $context->getWordAtIndex($context->getWordIndex() - 1);
121
+
122
+            $ms = new MigrationService($appName, $this->connection);
123
+            $migrations = $ms->getAvailableVersions();
124
+
125
+            array_unshift($migrations, 'next', 'latest');
126
+            return $migrations;
127
+        }
128
+
129
+        return [];
130
+    }
131 131
 
132 132
 }
Please login to merge, or discard this patch.
lib/private/DB/OracleConnection.php 2 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -26,80 +26,80 @@
 block discarded – undo
26 26
 namespace OC\DB;
27 27
 
28 28
 class OracleConnection extends Connection {
29
-	/**
30
-	 * Quote the keys of the array
31
-	 */
32
-	private function quoteKeys(array $data) {
33
-		$return = [];
34
-		$c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter();
35
-		foreach($data as $key => $value) {
36
-			if ($key[0] !== $c) {
37
-				$return[$this->quoteIdentifier($key)] = $value;
38
-			} else {
39
-				$return[$key] = $value;
40
-			}
41
-		}
42
-		return $return;
43
-	}
29
+    /**
30
+     * Quote the keys of the array
31
+     */
32
+    private function quoteKeys(array $data) {
33
+        $return = [];
34
+        $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter();
35
+        foreach($data as $key => $value) {
36
+            if ($key[0] !== $c) {
37
+                $return[$this->quoteIdentifier($key)] = $value;
38
+            } else {
39
+                $return[$key] = $value;
40
+            }
41
+        }
42
+        return $return;
43
+    }
44 44
 
45
-	/**
46
-	 * {@inheritDoc}
47
-	 */
48
-	public function insert($tableName, array $data, array $types = array()) {
49
-		if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
50
-			$tableName = $this->quoteIdentifier($tableName);
51
-		}
52
-		$data = $this->quoteKeys($data);
53
-		return parent::insert($tableName, $data, $types);
54
-	}
45
+    /**
46
+     * {@inheritDoc}
47
+     */
48
+    public function insert($tableName, array $data, array $types = array()) {
49
+        if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
50
+            $tableName = $this->quoteIdentifier($tableName);
51
+        }
52
+        $data = $this->quoteKeys($data);
53
+        return parent::insert($tableName, $data, $types);
54
+    }
55 55
 
56
-	/**
57
-	 * {@inheritDoc}
58
-	 */
59
-	public function update($tableName, array $data, array $identifier, array $types = array()) {
60
-		if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
61
-			$tableName = $this->quoteIdentifier($tableName);
62
-		}
63
-		$data = $this->quoteKeys($data);
64
-		$identifier = $this->quoteKeys($identifier);
65
-		return parent::update($tableName, $data, $identifier, $types);
66
-	}
56
+    /**
57
+     * {@inheritDoc}
58
+     */
59
+    public function update($tableName, array $data, array $identifier, array $types = array()) {
60
+        if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
61
+            $tableName = $this->quoteIdentifier($tableName);
62
+        }
63
+        $data = $this->quoteKeys($data);
64
+        $identifier = $this->quoteKeys($identifier);
65
+        return parent::update($tableName, $data, $identifier, $types);
66
+    }
67 67
 
68
-	/**
69
-	 * {@inheritDoc}
70
-	 */
71
-	public function delete($tableExpression, array $identifier, array $types = array()) {
72
-		if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
73
-			$tableExpression = $this->quoteIdentifier($tableExpression);
74
-		}
75
-		$identifier = $this->quoteKeys($identifier);
76
-		return parent::delete($tableExpression, $identifier);
77
-	}
68
+    /**
69
+     * {@inheritDoc}
70
+     */
71
+    public function delete($tableExpression, array $identifier, array $types = array()) {
72
+        if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
73
+            $tableExpression = $this->quoteIdentifier($tableExpression);
74
+        }
75
+        $identifier = $this->quoteKeys($identifier);
76
+        return parent::delete($tableExpression, $identifier);
77
+    }
78 78
 
79
-	/**
80
-	 * Drop a table from the database if it exists
81
-	 *
82
-	 * @param string $table table name without the prefix
83
-	 */
84
-	public function dropTable($table) {
85
-		$table = $this->tablePrefix . trim($table);
86
-		$table = $this->quoteIdentifier($table);
87
-		$schema = $this->getSchemaManager();
88
-		if($schema->tablesExist(array($table))) {
89
-			$schema->dropTable($table);
90
-		}
91
-	}
79
+    /**
80
+     * Drop a table from the database if it exists
81
+     *
82
+     * @param string $table table name without the prefix
83
+     */
84
+    public function dropTable($table) {
85
+        $table = $this->tablePrefix . trim($table);
86
+        $table = $this->quoteIdentifier($table);
87
+        $schema = $this->getSchemaManager();
88
+        if($schema->tablesExist(array($table))) {
89
+            $schema->dropTable($table);
90
+        }
91
+    }
92 92
 
93
-	/**
94
-	 * Check if a table exists
95
-	 *
96
-	 * @param string $table table name without the prefix
97
-	 * @return bool
98
-	 */
99
-	public function tableExists($table){
100
-		$table = $this->tablePrefix . trim($table);
101
-		$table = $this->quoteIdentifier($table);
102
-		$schema = $this->getSchemaManager();
103
-		return $schema->tablesExist(array($table));
104
-	}
93
+    /**
94
+     * Check if a table exists
95
+     *
96
+     * @param string $table table name without the prefix
97
+     * @return bool
98
+     */
99
+    public function tableExists($table){
100
+        $table = $this->tablePrefix . trim($table);
101
+        $table = $this->quoteIdentifier($table);
102
+        $schema = $this->getSchemaManager();
103
+        return $schema->tablesExist(array($table));
104
+    }
105 105
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	private function quoteKeys(array $data) {
33 33
 		$return = [];
34 34
 		$c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter();
35
-		foreach($data as $key => $value) {
35
+		foreach ($data as $key => $value) {
36 36
 			if ($key[0] !== $c) {
37 37
 				$return[$this->quoteIdentifier($key)] = $value;
38 38
 			} else {
@@ -82,10 +82,10 @@  discard block
 block discarded – undo
82 82
 	 * @param string $table table name without the prefix
83 83
 	 */
84 84
 	public function dropTable($table) {
85
-		$table = $this->tablePrefix . trim($table);
85
+		$table = $this->tablePrefix.trim($table);
86 86
 		$table = $this->quoteIdentifier($table);
87 87
 		$schema = $this->getSchemaManager();
88
-		if($schema->tablesExist(array($table))) {
88
+		if ($schema->tablesExist(array($table))) {
89 89
 			$schema->dropTable($table);
90 90
 		}
91 91
 	}
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
 	 * @param string $table table name without the prefix
97 97
 	 * @return bool
98 98
 	 */
99
-	public function tableExists($table){
100
-		$table = $this->tablePrefix . trim($table);
99
+	public function tableExists($table) {
100
+		$table = $this->tablePrefix.trim($table);
101 101
 		$table = $this->quoteIdentifier($table);
102 102
 		$schema = $this->getSchemaManager();
103 103
 		return $schema->tablesExist(array($table));
Please login to merge, or discard this patch.
lib/private/Migration/SimpleOutput.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -36,49 +36,49 @@
 block discarded – undo
36 36
  */
37 37
 class SimpleOutput implements IOutput {
38 38
 
39
-	/** @var ILogger */
40
-	private $logger;
41
-	private $appName;
39
+    /** @var ILogger */
40
+    private $logger;
41
+    private $appName;
42 42
 
43
-	public function __construct(ILogger $logger, $appName) {
44
-		$this->logger = $logger;
45
-		$this->appName = $appName;
46
-	}
43
+    public function __construct(ILogger $logger, $appName) {
44
+        $this->logger = $logger;
45
+        $this->appName = $appName;
46
+    }
47 47
 
48
-	/**
49
-	 * @param string $message
50
-	 * @since 9.1.0
51
-	 */
52
-	public function info($message) {
53
-		$this->logger->info($message, ['app' => $this->appName]);
54
-	}
48
+    /**
49
+     * @param string $message
50
+     * @since 9.1.0
51
+     */
52
+    public function info($message) {
53
+        $this->logger->info($message, ['app' => $this->appName]);
54
+    }
55 55
 
56
-	/**
57
-	 * @param string $message
58
-	 * @since 9.1.0
59
-	 */
60
-	public function warning($message) {
61
-		$this->logger->warning($message, ['app' => $this->appName]);
62
-	}
56
+    /**
57
+     * @param string $message
58
+     * @since 9.1.0
59
+     */
60
+    public function warning($message) {
61
+        $this->logger->warning($message, ['app' => $this->appName]);
62
+    }
63 63
 
64
-	/**
65
-	 * @param int $max
66
-	 * @since 9.1.0
67
-	 */
68
-	public function startProgress($max = 0) {
69
-	}
64
+    /**
65
+     * @param int $max
66
+     * @since 9.1.0
67
+     */
68
+    public function startProgress($max = 0) {
69
+    }
70 70
 
71
-	/**
72
-	 * @param int $step
73
-	 * @param string $description
74
-	 * @since 9.1.0
75
-	 */
76
-	public function advance($step = 1, $description = '') {
77
-	}
71
+    /**
72
+     * @param int $step
73
+     * @param string $description
74
+     * @since 9.1.0
75
+     */
76
+    public function advance($step = 1, $description = '') {
77
+    }
78 78
 
79
-	/**
80
-	 * @since 9.1.0
81
-	 */
82
-	public function finishProgress() {
83
-	}
79
+    /**
80
+     * @since 9.1.0
81
+     */
82
+    public function finishProgress() {
83
+    }
84 84
 }
Please login to merge, or discard this patch.
lib/private/DB/SchemaWrapper.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	 * @throws \Doctrine\DBAL\Schema\SchemaException
81 81
 	 */
82 82
 	public function getTable($tableName) {
83
-		return $this->schema->getTable($this->connection->getPrefix() . $tableName);
83
+		return $this->schema->getTable($this->connection->getPrefix().$tableName);
84 84
 	}
85 85
 
86 86
 	/**
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 * @return boolean
92 92
 	 */
93 93
 	public function hasTable($tableName) {
94
-		return $this->schema->hasTable($this->connection->getPrefix() . $tableName);
94
+		return $this->schema->hasTable($this->connection->getPrefix().$tableName);
95 95
 	}
96 96
 
97 97
 	/**
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 	 * @return \Doctrine\DBAL\Schema\Table
102 102
 	 */
103 103
 	public function createTable($tableName) {
104
-		return $this->schema->createTable($this->connection->getPrefix() . $tableName);
104
+		return $this->schema->createTable($this->connection->getPrefix().$tableName);
105 105
 	}
106 106
 
107 107
 	/**
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 	 */
126 126
 	public function dropTable($tableName) {
127 127
 		$this->tablesToDelete[$tableName] = true;
128
-		return $this->schema->dropTable($this->connection->getPrefix() . $tableName);
128
+		return $this->schema->dropTable($this->connection->getPrefix().$tableName);
129 129
 	}
130 130
 
131 131
 	/**
Please login to merge, or discard this patch.
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -30,107 +30,107 @@
 block discarded – undo
30 30
 
31 31
 class SchemaWrapper implements ISchemaWrapper {
32 32
 
33
-	/** @var IDBConnection|Connection */
34
-	protected $connection;
35
-
36
-	/** @var Schema */
37
-	protected $schema;
38
-
39
-	/** @var array */
40
-	protected $tablesToDelete = [];
41
-
42
-	/**
43
-	 * @param IDBConnection $connection
44
-	 */
45
-	public function __construct(IDBConnection $connection) {
46
-		$this->connection = $connection;
47
-		$this->schema = $this->connection->createSchema();
48
-	}
49
-
50
-	public function getWrappedSchema() {
51
-		return $this->schema;
52
-	}
53
-
54
-	public function performDropTableCalls() {
55
-		foreach ($this->tablesToDelete as $tableName => $true) {
56
-			$this->connection->dropTable($tableName);
57
-			unset($this->tablesToDelete[$tableName]);
58
-		}
59
-	}
60
-
61
-	/**
62
-	 * Gets all table names
63
-	 *
64
-	 * @return array
65
-	 */
66
-	public function getTableNamesWithoutPrefix() {
67
-		$tableNames = $this->schema->getTableNames();
68
-		return array_map(function($tableName) {
69
-			if (strpos($tableName, $this->connection->getPrefix()) === 0) {
70
-				return substr($tableName, strlen($this->connection->getPrefix()));
71
-			}
72
-
73
-			return $tableName;
74
-		}, $tableNames);
75
-	}
76
-
77
-	// Overwritten methods
78
-
79
-	/**
80
-	 * @return array
81
-	 */
82
-	public function getTableNames() {
83
-		return $this->schema->getTableNames();
84
-	}
85
-
86
-	/**
87
-	 * @param string $tableName
88
-	 *
89
-	 * @return \Doctrine\DBAL\Schema\Table
90
-	 * @throws \Doctrine\DBAL\Schema\SchemaException
91
-	 */
92
-	public function getTable($tableName) {
93
-		return $this->schema->getTable($this->connection->getPrefix() . $tableName);
94
-	}
95
-
96
-	/**
97
-	 * Does this schema have a table with the given name?
98
-	 *
99
-	 * @param string $tableName
100
-	 *
101
-	 * @return boolean
102
-	 */
103
-	public function hasTable($tableName) {
104
-		return $this->schema->hasTable($this->connection->getPrefix() . $tableName);
105
-	}
106
-
107
-	/**
108
-	 * Creates a new table.
109
-	 *
110
-	 * @param string $tableName
111
-	 * @return \Doctrine\DBAL\Schema\Table
112
-	 */
113
-	public function createTable($tableName) {
114
-		return $this->schema->createTable($this->connection->getPrefix() . $tableName);
115
-	}
116
-
117
-	/**
118
-	 * Drops a table from the schema.
119
-	 *
120
-	 * @param string $tableName
121
-	 * @return \Doctrine\DBAL\Schema\Schema
122
-	 */
123
-	public function dropTable($tableName) {
124
-		$this->tablesToDelete[$tableName] = true;
125
-		return $this->schema->dropTable($this->connection->getPrefix() . $tableName);
126
-	}
127
-
128
-	/**
129
-	 * Gets all tables of this schema.
130
-	 *
131
-	 * @return \Doctrine\DBAL\Schema\Table[]
132
-	 */
133
-	public function getTables() {
134
-		return $this->schema->getTables();
135
-	}
33
+    /** @var IDBConnection|Connection */
34
+    protected $connection;
35
+
36
+    /** @var Schema */
37
+    protected $schema;
38
+
39
+    /** @var array */
40
+    protected $tablesToDelete = [];
41
+
42
+    /**
43
+     * @param IDBConnection $connection
44
+     */
45
+    public function __construct(IDBConnection $connection) {
46
+        $this->connection = $connection;
47
+        $this->schema = $this->connection->createSchema();
48
+    }
49
+
50
+    public function getWrappedSchema() {
51
+        return $this->schema;
52
+    }
53
+
54
+    public function performDropTableCalls() {
55
+        foreach ($this->tablesToDelete as $tableName => $true) {
56
+            $this->connection->dropTable($tableName);
57
+            unset($this->tablesToDelete[$tableName]);
58
+        }
59
+    }
60
+
61
+    /**
62
+     * Gets all table names
63
+     *
64
+     * @return array
65
+     */
66
+    public function getTableNamesWithoutPrefix() {
67
+        $tableNames = $this->schema->getTableNames();
68
+        return array_map(function($tableName) {
69
+            if (strpos($tableName, $this->connection->getPrefix()) === 0) {
70
+                return substr($tableName, strlen($this->connection->getPrefix()));
71
+            }
72
+
73
+            return $tableName;
74
+        }, $tableNames);
75
+    }
76
+
77
+    // Overwritten methods
78
+
79
+    /**
80
+     * @return array
81
+     */
82
+    public function getTableNames() {
83
+        return $this->schema->getTableNames();
84
+    }
85
+
86
+    /**
87
+     * @param string $tableName
88
+     *
89
+     * @return \Doctrine\DBAL\Schema\Table
90
+     * @throws \Doctrine\DBAL\Schema\SchemaException
91
+     */
92
+    public function getTable($tableName) {
93
+        return $this->schema->getTable($this->connection->getPrefix() . $tableName);
94
+    }
95
+
96
+    /**
97
+     * Does this schema have a table with the given name?
98
+     *
99
+     * @param string $tableName
100
+     *
101
+     * @return boolean
102
+     */
103
+    public function hasTable($tableName) {
104
+        return $this->schema->hasTable($this->connection->getPrefix() . $tableName);
105
+    }
106
+
107
+    /**
108
+     * Creates a new table.
109
+     *
110
+     * @param string $tableName
111
+     * @return \Doctrine\DBAL\Schema\Table
112
+     */
113
+    public function createTable($tableName) {
114
+        return $this->schema->createTable($this->connection->getPrefix() . $tableName);
115
+    }
116
+
117
+    /**
118
+     * Drops a table from the schema.
119
+     *
120
+     * @param string $tableName
121
+     * @return \Doctrine\DBAL\Schema\Schema
122
+     */
123
+    public function dropTable($tableName) {
124
+        $this->tablesToDelete[$tableName] = true;
125
+        return $this->schema->dropTable($this->connection->getPrefix() . $tableName);
126
+    }
127
+
128
+    /**
129
+     * Gets all tables of this schema.
130
+     *
131
+     * @return \Doctrine\DBAL\Schema\Table[]
132
+     */
133
+    public function getTables() {
134
+        return $this->schema->getTables();
135
+    }
136 136
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Calendar.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	}
111 111
 
112 112
 	public function getACL() {
113
-		$acl =  [
113
+		$acl = [
114 114
 			[
115 115
 				'privilege' => '{DAV:}read',
116 116
 				'principal' => $this->getOwner(),
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 		}
132 132
 
133 133
 		if ($this->getOwner() !== parent::getOwner()) {
134
-			$acl[] =  [
134
+			$acl[] = [
135 135
 					'privilege' => '{DAV:}read',
136 136
 					'principal' => parent::getOwner(),
137 137
 					'protected' => true,
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	public function delete() {
179 179
 		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) &&
180 180
 			$this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) {
181
-			$principal = 'principal:' . parent::getOwner();
181
+			$principal = 'principal:'.parent::getOwner();
182 182
 			$shares = $this->caldavBackend->getShares($this->getResourceId());
183 183
 			$shares = array_filter($shares, function($share) use ($principal){
184 184
 				return $share['href'] === $principal;
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 
268 268
 		$uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);
269 269
 		if ($this->isShared()) {
270
-			return array_filter($uris, function ($uri) {
270
+			return array_filter($uris, function($uri) {
271 271
 				return $this->childExists($uri);
272 272
 			});
273 273
 		}
Please login to merge, or discard this patch.
Indentation   +297 added lines, -297 removed lines patch added patch discarded remove patch
@@ -42,302 +42,302 @@
 block discarded – undo
42 42
  */
43 43
 class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
44 44
 
45
-	/** @var IConfig */
46
-	private $config;
47
-
48
-	public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) {
49
-		parent::__construct($caldavBackend, $calendarInfo);
50
-
51
-		if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
52
-			$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays');
53
-		}
54
-		if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI &&
55
-			$this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
56
-			$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal');
57
-		}
58
-
59
-		$this->config = $config;
60
-	}
61
-
62
-	/**
63
-	 * Updates the list of shares.
64
-	 *
65
-	 * The first array is a list of people that are to be added to the
66
-	 * resource.
67
-	 *
68
-	 * Every element in the add array has the following properties:
69
-	 *   * href - A url. Usually a mailto: address
70
-	 *   * commonName - Usually a first and last name, or false
71
-	 *   * summary - A description of the share, can also be false
72
-	 *   * readOnly - A boolean value
73
-	 *
74
-	 * Every element in the remove array is just the address string.
75
-	 *
76
-	 * @param array $add
77
-	 * @param array $remove
78
-	 * @return void
79
-	 * @throws Forbidden
80
-	 */
81
-	public function updateShares(array $add, array $remove) {
82
-		if ($this->isShared()) {
83
-			throw new Forbidden();
84
-		}
85
-		$this->caldavBackend->updateShares($this, $add, $remove);
86
-	}
87
-
88
-	/**
89
-	 * Returns the list of people whom this resource is shared with.
90
-	 *
91
-	 * Every element in this array should have the following properties:
92
-	 *   * href - Often a mailto: address
93
-	 *   * commonName - Optional, for example a first + last name
94
-	 *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
95
-	 *   * readOnly - boolean
96
-	 *   * summary - Optional, a description for the share
97
-	 *
98
-	 * @return array
99
-	 */
100
-	public function getShares() {
101
-		if ($this->isShared()) {
102
-			return [];
103
-		}
104
-		return $this->caldavBackend->getShares($this->getResourceId());
105
-	}
106
-
107
-	/**
108
-	 * @return int
109
-	 */
110
-	public function getResourceId() {
111
-		return $this->calendarInfo['id'];
112
-	}
113
-
114
-	/**
115
-	 * @return string
116
-	 */
117
-	public function getPrincipalURI() {
118
-		return $this->calendarInfo['principaluri'];
119
-	}
120
-
121
-	public function getACL() {
122
-		$acl =  [
123
-			[
124
-				'privilege' => '{DAV:}read',
125
-				'principal' => $this->getOwner(),
126
-				'protected' => true,
127
-			]];
128
-		if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) {
129
-			$acl[] = [
130
-				'privilege' => '{DAV:}write',
131
-				'principal' => $this->getOwner(),
132
-				'protected' => true,
133
-			];
134
-		} else {
135
-			$acl[] = [
136
-				'privilege' => '{DAV:}write-properties',
137
-				'principal' => $this->getOwner(),
138
-				'protected' => true,
139
-			];
140
-		}
141
-
142
-		if ($this->getOwner() !== parent::getOwner()) {
143
-			$acl[] =  [
144
-					'privilege' => '{DAV:}read',
145
-					'principal' => parent::getOwner(),
146
-					'protected' => true,
147
-				];
148
-			if ($this->canWrite()) {
149
-				$acl[] = [
150
-					'privilege' => '{DAV:}write',
151
-					'principal' => parent::getOwner(),
152
-					'protected' => true,
153
-				];
154
-			} else {
155
-				$acl[] = [
156
-					'privilege' => '{DAV:}write-properties',
157
-					'principal' => parent::getOwner(),
158
-					'protected' => true,
159
-				];
160
-			}
161
-		}
162
-		if ($this->isPublic()) {
163
-			$acl[] = [
164
-				'privilege' => '{DAV:}read',
165
-				'principal' => 'principals/system/public',
166
-				'protected' => true,
167
-			];
168
-		}
169
-
170
-		$acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl);
171
-
172
-		if (!$this->isShared()) {
173
-			return $acl;
174
-		}
175
-
176
-		$allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public'];
177
-		return array_filter($acl, function($rule) use ($allowedPrincipals) {
178
-			return in_array($rule['principal'], $allowedPrincipals);
179
-		});
180
-	}
181
-
182
-	public function getChildACL() {
183
-		return $this->getACL();
184
-	}
185
-
186
-	public function getOwner() {
187
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
188
-			return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
189
-		}
190
-		return parent::getOwner();
191
-	}
192
-
193
-	public function delete() {
194
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) &&
195
-			$this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) {
196
-			$principal = 'principal:' . parent::getOwner();
197
-			$shares = $this->caldavBackend->getShares($this->getResourceId());
198
-			$shares = array_filter($shares, function($share) use ($principal){
199
-				return $share['href'] === $principal;
200
-			});
201
-			if (empty($shares)) {
202
-				throw new Forbidden();
203
-			}
204
-
205
-			$this->caldavBackend->updateShares($this, [], [
206
-				$principal
207
-			]);
208
-			return;
209
-		}
210
-
211
-		// Remember when a user deleted their birthday calendar
212
-		// in order to not regenerate it on the next contacts change
213
-		if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
214
-			$principalURI = $this->getPrincipalURI();
215
-			$userId = substr($principalURI, 17);
216
-
217
-			$this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no');
218
-		}
219
-
220
-		parent::delete();
221
-	}
222
-
223
-	public function propPatch(PropPatch $propPatch) {
224
-		// parent::propPatch will only update calendars table
225
-		// if calendar is shared, changes have to be made to the properties table
226
-		if (!$this->isShared()) {
227
-			parent::propPatch($propPatch);
228
-		}
229
-	}
230
-
231
-	public function getChild($name) {
232
-
233
-		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
234
-
235
-		if (!$obj) {
236
-			throw new NotFound('Calendar object not found');
237
-		}
238
-
239
-		if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
240
-			throw new NotFound('Calendar object not found');
241
-		}
242
-
243
-		$obj['acl'] = $this->getChildACL();
244
-
245
-		return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
246
-
247
-	}
248
-
249
-	public function getChildren() {
250
-
251
-		$objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);
252
-		$children = [];
253
-		foreach ($objs as $obj) {
254
-			if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
255
-				continue;
256
-			}
257
-			$obj['acl'] = $this->getChildACL();
258
-			$children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
259
-		}
260
-		return $children;
261
-
262
-	}
263
-
264
-	public function getMultipleChildren(array $paths) {
265
-
266
-		$objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);
267
-		$children = [];
268
-		foreach ($objs as $obj) {
269
-			if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
270
-				continue;
271
-			}
272
-			$obj['acl'] = $this->getChildACL();
273
-			$children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
274
-		}
275
-		return $children;
276
-
277
-	}
278
-
279
-	public function childExists($name) {
280
-		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
281
-		if (!$obj) {
282
-			return false;
283
-		}
284
-		if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
285
-			return false;
286
-		}
287
-
288
-		return true;
289
-	}
290
-
291
-	public function calendarQuery(array $filters) {
292
-
293
-		$uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);
294
-		if ($this->isShared()) {
295
-			return array_filter($uris, function ($uri) {
296
-				return $this->childExists($uri);
297
-			});
298
-		}
299
-
300
-		return $uris;
301
-	}
302
-
303
-	/**
304
-	 * @param boolean $value
305
-	 * @return string|null
306
-	 */
307
-	public function setPublishStatus($value) {
308
-		$publicUri = $this->caldavBackend->setPublishStatus($value, $this);
309
-		$this->calendarInfo['publicuri'] = $publicUri;
310
-		return $publicUri;
311
-	}
312
-
313
-	/**
314
-	 * @return mixed $value
315
-	 */
316
-	public function getPublishStatus() {
317
-		return $this->caldavBackend->getPublishStatus($this);
318
-	}
319
-
320
-	private function canWrite() {
321
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) {
322
-			return !$this->calendarInfo['{http://owncloud.org/ns}read-only'];
323
-		}
324
-		return true;
325
-	}
326
-
327
-	private function isPublic() {
328
-		return isset($this->calendarInfo['{http://owncloud.org/ns}public']);
329
-	}
330
-
331
-	protected function isShared() {
332
-		if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
333
-			return false;
334
-		}
335
-
336
-		return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
337
-	}
338
-
339
-	public function isSubscription() {
340
-		return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']);
341
-	}
45
+    /** @var IConfig */
46
+    private $config;
47
+
48
+    public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) {
49
+        parent::__construct($caldavBackend, $calendarInfo);
50
+
51
+        if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
52
+            $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays');
53
+        }
54
+        if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI &&
55
+            $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
56
+            $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal');
57
+        }
58
+
59
+        $this->config = $config;
60
+    }
61
+
62
+    /**
63
+     * Updates the list of shares.
64
+     *
65
+     * The first array is a list of people that are to be added to the
66
+     * resource.
67
+     *
68
+     * Every element in the add array has the following properties:
69
+     *   * href - A url. Usually a mailto: address
70
+     *   * commonName - Usually a first and last name, or false
71
+     *   * summary - A description of the share, can also be false
72
+     *   * readOnly - A boolean value
73
+     *
74
+     * Every element in the remove array is just the address string.
75
+     *
76
+     * @param array $add
77
+     * @param array $remove
78
+     * @return void
79
+     * @throws Forbidden
80
+     */
81
+    public function updateShares(array $add, array $remove) {
82
+        if ($this->isShared()) {
83
+            throw new Forbidden();
84
+        }
85
+        $this->caldavBackend->updateShares($this, $add, $remove);
86
+    }
87
+
88
+    /**
89
+     * Returns the list of people whom this resource is shared with.
90
+     *
91
+     * Every element in this array should have the following properties:
92
+     *   * href - Often a mailto: address
93
+     *   * commonName - Optional, for example a first + last name
94
+     *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
95
+     *   * readOnly - boolean
96
+     *   * summary - Optional, a description for the share
97
+     *
98
+     * @return array
99
+     */
100
+    public function getShares() {
101
+        if ($this->isShared()) {
102
+            return [];
103
+        }
104
+        return $this->caldavBackend->getShares($this->getResourceId());
105
+    }
106
+
107
+    /**
108
+     * @return int
109
+     */
110
+    public function getResourceId() {
111
+        return $this->calendarInfo['id'];
112
+    }
113
+
114
+    /**
115
+     * @return string
116
+     */
117
+    public function getPrincipalURI() {
118
+        return $this->calendarInfo['principaluri'];
119
+    }
120
+
121
+    public function getACL() {
122
+        $acl =  [
123
+            [
124
+                'privilege' => '{DAV:}read',
125
+                'principal' => $this->getOwner(),
126
+                'protected' => true,
127
+            ]];
128
+        if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) {
129
+            $acl[] = [
130
+                'privilege' => '{DAV:}write',
131
+                'principal' => $this->getOwner(),
132
+                'protected' => true,
133
+            ];
134
+        } else {
135
+            $acl[] = [
136
+                'privilege' => '{DAV:}write-properties',
137
+                'principal' => $this->getOwner(),
138
+                'protected' => true,
139
+            ];
140
+        }
141
+
142
+        if ($this->getOwner() !== parent::getOwner()) {
143
+            $acl[] =  [
144
+                    'privilege' => '{DAV:}read',
145
+                    'principal' => parent::getOwner(),
146
+                    'protected' => true,
147
+                ];
148
+            if ($this->canWrite()) {
149
+                $acl[] = [
150
+                    'privilege' => '{DAV:}write',
151
+                    'principal' => parent::getOwner(),
152
+                    'protected' => true,
153
+                ];
154
+            } else {
155
+                $acl[] = [
156
+                    'privilege' => '{DAV:}write-properties',
157
+                    'principal' => parent::getOwner(),
158
+                    'protected' => true,
159
+                ];
160
+            }
161
+        }
162
+        if ($this->isPublic()) {
163
+            $acl[] = [
164
+                'privilege' => '{DAV:}read',
165
+                'principal' => 'principals/system/public',
166
+                'protected' => true,
167
+            ];
168
+        }
169
+
170
+        $acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl);
171
+
172
+        if (!$this->isShared()) {
173
+            return $acl;
174
+        }
175
+
176
+        $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public'];
177
+        return array_filter($acl, function($rule) use ($allowedPrincipals) {
178
+            return in_array($rule['principal'], $allowedPrincipals);
179
+        });
180
+    }
181
+
182
+    public function getChildACL() {
183
+        return $this->getACL();
184
+    }
185
+
186
+    public function getOwner() {
187
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
188
+            return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
189
+        }
190
+        return parent::getOwner();
191
+    }
192
+
193
+    public function delete() {
194
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) &&
195
+            $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) {
196
+            $principal = 'principal:' . parent::getOwner();
197
+            $shares = $this->caldavBackend->getShares($this->getResourceId());
198
+            $shares = array_filter($shares, function($share) use ($principal){
199
+                return $share['href'] === $principal;
200
+            });
201
+            if (empty($shares)) {
202
+                throw new Forbidden();
203
+            }
204
+
205
+            $this->caldavBackend->updateShares($this, [], [
206
+                $principal
207
+            ]);
208
+            return;
209
+        }
210
+
211
+        // Remember when a user deleted their birthday calendar
212
+        // in order to not regenerate it on the next contacts change
213
+        if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
214
+            $principalURI = $this->getPrincipalURI();
215
+            $userId = substr($principalURI, 17);
216
+
217
+            $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no');
218
+        }
219
+
220
+        parent::delete();
221
+    }
222
+
223
+    public function propPatch(PropPatch $propPatch) {
224
+        // parent::propPatch will only update calendars table
225
+        // if calendar is shared, changes have to be made to the properties table
226
+        if (!$this->isShared()) {
227
+            parent::propPatch($propPatch);
228
+        }
229
+    }
230
+
231
+    public function getChild($name) {
232
+
233
+        $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
234
+
235
+        if (!$obj) {
236
+            throw new NotFound('Calendar object not found');
237
+        }
238
+
239
+        if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
240
+            throw new NotFound('Calendar object not found');
241
+        }
242
+
243
+        $obj['acl'] = $this->getChildACL();
244
+
245
+        return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
246
+
247
+    }
248
+
249
+    public function getChildren() {
250
+
251
+        $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);
252
+        $children = [];
253
+        foreach ($objs as $obj) {
254
+            if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
255
+                continue;
256
+            }
257
+            $obj['acl'] = $this->getChildACL();
258
+            $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
259
+        }
260
+        return $children;
261
+
262
+    }
263
+
264
+    public function getMultipleChildren(array $paths) {
265
+
266
+        $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);
267
+        $children = [];
268
+        foreach ($objs as $obj) {
269
+            if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
270
+                continue;
271
+            }
272
+            $obj['acl'] = $this->getChildACL();
273
+            $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
274
+        }
275
+        return $children;
276
+
277
+    }
278
+
279
+    public function childExists($name) {
280
+        $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
281
+        if (!$obj) {
282
+            return false;
283
+        }
284
+        if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) {
285
+            return false;
286
+        }
287
+
288
+        return true;
289
+    }
290
+
291
+    public function calendarQuery(array $filters) {
292
+
293
+        $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);
294
+        if ($this->isShared()) {
295
+            return array_filter($uris, function ($uri) {
296
+                return $this->childExists($uri);
297
+            });
298
+        }
299
+
300
+        return $uris;
301
+    }
302
+
303
+    /**
304
+     * @param boolean $value
305
+     * @return string|null
306
+     */
307
+    public function setPublishStatus($value) {
308
+        $publicUri = $this->caldavBackend->setPublishStatus($value, $this);
309
+        $this->calendarInfo['publicuri'] = $publicUri;
310
+        return $publicUri;
311
+    }
312
+
313
+    /**
314
+     * @return mixed $value
315
+     */
316
+    public function getPublishStatus() {
317
+        return $this->caldavBackend->getPublishStatus($this);
318
+    }
319
+
320
+    private function canWrite() {
321
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) {
322
+            return !$this->calendarInfo['{http://owncloud.org/ns}read-only'];
323
+        }
324
+        return true;
325
+    }
326
+
327
+    private function isPublic() {
328
+        return isset($this->calendarInfo['{http://owncloud.org/ns}public']);
329
+    }
330
+
331
+    protected function isShared() {
332
+        if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
333
+            return false;
334
+        }
335
+
336
+        return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
337
+    }
338
+
339
+    public function isSubscription() {
340
+        return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']);
341
+    }
342 342
 
343 343
 }
Please login to merge, or discard this patch.