Completed
Push — master ( fabaf0...9edd39 )
by Blizzz
22s
created
lib/private/Settings/Manager.php 1 patch
Indentation   +293 added lines, -293 removed lines patch added patch discarded remove patch
@@ -38,324 +38,324 @@
 block discarded – undo
38 38
 use OCP\Settings\ISection;
39 39
 
40 40
 class Manager implements IManager {
41
-	const TABLE_ADMIN_SETTINGS = 'admin_settings';
42
-	const TABLE_ADMIN_SECTIONS = 'admin_sections';
41
+    const TABLE_ADMIN_SETTINGS = 'admin_settings';
42
+    const TABLE_ADMIN_SECTIONS = 'admin_sections';
43 43
 
44
-	/** @var ILogger */
45
-	private $log;
46
-	/** @var IDBConnection */
47
-	private $dbc;
48
-	/** @var Mapper */
49
-	private $mapper;
50
-	/** @var IL10N */
51
-	private $l;
52
-	/** @var IConfig */
53
-	private $config;
54
-	/** @var EncryptionManager */
55
-	private $encryptionManager;
56
-	/** @var IUserManager */
57
-	private $userManager;
58
-	/** @var ILockingProvider */
59
-	private $lockingProvider;
60
-	/** @var IRequest */
61
-	private $request;
62
-	/** @var IURLGenerator */
63
-	private $url;
44
+    /** @var ILogger */
45
+    private $log;
46
+    /** @var IDBConnection */
47
+    private $dbc;
48
+    /** @var Mapper */
49
+    private $mapper;
50
+    /** @var IL10N */
51
+    private $l;
52
+    /** @var IConfig */
53
+    private $config;
54
+    /** @var EncryptionManager */
55
+    private $encryptionManager;
56
+    /** @var IUserManager */
57
+    private $userManager;
58
+    /** @var ILockingProvider */
59
+    private $lockingProvider;
60
+    /** @var IRequest */
61
+    private $request;
62
+    /** @var IURLGenerator */
63
+    private $url;
64 64
 
65
-	/**
66
-	 * @param ILogger $log
67
-	 * @param IDBConnection $dbc
68
-	 * @param IL10N $l
69
-	 * @param IConfig $config
70
-	 * @param EncryptionManager $encryptionManager
71
-	 * @param IUserManager $userManager
72
-	 * @param ILockingProvider $lockingProvider
73
-	 * @param IRequest $request
74
-	 * @param Mapper $mapper
75
-	 * @param IURLGenerator $url
76
-	 */
77
-	public function __construct(
78
-		ILogger $log,
79
-		IDBConnection $dbc,
80
-		IL10N $l,
81
-		IConfig $config,
82
-		EncryptionManager $encryptionManager,
83
-		IUserManager $userManager,
84
-		ILockingProvider $lockingProvider,
85
-		IRequest $request,
86
-		Mapper $mapper,
87
-		IURLGenerator $url
88
-	) {
89
-		$this->log = $log;
90
-		$this->dbc = $dbc;
91
-		$this->mapper = $mapper;
92
-		$this->l = $l;
93
-		$this->config = $config;
94
-		$this->encryptionManager = $encryptionManager;
95
-		$this->userManager = $userManager;
96
-		$this->lockingProvider = $lockingProvider;
97
-		$this->request = $request;
98
-		$this->url = $url;
99
-	}
65
+    /**
66
+     * @param ILogger $log
67
+     * @param IDBConnection $dbc
68
+     * @param IL10N $l
69
+     * @param IConfig $config
70
+     * @param EncryptionManager $encryptionManager
71
+     * @param IUserManager $userManager
72
+     * @param ILockingProvider $lockingProvider
73
+     * @param IRequest $request
74
+     * @param Mapper $mapper
75
+     * @param IURLGenerator $url
76
+     */
77
+    public function __construct(
78
+        ILogger $log,
79
+        IDBConnection $dbc,
80
+        IL10N $l,
81
+        IConfig $config,
82
+        EncryptionManager $encryptionManager,
83
+        IUserManager $userManager,
84
+        ILockingProvider $lockingProvider,
85
+        IRequest $request,
86
+        Mapper $mapper,
87
+        IURLGenerator $url
88
+    ) {
89
+        $this->log = $log;
90
+        $this->dbc = $dbc;
91
+        $this->mapper = $mapper;
92
+        $this->l = $l;
93
+        $this->config = $config;
94
+        $this->encryptionManager = $encryptionManager;
95
+        $this->userManager = $userManager;
96
+        $this->lockingProvider = $lockingProvider;
97
+        $this->request = $request;
98
+        $this->url = $url;
99
+    }
100 100
 
101
-	/**
102
-	 * @inheritdoc
103
-	 */
104
-	public function setupSettings(array $settings) {
105
-		if (isset($settings[IManager::KEY_ADMIN_SECTION])) {
106
-			$this->setupAdminSection($settings[IManager::KEY_ADMIN_SECTION]);
107
-		}
108
-		if (isset($settings[IManager::KEY_ADMIN_SETTINGS])) {
109
-			$this->setupAdminSettings($settings[IManager::KEY_ADMIN_SETTINGS]);
110
-		}
111
-	}
101
+    /**
102
+     * @inheritdoc
103
+     */
104
+    public function setupSettings(array $settings) {
105
+        if (isset($settings[IManager::KEY_ADMIN_SECTION])) {
106
+            $this->setupAdminSection($settings[IManager::KEY_ADMIN_SECTION]);
107
+        }
108
+        if (isset($settings[IManager::KEY_ADMIN_SETTINGS])) {
109
+            $this->setupAdminSettings($settings[IManager::KEY_ADMIN_SETTINGS]);
110
+        }
111
+    }
112 112
 
113
-	/**
114
-	 * attempts to remove an apps section and/or settings entry. A listener is
115
-	 * added centrally making sure that this method is called ones an app was
116
-	 * disabled.
117
-	 *
118
-	 * @param string $appId
119
-	 * @since 9.1.0
120
-	 */
121
-	public function onAppDisabled($appId) {
122
-		$appInfo = \OC_App::getAppInfo($appId); // hello static legacy
113
+    /**
114
+     * attempts to remove an apps section and/or settings entry. A listener is
115
+     * added centrally making sure that this method is called ones an app was
116
+     * disabled.
117
+     *
118
+     * @param string $appId
119
+     * @since 9.1.0
120
+     */
121
+    public function onAppDisabled($appId) {
122
+        $appInfo = \OC_App::getAppInfo($appId); // hello static legacy
123 123
 
124
-		if (isset($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) {
125
-			$this->mapper->remove(self::TABLE_ADMIN_SECTIONS, trim($appInfo['settings'][IManager::KEY_ADMIN_SECTION], '\\'));
126
-		}
127
-		if (isset($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) {
128
-			$this->mapper->remove(self::TABLE_ADMIN_SETTINGS, trim($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS], '\\'));
129
-		}
130
-	}
124
+        if (isset($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) {
125
+            $this->mapper->remove(self::TABLE_ADMIN_SECTIONS, trim($appInfo['settings'][IManager::KEY_ADMIN_SECTION], '\\'));
126
+        }
127
+        if (isset($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) {
128
+            $this->mapper->remove(self::TABLE_ADMIN_SETTINGS, trim($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS], '\\'));
129
+        }
130
+    }
131 131
 
132
-	public function checkForOrphanedClassNames() {
133
-		$tables = [self::TABLE_ADMIN_SECTIONS, self::TABLE_ADMIN_SETTINGS];
134
-		foreach ($tables as $table) {
135
-			$classes = $this->mapper->getClasses($table);
136
-			foreach ($classes as $className) {
137
-				try {
138
-					\OC::$server->query($className);
139
-				} catch (QueryException $e) {
140
-					$this->mapper->remove($table, $className);
141
-				}
142
-			}
143
-		}
144
-	}
132
+    public function checkForOrphanedClassNames() {
133
+        $tables = [self::TABLE_ADMIN_SECTIONS, self::TABLE_ADMIN_SETTINGS];
134
+        foreach ($tables as $table) {
135
+            $classes = $this->mapper->getClasses($table);
136
+            foreach ($classes as $className) {
137
+                try {
138
+                    \OC::$server->query($className);
139
+                } catch (QueryException $e) {
140
+                    $this->mapper->remove($table, $className);
141
+                }
142
+            }
143
+        }
144
+    }
145 145
 
146
-	/**
147
-	 * @param string $sectionClassName
148
-	 */
149
-	private function setupAdminSection($sectionClassName) {
150
-		if (!class_exists($sectionClassName)) {
151
-			$this->log->debug('Could not find admin section class ' . $sectionClassName);
152
-			return;
153
-		}
154
-		try {
155
-			$section = $this->query($sectionClassName);
156
-		} catch (QueryException $e) {
157
-			// cancel
158
-			return;
159
-		}
146
+    /**
147
+     * @param string $sectionClassName
148
+     */
149
+    private function setupAdminSection($sectionClassName) {
150
+        if (!class_exists($sectionClassName)) {
151
+            $this->log->debug('Could not find admin section class ' . $sectionClassName);
152
+            return;
153
+        }
154
+        try {
155
+            $section = $this->query($sectionClassName);
156
+        } catch (QueryException $e) {
157
+            // cancel
158
+            return;
159
+        }
160 160
 
161
-		if (!$section instanceof ISection) {
162
-			$this->log->error(
163
-				'Admin section instance must implement \OCP\ISection. Invalid class: {class}',
164
-				['class' => $sectionClassName]
165
-			);
166
-			return;
167
-		}
168
-		if (!$this->hasAdminSection(get_class($section))) {
169
-			$this->addAdminSection($section);
170
-		} else {
171
-			$this->updateAdminSection($section);
172
-		}
173
-	}
161
+        if (!$section instanceof ISection) {
162
+            $this->log->error(
163
+                'Admin section instance must implement \OCP\ISection. Invalid class: {class}',
164
+                ['class' => $sectionClassName]
165
+            );
166
+            return;
167
+        }
168
+        if (!$this->hasAdminSection(get_class($section))) {
169
+            $this->addAdminSection($section);
170
+        } else {
171
+            $this->updateAdminSection($section);
172
+        }
173
+    }
174 174
 
175
-	private function addAdminSection(ISection $section) {
176
-		$this->mapper->add(self::TABLE_ADMIN_SECTIONS, [
177
-			'id' => $section->getID(),
178
-			'class' => get_class($section),
179
-			'priority' => $section->getPriority(),
180
-		]);
181
-	}
175
+    private function addAdminSection(ISection $section) {
176
+        $this->mapper->add(self::TABLE_ADMIN_SECTIONS, [
177
+            'id' => $section->getID(),
178
+            'class' => get_class($section),
179
+            'priority' => $section->getPriority(),
180
+        ]);
181
+    }
182 182
 
183
-	private function addAdminSettings(ISettings $settings) {
184
-		$this->mapper->add(self::TABLE_ADMIN_SETTINGS, [
185
-			'class' => get_class($settings),
186
-			'section' => $settings->getSection(),
187
-			'priority' => $settings->getPriority(),
188
-		]);
189
-	}
183
+    private function addAdminSettings(ISettings $settings) {
184
+        $this->mapper->add(self::TABLE_ADMIN_SETTINGS, [
185
+            'class' => get_class($settings),
186
+            'section' => $settings->getSection(),
187
+            'priority' => $settings->getPriority(),
188
+        ]);
189
+    }
190 190
 
191
-	private function updateAdminSettings(ISettings $settings) {
192
-		$this->mapper->update(
193
-			self::TABLE_ADMIN_SETTINGS,
194
-			'class',
195
-			get_class($settings),
196
-			[
197
-				'section' => $settings->getSection(),
198
-				'priority' => $settings->getPriority(),
199
-			]
200
-		);
201
-	}
191
+    private function updateAdminSettings(ISettings $settings) {
192
+        $this->mapper->update(
193
+            self::TABLE_ADMIN_SETTINGS,
194
+            'class',
195
+            get_class($settings),
196
+            [
197
+                'section' => $settings->getSection(),
198
+                'priority' => $settings->getPriority(),
199
+            ]
200
+        );
201
+    }
202 202
 
203
-	private function updateAdminSection(ISection $section) {
204
-		$this->mapper->update(
205
-			self::TABLE_ADMIN_SECTIONS,
206
-			'class',
207
-			get_class($section),
208
-			[
209
-				'id' => $section->getID(),
210
-				'priority' => $section->getPriority(),
211
-			]
212
-		);
213
-	}
203
+    private function updateAdminSection(ISection $section) {
204
+        $this->mapper->update(
205
+            self::TABLE_ADMIN_SECTIONS,
206
+            'class',
207
+            get_class($section),
208
+            [
209
+                'id' => $section->getID(),
210
+                'priority' => $section->getPriority(),
211
+            ]
212
+        );
213
+    }
214 214
 
215
-	/**
216
-	 * @param string $className
217
-	 * @return bool
218
-	 */
219
-	private function hasAdminSection($className) {
220
-		return $this->mapper->has(self::TABLE_ADMIN_SECTIONS, $className);
221
-	}
215
+    /**
216
+     * @param string $className
217
+     * @return bool
218
+     */
219
+    private function hasAdminSection($className) {
220
+        return $this->mapper->has(self::TABLE_ADMIN_SECTIONS, $className);
221
+    }
222 222
 
223
-	/**
224
-	 * @param string $className
225
-	 * @return bool
226
-	 */
227
-	private function hasAdminSettings($className) {
228
-		return $this->mapper->has(self::TABLE_ADMIN_SETTINGS, $className);
229
-	}
223
+    /**
224
+     * @param string $className
225
+     * @return bool
226
+     */
227
+    private function hasAdminSettings($className) {
228
+        return $this->mapper->has(self::TABLE_ADMIN_SETTINGS, $className);
229
+    }
230 230
 
231
-	private function setupAdminSettings($settingsClassName) {
232
-		if (!class_exists($settingsClassName)) {
233
-			$this->log->debug('Could not find admin section class ' . $settingsClassName);
234
-			return;
235
-		}
231
+    private function setupAdminSettings($settingsClassName) {
232
+        if (!class_exists($settingsClassName)) {
233
+            $this->log->debug('Could not find admin section class ' . $settingsClassName);
234
+            return;
235
+        }
236 236
 
237
-		try {
238
-			/** @var ISettings $settings */
239
-			$settings = $this->query($settingsClassName);
240
-		} catch (QueryException $e) {
241
-			// cancel
242
-			return;
243
-		}
237
+        try {
238
+            /** @var ISettings $settings */
239
+            $settings = $this->query($settingsClassName);
240
+        } catch (QueryException $e) {
241
+            // cancel
242
+            return;
243
+        }
244 244
 
245
-		if (!$settings instanceof ISettings) {
246
-			$this->log->error(
247
-				'Admin section instance must implement \OCP\Settings\ISection. Invalid class: {class}',
248
-				['class' => $settingsClassName]
249
-			);
250
-			return;
251
-		}
252
-		if (!$this->hasAdminSettings(get_class($settings))) {
253
-			$this->addAdminSettings($settings);
254
-		} else {
255
-			$this->updateAdminSettings($settings);
256
-		}
257
-	}
245
+        if (!$settings instanceof ISettings) {
246
+            $this->log->error(
247
+                'Admin section instance must implement \OCP\Settings\ISection. Invalid class: {class}',
248
+                ['class' => $settingsClassName]
249
+            );
250
+            return;
251
+        }
252
+        if (!$this->hasAdminSettings(get_class($settings))) {
253
+            $this->addAdminSettings($settings);
254
+        } else {
255
+            $this->updateAdminSettings($settings);
256
+        }
257
+    }
258 258
 
259
-	private function query($className) {
260
-		try {
261
-			return \OC::$server->query($className);
262
-		} catch (QueryException $e) {
263
-			$this->log->logException($e);
264
-			throw $e;
265
-		}
266
-	}
259
+    private function query($className) {
260
+        try {
261
+            return \OC::$server->query($className);
262
+        } catch (QueryException $e) {
263
+            $this->log->logException($e);
264
+            throw $e;
265
+        }
266
+    }
267 267
 
268
-	/**
269
-	 * @inheritdoc
270
-	 */
271
-	public function getAdminSections() {
272
-		// built-in sections
273
-		$sections = [
274
-			0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))],
275
-			5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))],
276
-			10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
277
-			45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
278
-			98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
279
-			99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))],
280
-		];
268
+    /**
269
+     * @inheritdoc
270
+     */
271
+    public function getAdminSections() {
272
+        // built-in sections
273
+        $sections = [
274
+            0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))],
275
+            5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))],
276
+            10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
277
+            45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
278
+            98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
279
+            99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))],
280
+        ];
281 281
 
282
-		$rows = $this->mapper->getAdminSectionsFromDB();
282
+        $rows = $this->mapper->getAdminSectionsFromDB();
283 283
 
284
-		foreach ($rows as $row) {
285
-			if (!isset($sections[$row['priority']])) {
286
-				$sections[$row['priority']] = [];
287
-			}
288
-			try {
289
-				$sections[$row['priority']][] = $this->query($row['class']);
290
-			} catch (QueryException $e) {
291
-				// skip
292
-			}
293
-		}
284
+        foreach ($rows as $row) {
285
+            if (!isset($sections[$row['priority']])) {
286
+                $sections[$row['priority']] = [];
287
+            }
288
+            try {
289
+                $sections[$row['priority']][] = $this->query($row['class']);
290
+            } catch (QueryException $e) {
291
+                // skip
292
+            }
293
+        }
294 294
 
295
-		ksort($sections);
295
+        ksort($sections);
296 296
 
297
-		return $sections;
298
-	}
297
+        return $sections;
298
+    }
299 299
 
300
-	/**
301
-	 * @param string $section
302
-	 * @return ISection[]
303
-	 */
304
-	private function getBuiltInAdminSettings($section) {
305
-		$forms = [];
306
-		try {
307
-			if ($section === 'server') {
308
-				/** @var ISettings $form */
309
-				$form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l);
310
-				$forms[$form->getPriority()] = [$form];
311
-				$form = new Admin\ServerDevNotice();
312
-				$forms[$form->getPriority()] = [$form];
313
-			}
314
-			if ($section === 'encryption') {
315
-				/** @var ISettings $form */
316
-				$form = new Admin\Encryption($this->encryptionManager, $this->userManager);
317
-				$forms[$form->getPriority()] = [$form];
318
-			}
319
-			if ($section === 'sharing') {
320
-				/** @var ISettings $form */
321
-				$form = new Admin\Sharing($this->config);
322
-				$forms[$form->getPriority()] = [$form];
323
-			}
324
-			if ($section === 'additional') {
325
-				/** @var ISettings $form */
326
-				$form = new Admin\Additional($this->config);
327
-				$forms[$form->getPriority()] = [$form];
328
-			}
329
-			if ($section === 'tips-tricks') {
330
-				/** @var ISettings $form */
331
-				$form = new Admin\TipsTricks($this->config);
332
-				$forms[$form->getPriority()] = [$form];
333
-			}
334
-		} catch (QueryException $e) {
335
-			// skip
336
-		}
337
-		return $forms;
338
-	}
300
+    /**
301
+     * @param string $section
302
+     * @return ISection[]
303
+     */
304
+    private function getBuiltInAdminSettings($section) {
305
+        $forms = [];
306
+        try {
307
+            if ($section === 'server') {
308
+                /** @var ISettings $form */
309
+                $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l);
310
+                $forms[$form->getPriority()] = [$form];
311
+                $form = new Admin\ServerDevNotice();
312
+                $forms[$form->getPriority()] = [$form];
313
+            }
314
+            if ($section === 'encryption') {
315
+                /** @var ISettings $form */
316
+                $form = new Admin\Encryption($this->encryptionManager, $this->userManager);
317
+                $forms[$form->getPriority()] = [$form];
318
+            }
319
+            if ($section === 'sharing') {
320
+                /** @var ISettings $form */
321
+                $form = new Admin\Sharing($this->config);
322
+                $forms[$form->getPriority()] = [$form];
323
+            }
324
+            if ($section === 'additional') {
325
+                /** @var ISettings $form */
326
+                $form = new Admin\Additional($this->config);
327
+                $forms[$form->getPriority()] = [$form];
328
+            }
329
+            if ($section === 'tips-tricks') {
330
+                /** @var ISettings $form */
331
+                $form = new Admin\TipsTricks($this->config);
332
+                $forms[$form->getPriority()] = [$form];
333
+            }
334
+        } catch (QueryException $e) {
335
+            // skip
336
+        }
337
+        return $forms;
338
+    }
339 339
 
340
-	/**
341
-	 * @inheritdoc
342
-	 */
343
-	public function getAdminSettings($section) {
344
-		$settings = $this->getBuiltInAdminSettings($section);
345
-		$dbRows = $this->mapper->getAdminSettingsFromDB($section);
340
+    /**
341
+     * @inheritdoc
342
+     */
343
+    public function getAdminSettings($section) {
344
+        $settings = $this->getBuiltInAdminSettings($section);
345
+        $dbRows = $this->mapper->getAdminSettingsFromDB($section);
346 346
 
347
-		foreach ($dbRows as $row) {
348
-			if (!isset($settings[$row['priority']])) {
349
-				$settings[$row['priority']] = [];
350
-			}
351
-			try {
352
-				$settings[$row['priority']][] = $this->query($row['class']);
353
-			} catch (QueryException $e) {
354
-				// skip
355
-			}
356
-		}
347
+        foreach ($dbRows as $row) {
348
+            if (!isset($settings[$row['priority']])) {
349
+                $settings[$row['priority']] = [];
350
+            }
351
+            try {
352
+                $settings[$row['priority']][] = $this->query($row['class']);
353
+            } catch (QueryException $e) {
354
+                // skip
355
+            }
356
+        }
357 357
 
358
-		ksort($settings);
359
-		return $settings;
360
-	}
358
+        ksort($settings);
359
+        return $settings;
360
+    }
361 361
 }
Please login to merge, or discard this patch.