Completed
Pull Request — master (#6759)
by Joas
51:11 queued 36:54
created
lib/private/Settings/Manager.php 1 patch
Indentation   +489 added lines, -489 removed lines patch added patch discarded remove patch
@@ -42,493 +42,493 @@
 block discarded – undo
42 42
 use OCP\Settings\ISection;
43 43
 
44 44
 class Manager implements IManager {
45
-	/** @var ILogger */
46
-	private $log;
47
-	/** @var IDBConnection */
48
-	private $dbc;
49
-	/** @var Mapper */
50
-	private $mapper;
51
-	/** @var IL10N */
52
-	private $l;
53
-	/** @var IConfig */
54
-	private $config;
55
-	/** @var EncryptionManager */
56
-	private $encryptionManager;
57
-	/** @var IUserManager */
58
-	private $userManager;
59
-	/** @var ILockingProvider */
60
-	private $lockingProvider;
61
-	/** @var IRequest */
62
-	private $request;
63
-	/** @var IURLGenerator */
64
-	private $url;
65
-	/** @var AccountManager */
66
-	private $accountManager;
67
-	/** @var IGroupManager */
68
-	private $groupManager;
69
-	/** @var IFactory */
70
-	private $l10nFactory;
71
-	/** @var \OC_Defaults */
72
-	private $defaults;
73
-	/** @var IAppManager */
74
-	private $appManager;
75
-
76
-	/**
77
-	 * @param ILogger $log
78
-	 * @param IDBConnection $dbc
79
-	 * @param IL10N $l
80
-	 * @param IConfig $config
81
-	 * @param EncryptionManager $encryptionManager
82
-	 * @param IUserManager $userManager
83
-	 * @param ILockingProvider $lockingProvider
84
-	 * @param IRequest $request
85
-	 * @param Mapper $mapper
86
-	 * @param IURLGenerator $url
87
-	 * @param AccountManager $accountManager
88
-	 * @param IGroupManager $groupManager
89
-	 * @param IFactory $l10nFactory
90
-	 * @param \OC_Defaults $defaults
91
-	 */
92
-	public function __construct(
93
-		ILogger $log,
94
-		IDBConnection $dbc,
95
-		IL10N $l,
96
-		IConfig $config,
97
-		EncryptionManager $encryptionManager,
98
-		IUserManager $userManager,
99
-		ILockingProvider $lockingProvider,
100
-		IRequest $request,
101
-		Mapper $mapper,
102
-		IURLGenerator $url,
103
-		AccountManager $accountManager,
104
-		IGroupManager $groupManager,
105
-		IFactory $l10nFactory,
106
-		\OC_Defaults $defaults,
107
-		IAppManager $appManager
108
-	) {
109
-		$this->log = $log;
110
-		$this->dbc = $dbc;
111
-		$this->mapper = $mapper;
112
-		$this->l = $l;
113
-		$this->config = $config;
114
-		$this->encryptionManager = $encryptionManager;
115
-		$this->userManager = $userManager;
116
-		$this->lockingProvider = $lockingProvider;
117
-		$this->request = $request;
118
-		$this->url = $url;
119
-		$this->accountManager = $accountManager;
120
-		$this->groupManager = $groupManager;
121
-		$this->l10nFactory = $l10nFactory;
122
-		$this->defaults = $defaults;
123
-		$this->appManager = $appManager;
124
-	}
125
-
126
-	/**
127
-	 * @inheritdoc
128
-	 */
129
-	public function setupSettings(array $settings) {
130
-		if (!empty($settings[IManager::KEY_ADMIN_SECTION])) {
131
-			foreach ($settings[IManager::KEY_ADMIN_SECTION] as $className) {
132
-				$this->setupSectionEntry($className, 'admin');
133
-			}
134
-		}
135
-		if (!empty($settings[IManager::KEY_ADMIN_SETTINGS])) {
136
-			foreach ($settings[IManager::KEY_ADMIN_SETTINGS] as $className) {
137
-				$this->setupSettingsEntry($className, 'admin');
138
-			}
139
-		}
140
-
141
-		if (!empty($settings[IManager::KEY_PERSONAL_SECTION])) {
142
-			foreach ($settings[IManager::KEY_PERSONAL_SECTION] as $className) {
143
-				$this->setupSectionEntry($className, 'personal');
144
-			}
145
-		}
146
-		if (!empty($settings[IManager::KEY_PERSONAL_SETTINGS])) {
147
-			foreach ($settings[IManager::KEY_PERSONAL_SETTINGS] as $className) {
148
-				$this->setupSettingsEntry($className, 'personal');
149
-			}
150
-		}
151
-	}
152
-
153
-	/**
154
-	 * attempts to remove an apps section and/or settings entry. A listener is
155
-	 * added centrally making sure that this method is called ones an app was
156
-	 * disabled.
157
-	 *
158
-	 * @param string $appId
159
-	 * @since 9.1.0
160
-	 */
161
-	public function onAppDisabled($appId) {
162
-		$appInfo = \OC_App::getAppInfo($appId); // hello static legacy
163
-
164
-		if (isset($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) {
165
-			$this->mapper->remove(Mapper::TABLE_ADMIN_SECTIONS, trim($appInfo['settings'][IManager::KEY_ADMIN_SECTION], '\\'));
166
-		}
167
-		if (isset($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) {
168
-			$this->mapper->remove(Mapper::TABLE_ADMIN_SETTINGS, trim($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS], '\\'));
169
-		}
170
-
171
-		if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SECTION])) {
172
-			$this->mapper->remove(Mapper::TABLE_PERSONAL_SECTIONS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SECTION], '\\'));
173
-		}
174
-		if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS])) {
175
-			$this->mapper->remove(Mapper::TABLE_PERSONAL_SETTINGS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS], '\\'));
176
-		}
177
-	}
178
-
179
-	public function checkForOrphanedClassNames() {
180
-		$tables = [Mapper::TABLE_ADMIN_SECTIONS, Mapper::TABLE_ADMIN_SETTINGS, Mapper::TABLE_PERSONAL_SECTIONS, Mapper::TABLE_PERSONAL_SETTINGS];
181
-		foreach ($tables as $table) {
182
-			$classes = $this->mapper->getClasses($table);
183
-			foreach ($classes as $className) {
184
-				try {
185
-					\OC::$server->query($className);
186
-				} catch (QueryException $e) {
187
-					$this->mapper->remove($table, $className);
188
-				}
189
-			}
190
-		}
191
-	}
192
-
193
-	/**
194
-	 * @param string $sectionClassName
195
-	 * @param string $type either 'admin' or 'personal'
196
-	 */
197
-	private function setupSectionEntry($sectionClassName, $type) {
198
-		if (!class_exists($sectionClassName)) {
199
-			$this->log->debug('Could not find ' . ucfirst($type) . ' section class ' . $sectionClassName);
200
-			return;
201
-		}
202
-		try {
203
-			$section = $this->query($sectionClassName);
204
-		} catch (QueryException $e) {
205
-			// cancel
206
-			return;
207
-		}
208
-
209
-		if (!$section instanceof ISection) {
210
-			$this->log->error(
211
-				ucfirst($type) .' section instance must implement \OCP\ISection. Invalid class: {class}',
212
-				['class' => $sectionClassName]
213
-			);
214
-			return;
215
-		}
216
-		$table = $this->getSectionTableForType($type);
217
-		if(!$this->hasSection(get_class($section), $table)) {
218
-			$this->addSection($section, $table);
219
-		} else {
220
-			$this->updateSection($section, $table);
221
-		}
222
-	}
223
-
224
-	private function addSection(ISection $section, $table) {
225
-		$this->mapper->add($table, [
226
-			'id' => $section->getID(),
227
-			'class' => get_class($section),
228
-			'priority' => $section->getPriority(),
229
-		]);
230
-	}
231
-
232
-	private function addSettings(ISettings $settings, $table) {
233
-		$this->mapper->add($table, [
234
-			'class' => get_class($settings),
235
-			'section' => $settings->getSection(),
236
-			'priority' => $settings->getPriority(),
237
-		]);
238
-	}
239
-
240
-	private function updateSettings(ISettings $settings, $table) {
241
-		$this->mapper->update(
242
-			$table,
243
-			'class',
244
-			get_class($settings),
245
-			[
246
-				'section' => $settings->getSection(),
247
-				'priority' => $settings->getPriority(),
248
-			]
249
-		);
250
-	}
251
-
252
-	private function updateSection(ISection $section, $table) {
253
-		$this->mapper->update(
254
-			$table,
255
-			'class',
256
-			get_class($section),
257
-			[
258
-				'id' => $section->getID(),
259
-				'priority' => $section->getPriority(),
260
-			]
261
-		);
262
-	}
263
-
264
-	/**
265
-	 * @param string $className
266
-	 * @param string $table
267
-	 * @return bool
268
-	 */
269
-	private function hasSection($className, $table) {
270
-		return $this->mapper->has($table, $className);
271
-	}
272
-
273
-	/**
274
-	 * @param string $className
275
-	 * @return bool
276
-	 */
277
-	private function hasSettings($className, $table) {
278
-		return $this->mapper->has($table, $className);
279
-	}
280
-
281
-	private function setupSettingsEntry($settingsClassName, $type) {
282
-		if (!class_exists($settingsClassName)) {
283
-			$this->log->debug('Could not find ' . $type . ' section class ' . $settingsClassName);
284
-			return;
285
-		}
286
-
287
-		try {
288
-			/** @var ISettings $settings */
289
-			$settings = $this->query($settingsClassName);
290
-		} catch (QueryException $e) {
291
-			// cancel
292
-			return;
293
-		}
294
-
295
-		if (!$settings instanceof ISettings) {
296
-			$this->log->error(
297
-				ucfirst($type) . ' section instance must implement \OCP\Settings\ISettings. Invalid class: {class}',
298
-				['class' => $settingsClassName]
299
-			);
300
-			return;
301
-		}
302
-		$table = $this->getSettingsTableForType($type);
303
-		if (!$this->hasSettings(get_class($settings), $table)) {
304
-			$this->addSettings($settings, $table);
305
-		} else {
306
-			$this->updateSettings($settings, $table);
307
-		}
308
-	}
309
-
310
-	private function getSectionTableForType($type) {
311
-		if($type === 'admin') {
312
-			return Mapper::TABLE_ADMIN_SECTIONS;
313
-		} else if($type === 'personal') {
314
-			return Mapper::TABLE_PERSONAL_SECTIONS;
315
-		}
316
-		throw new \InvalidArgumentException('"admin" or "personal" expected');
317
-	}
318
-
319
-	private function getSettingsTableForType($type) {
320
-		if($type === 'admin') {
321
-			return Mapper::TABLE_ADMIN_SETTINGS;
322
-		} else if($type === 'personal') {
323
-			return Mapper::TABLE_PERSONAL_SETTINGS;
324
-		}
325
-		throw new \InvalidArgumentException('"admin" or "personal" expected');
326
-	}
327
-
328
-	private function query($className) {
329
-		try {
330
-			return \OC::$server->query($className);
331
-		} catch (QueryException $e) {
332
-			$this->log->logException($e);
333
-			throw $e;
334
-		}
335
-	}
336
-
337
-	/**
338
-	 * @inheritdoc
339
-	 */
340
-	public function getAdminSections() {
341
-		// built-in sections
342
-		$sections = [
343
-			0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))],
344
-			5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))],
345
-			10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
346
-			45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
347
-			98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
348
-			99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))],
349
-		];
350
-
351
-		$rows = $this->mapper->getAdminSectionsFromDB();
352
-
353
-		foreach ($rows as $row) {
354
-			if (!isset($sections[$row['priority']])) {
355
-				$sections[$row['priority']] = [];
356
-			}
357
-			try {
358
-				$sections[$row['priority']][] = $this->query($row['class']);
359
-			} catch (QueryException $e) {
360
-				// skip
361
-			}
362
-		}
363
-
364
-		ksort($sections);
365
-
366
-		return $sections;
367
-	}
368
-
369
-	/**
370
-	 * @param string $section
371
-	 * @return ISection[]
372
-	 */
373
-	private function getBuiltInAdminSettings($section) {
374
-		$forms = [];
375
-		try {
376
-			if ($section === 'server') {
377
-				/** @var ISettings $form */
378
-				$form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l);
379
-				$forms[$form->getPriority()] = [$form];
380
-				$form = new Admin\ServerDevNotice();
381
-				$forms[$form->getPriority()] = [$form];
382
-			}
383
-			if ($section === 'encryption') {
384
-				/** @var ISettings $form */
385
-				$form = new Admin\Encryption($this->encryptionManager, $this->userManager);
386
-				$forms[$form->getPriority()] = [$form];
387
-			}
388
-			if ($section === 'sharing') {
389
-				/** @var ISettings $form */
390
-				$form = new Admin\Sharing($this->config);
391
-				$forms[$form->getPriority()] = [$form];
392
-			}
393
-			if ($section === 'additional') {
394
-				/** @var ISettings $form */
395
-				$form = new Admin\Additional($this->config);
396
-				$forms[$form->getPriority()] = [$form];
397
-			}
398
-			if ($section === 'tips-tricks') {
399
-				/** @var ISettings $form */
400
-				$form = new Admin\TipsTricks($this->config);
401
-				$forms[$form->getPriority()] = [$form];
402
-			}
403
-		} catch (QueryException $e) {
404
-			// skip
405
-		}
406
-		return $forms;
407
-	}
408
-
409
-	/**
410
-	 * @param string $section
411
-	 * @return ISection[]
412
-	 */
413
-	private function getBuiltInPersonalSettings($section) {
414
-		$forms = [];
415
-		try {
416
-			if ($section === 'personal-info') {
417
-				/** @var ISettings $form */
418
-				$form = new Personal\PersonalInfo(
419
-					$this->config,
420
-					$this->userManager,
421
-					$this->groupManager,
422
-					$this->accountManager,
423
-					$this->appManager,
424
-					$this->l10nFactory,
425
-					$this->l
426
-				);
427
-				$forms[$form->getPriority()] = [$form];
428
-			}
429
-			if($section === 'security') {
430
-				/** @var ISettings $form */
431
-				$form = new Personal\Security();
432
-				$forms[$form->getPriority()] = [$form];
433
-			}
434
-			if ($section === 'additional') {
435
-				/** @var ISettings $form */
436
-				$form = new Personal\Additional($this->config);
437
-				$forms[$form->getPriority()] = [$form];
438
-			}
439
-		} catch (QueryException $e) {
440
-			// skip
441
-		}
442
-		return $forms;
443
-	}
444
-
445
-	/**
446
-	 * @inheritdoc
447
-	 */
448
-	public function getAdminSettings($section) {
449
-		$settings = $this->getBuiltInAdminSettings($section);
450
-		$dbRows = $this->mapper->getAdminSettingsFromDB($section);
451
-
452
-		foreach ($dbRows as $row) {
453
-			if (!isset($settings[$row['priority']])) {
454
-				$settings[$row['priority']] = [];
455
-			}
456
-			try {
457
-				$settings[$row['priority']][] = $this->query($row['class']);
458
-			} catch (QueryException $e) {
459
-				// skip
460
-			}
461
-		}
462
-
463
-		ksort($settings);
464
-		return $settings;
465
-	}
466
-
467
-	/**
468
-	 * @inheritdoc
469
-	 */
470
-	public function getPersonalSections() {
471
-		$sections = [
472
-			0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))],
473
-			5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))],
474
-			15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))],
475
-		];
476
-
477
-		$legacyForms = \OC_App::getForms('personal');
478
-		if(count($legacyForms) > 0 && $this->hasLegacyPersonalSettingsToRender($legacyForms)) {
479
-			$sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))];
480
-		}
481
-
482
-		$rows = $this->mapper->getPersonalSectionsFromDB();
483
-
484
-		foreach ($rows as $row) {
485
-			if (!isset($sections[$row['priority']])) {
486
-				$sections[$row['priority']] = [];
487
-			}
488
-			try {
489
-				$sections[$row['priority']][] = $this->query($row['class']);
490
-			} catch (QueryException $e) {
491
-				// skip
492
-			}
493
-		}
494
-
495
-		ksort($sections);
496
-
497
-		return $sections;
498
-	}
499
-
500
-	/**
501
-	 * @param $forms
502
-	 * @return bool
503
-	 */
504
-	private function hasLegacyPersonalSettingsToRender($forms) {
505
-		foreach ($forms as $form) {
506
-			if(trim($form) !== '') {
507
-				return true;
508
-			}
509
-		}
510
-		return false;
511
-	}
512
-
513
-	/**
514
-	 * @inheritdoc
515
-	 */
516
-	public function getPersonalSettings($section) {
517
-		$settings = $this->getBuiltInPersonalSettings($section);
518
-		$dbRows = $this->mapper->getPersonalSettingsFromDB($section);
519
-
520
-		foreach ($dbRows as $row) {
521
-			if (!isset($settings[$row['priority']])) {
522
-				$settings[$row['priority']] = [];
523
-			}
524
-			try {
525
-				$settings[$row['priority']][] = $this->query($row['class']);
526
-			} catch (QueryException $e) {
527
-				// skip
528
-			}
529
-		}
530
-
531
-		ksort($settings);
532
-		return $settings;
533
-	}
45
+    /** @var ILogger */
46
+    private $log;
47
+    /** @var IDBConnection */
48
+    private $dbc;
49
+    /** @var Mapper */
50
+    private $mapper;
51
+    /** @var IL10N */
52
+    private $l;
53
+    /** @var IConfig */
54
+    private $config;
55
+    /** @var EncryptionManager */
56
+    private $encryptionManager;
57
+    /** @var IUserManager */
58
+    private $userManager;
59
+    /** @var ILockingProvider */
60
+    private $lockingProvider;
61
+    /** @var IRequest */
62
+    private $request;
63
+    /** @var IURLGenerator */
64
+    private $url;
65
+    /** @var AccountManager */
66
+    private $accountManager;
67
+    /** @var IGroupManager */
68
+    private $groupManager;
69
+    /** @var IFactory */
70
+    private $l10nFactory;
71
+    /** @var \OC_Defaults */
72
+    private $defaults;
73
+    /** @var IAppManager */
74
+    private $appManager;
75
+
76
+    /**
77
+     * @param ILogger $log
78
+     * @param IDBConnection $dbc
79
+     * @param IL10N $l
80
+     * @param IConfig $config
81
+     * @param EncryptionManager $encryptionManager
82
+     * @param IUserManager $userManager
83
+     * @param ILockingProvider $lockingProvider
84
+     * @param IRequest $request
85
+     * @param Mapper $mapper
86
+     * @param IURLGenerator $url
87
+     * @param AccountManager $accountManager
88
+     * @param IGroupManager $groupManager
89
+     * @param IFactory $l10nFactory
90
+     * @param \OC_Defaults $defaults
91
+     */
92
+    public function __construct(
93
+        ILogger $log,
94
+        IDBConnection $dbc,
95
+        IL10N $l,
96
+        IConfig $config,
97
+        EncryptionManager $encryptionManager,
98
+        IUserManager $userManager,
99
+        ILockingProvider $lockingProvider,
100
+        IRequest $request,
101
+        Mapper $mapper,
102
+        IURLGenerator $url,
103
+        AccountManager $accountManager,
104
+        IGroupManager $groupManager,
105
+        IFactory $l10nFactory,
106
+        \OC_Defaults $defaults,
107
+        IAppManager $appManager
108
+    ) {
109
+        $this->log = $log;
110
+        $this->dbc = $dbc;
111
+        $this->mapper = $mapper;
112
+        $this->l = $l;
113
+        $this->config = $config;
114
+        $this->encryptionManager = $encryptionManager;
115
+        $this->userManager = $userManager;
116
+        $this->lockingProvider = $lockingProvider;
117
+        $this->request = $request;
118
+        $this->url = $url;
119
+        $this->accountManager = $accountManager;
120
+        $this->groupManager = $groupManager;
121
+        $this->l10nFactory = $l10nFactory;
122
+        $this->defaults = $defaults;
123
+        $this->appManager = $appManager;
124
+    }
125
+
126
+    /**
127
+     * @inheritdoc
128
+     */
129
+    public function setupSettings(array $settings) {
130
+        if (!empty($settings[IManager::KEY_ADMIN_SECTION])) {
131
+            foreach ($settings[IManager::KEY_ADMIN_SECTION] as $className) {
132
+                $this->setupSectionEntry($className, 'admin');
133
+            }
134
+        }
135
+        if (!empty($settings[IManager::KEY_ADMIN_SETTINGS])) {
136
+            foreach ($settings[IManager::KEY_ADMIN_SETTINGS] as $className) {
137
+                $this->setupSettingsEntry($className, 'admin');
138
+            }
139
+        }
140
+
141
+        if (!empty($settings[IManager::KEY_PERSONAL_SECTION])) {
142
+            foreach ($settings[IManager::KEY_PERSONAL_SECTION] as $className) {
143
+                $this->setupSectionEntry($className, 'personal');
144
+            }
145
+        }
146
+        if (!empty($settings[IManager::KEY_PERSONAL_SETTINGS])) {
147
+            foreach ($settings[IManager::KEY_PERSONAL_SETTINGS] as $className) {
148
+                $this->setupSettingsEntry($className, 'personal');
149
+            }
150
+        }
151
+    }
152
+
153
+    /**
154
+     * attempts to remove an apps section and/or settings entry. A listener is
155
+     * added centrally making sure that this method is called ones an app was
156
+     * disabled.
157
+     *
158
+     * @param string $appId
159
+     * @since 9.1.0
160
+     */
161
+    public function onAppDisabled($appId) {
162
+        $appInfo = \OC_App::getAppInfo($appId); // hello static legacy
163
+
164
+        if (isset($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) {
165
+            $this->mapper->remove(Mapper::TABLE_ADMIN_SECTIONS, trim($appInfo['settings'][IManager::KEY_ADMIN_SECTION], '\\'));
166
+        }
167
+        if (isset($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) {
168
+            $this->mapper->remove(Mapper::TABLE_ADMIN_SETTINGS, trim($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS], '\\'));
169
+        }
170
+
171
+        if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SECTION])) {
172
+            $this->mapper->remove(Mapper::TABLE_PERSONAL_SECTIONS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SECTION], '\\'));
173
+        }
174
+        if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS])) {
175
+            $this->mapper->remove(Mapper::TABLE_PERSONAL_SETTINGS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS], '\\'));
176
+        }
177
+    }
178
+
179
+    public function checkForOrphanedClassNames() {
180
+        $tables = [Mapper::TABLE_ADMIN_SECTIONS, Mapper::TABLE_ADMIN_SETTINGS, Mapper::TABLE_PERSONAL_SECTIONS, Mapper::TABLE_PERSONAL_SETTINGS];
181
+        foreach ($tables as $table) {
182
+            $classes = $this->mapper->getClasses($table);
183
+            foreach ($classes as $className) {
184
+                try {
185
+                    \OC::$server->query($className);
186
+                } catch (QueryException $e) {
187
+                    $this->mapper->remove($table, $className);
188
+                }
189
+            }
190
+        }
191
+    }
192
+
193
+    /**
194
+     * @param string $sectionClassName
195
+     * @param string $type either 'admin' or 'personal'
196
+     */
197
+    private function setupSectionEntry($sectionClassName, $type) {
198
+        if (!class_exists($sectionClassName)) {
199
+            $this->log->debug('Could not find ' . ucfirst($type) . ' section class ' . $sectionClassName);
200
+            return;
201
+        }
202
+        try {
203
+            $section = $this->query($sectionClassName);
204
+        } catch (QueryException $e) {
205
+            // cancel
206
+            return;
207
+        }
208
+
209
+        if (!$section instanceof ISection) {
210
+            $this->log->error(
211
+                ucfirst($type) .' section instance must implement \OCP\ISection. Invalid class: {class}',
212
+                ['class' => $sectionClassName]
213
+            );
214
+            return;
215
+        }
216
+        $table = $this->getSectionTableForType($type);
217
+        if(!$this->hasSection(get_class($section), $table)) {
218
+            $this->addSection($section, $table);
219
+        } else {
220
+            $this->updateSection($section, $table);
221
+        }
222
+    }
223
+
224
+    private function addSection(ISection $section, $table) {
225
+        $this->mapper->add($table, [
226
+            'id' => $section->getID(),
227
+            'class' => get_class($section),
228
+            'priority' => $section->getPriority(),
229
+        ]);
230
+    }
231
+
232
+    private function addSettings(ISettings $settings, $table) {
233
+        $this->mapper->add($table, [
234
+            'class' => get_class($settings),
235
+            'section' => $settings->getSection(),
236
+            'priority' => $settings->getPriority(),
237
+        ]);
238
+    }
239
+
240
+    private function updateSettings(ISettings $settings, $table) {
241
+        $this->mapper->update(
242
+            $table,
243
+            'class',
244
+            get_class($settings),
245
+            [
246
+                'section' => $settings->getSection(),
247
+                'priority' => $settings->getPriority(),
248
+            ]
249
+        );
250
+    }
251
+
252
+    private function updateSection(ISection $section, $table) {
253
+        $this->mapper->update(
254
+            $table,
255
+            'class',
256
+            get_class($section),
257
+            [
258
+                'id' => $section->getID(),
259
+                'priority' => $section->getPriority(),
260
+            ]
261
+        );
262
+    }
263
+
264
+    /**
265
+     * @param string $className
266
+     * @param string $table
267
+     * @return bool
268
+     */
269
+    private function hasSection($className, $table) {
270
+        return $this->mapper->has($table, $className);
271
+    }
272
+
273
+    /**
274
+     * @param string $className
275
+     * @return bool
276
+     */
277
+    private function hasSettings($className, $table) {
278
+        return $this->mapper->has($table, $className);
279
+    }
280
+
281
+    private function setupSettingsEntry($settingsClassName, $type) {
282
+        if (!class_exists($settingsClassName)) {
283
+            $this->log->debug('Could not find ' . $type . ' section class ' . $settingsClassName);
284
+            return;
285
+        }
286
+
287
+        try {
288
+            /** @var ISettings $settings */
289
+            $settings = $this->query($settingsClassName);
290
+        } catch (QueryException $e) {
291
+            // cancel
292
+            return;
293
+        }
294
+
295
+        if (!$settings instanceof ISettings) {
296
+            $this->log->error(
297
+                ucfirst($type) . ' section instance must implement \OCP\Settings\ISettings. Invalid class: {class}',
298
+                ['class' => $settingsClassName]
299
+            );
300
+            return;
301
+        }
302
+        $table = $this->getSettingsTableForType($type);
303
+        if (!$this->hasSettings(get_class($settings), $table)) {
304
+            $this->addSettings($settings, $table);
305
+        } else {
306
+            $this->updateSettings($settings, $table);
307
+        }
308
+    }
309
+
310
+    private function getSectionTableForType($type) {
311
+        if($type === 'admin') {
312
+            return Mapper::TABLE_ADMIN_SECTIONS;
313
+        } else if($type === 'personal') {
314
+            return Mapper::TABLE_PERSONAL_SECTIONS;
315
+        }
316
+        throw new \InvalidArgumentException('"admin" or "personal" expected');
317
+    }
318
+
319
+    private function getSettingsTableForType($type) {
320
+        if($type === 'admin') {
321
+            return Mapper::TABLE_ADMIN_SETTINGS;
322
+        } else if($type === 'personal') {
323
+            return Mapper::TABLE_PERSONAL_SETTINGS;
324
+        }
325
+        throw new \InvalidArgumentException('"admin" or "personal" expected');
326
+    }
327
+
328
+    private function query($className) {
329
+        try {
330
+            return \OC::$server->query($className);
331
+        } catch (QueryException $e) {
332
+            $this->log->logException($e);
333
+            throw $e;
334
+        }
335
+    }
336
+
337
+    /**
338
+     * @inheritdoc
339
+     */
340
+    public function getAdminSections() {
341
+        // built-in sections
342
+        $sections = [
343
+            0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))],
344
+            5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))],
345
+            10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
346
+            45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
347
+            98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
348
+            99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))],
349
+        ];
350
+
351
+        $rows = $this->mapper->getAdminSectionsFromDB();
352
+
353
+        foreach ($rows as $row) {
354
+            if (!isset($sections[$row['priority']])) {
355
+                $sections[$row['priority']] = [];
356
+            }
357
+            try {
358
+                $sections[$row['priority']][] = $this->query($row['class']);
359
+            } catch (QueryException $e) {
360
+                // skip
361
+            }
362
+        }
363
+
364
+        ksort($sections);
365
+
366
+        return $sections;
367
+    }
368
+
369
+    /**
370
+     * @param string $section
371
+     * @return ISection[]
372
+     */
373
+    private function getBuiltInAdminSettings($section) {
374
+        $forms = [];
375
+        try {
376
+            if ($section === 'server') {
377
+                /** @var ISettings $form */
378
+                $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l);
379
+                $forms[$form->getPriority()] = [$form];
380
+                $form = new Admin\ServerDevNotice();
381
+                $forms[$form->getPriority()] = [$form];
382
+            }
383
+            if ($section === 'encryption') {
384
+                /** @var ISettings $form */
385
+                $form = new Admin\Encryption($this->encryptionManager, $this->userManager);
386
+                $forms[$form->getPriority()] = [$form];
387
+            }
388
+            if ($section === 'sharing') {
389
+                /** @var ISettings $form */
390
+                $form = new Admin\Sharing($this->config);
391
+                $forms[$form->getPriority()] = [$form];
392
+            }
393
+            if ($section === 'additional') {
394
+                /** @var ISettings $form */
395
+                $form = new Admin\Additional($this->config);
396
+                $forms[$form->getPriority()] = [$form];
397
+            }
398
+            if ($section === 'tips-tricks') {
399
+                /** @var ISettings $form */
400
+                $form = new Admin\TipsTricks($this->config);
401
+                $forms[$form->getPriority()] = [$form];
402
+            }
403
+        } catch (QueryException $e) {
404
+            // skip
405
+        }
406
+        return $forms;
407
+    }
408
+
409
+    /**
410
+     * @param string $section
411
+     * @return ISection[]
412
+     */
413
+    private function getBuiltInPersonalSettings($section) {
414
+        $forms = [];
415
+        try {
416
+            if ($section === 'personal-info') {
417
+                /** @var ISettings $form */
418
+                $form = new Personal\PersonalInfo(
419
+                    $this->config,
420
+                    $this->userManager,
421
+                    $this->groupManager,
422
+                    $this->accountManager,
423
+                    $this->appManager,
424
+                    $this->l10nFactory,
425
+                    $this->l
426
+                );
427
+                $forms[$form->getPriority()] = [$form];
428
+            }
429
+            if($section === 'security') {
430
+                /** @var ISettings $form */
431
+                $form = new Personal\Security();
432
+                $forms[$form->getPriority()] = [$form];
433
+            }
434
+            if ($section === 'additional') {
435
+                /** @var ISettings $form */
436
+                $form = new Personal\Additional($this->config);
437
+                $forms[$form->getPriority()] = [$form];
438
+            }
439
+        } catch (QueryException $e) {
440
+            // skip
441
+        }
442
+        return $forms;
443
+    }
444
+
445
+    /**
446
+     * @inheritdoc
447
+     */
448
+    public function getAdminSettings($section) {
449
+        $settings = $this->getBuiltInAdminSettings($section);
450
+        $dbRows = $this->mapper->getAdminSettingsFromDB($section);
451
+
452
+        foreach ($dbRows as $row) {
453
+            if (!isset($settings[$row['priority']])) {
454
+                $settings[$row['priority']] = [];
455
+            }
456
+            try {
457
+                $settings[$row['priority']][] = $this->query($row['class']);
458
+            } catch (QueryException $e) {
459
+                // skip
460
+            }
461
+        }
462
+
463
+        ksort($settings);
464
+        return $settings;
465
+    }
466
+
467
+    /**
468
+     * @inheritdoc
469
+     */
470
+    public function getPersonalSections() {
471
+        $sections = [
472
+            0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))],
473
+            5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))],
474
+            15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))],
475
+        ];
476
+
477
+        $legacyForms = \OC_App::getForms('personal');
478
+        if(count($legacyForms) > 0 && $this->hasLegacyPersonalSettingsToRender($legacyForms)) {
479
+            $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))];
480
+        }
481
+
482
+        $rows = $this->mapper->getPersonalSectionsFromDB();
483
+
484
+        foreach ($rows as $row) {
485
+            if (!isset($sections[$row['priority']])) {
486
+                $sections[$row['priority']] = [];
487
+            }
488
+            try {
489
+                $sections[$row['priority']][] = $this->query($row['class']);
490
+            } catch (QueryException $e) {
491
+                // skip
492
+            }
493
+        }
494
+
495
+        ksort($sections);
496
+
497
+        return $sections;
498
+    }
499
+
500
+    /**
501
+     * @param $forms
502
+     * @return bool
503
+     */
504
+    private function hasLegacyPersonalSettingsToRender($forms) {
505
+        foreach ($forms as $form) {
506
+            if(trim($form) !== '') {
507
+                return true;
508
+            }
509
+        }
510
+        return false;
511
+    }
512
+
513
+    /**
514
+     * @inheritdoc
515
+     */
516
+    public function getPersonalSettings($section) {
517
+        $settings = $this->getBuiltInPersonalSettings($section);
518
+        $dbRows = $this->mapper->getPersonalSettingsFromDB($section);
519
+
520
+        foreach ($dbRows as $row) {
521
+            if (!isset($settings[$row['priority']])) {
522
+                $settings[$row['priority']] = [];
523
+            }
524
+            try {
525
+                $settings[$row['priority']][] = $this->query($row['class']);
526
+            } catch (QueryException $e) {
527
+                // skip
528
+            }
529
+        }
530
+
531
+        ksort($settings);
532
+        return $settings;
533
+    }
534 534
 }
Please login to merge, or discard this patch.
lib/private/App/InfoParser.php 2 patches
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -30,230 +30,230 @@
 block discarded – undo
30 30
 use OCP\ICache;
31 31
 
32 32
 class InfoParser {
33
-	/** @var \OCP\ICache|null */
34
-	private $cache;
33
+    /** @var \OCP\ICache|null */
34
+    private $cache;
35 35
 
36
-	/**
37
-	 * @param ICache|null $cache
38
-	 */
39
-	public function __construct(ICache $cache = null) {
40
-		$this->cache = $cache;
41
-	}
36
+    /**
37
+     * @param ICache|null $cache
38
+     */
39
+    public function __construct(ICache $cache = null) {
40
+        $this->cache = $cache;
41
+    }
42 42
 
43
-	/**
44
-	 * @param string $file the xml file to be loaded
45
-	 * @return null|array where null is an indicator for an error
46
-	 */
47
-	public function parse($file) {
48
-		if (!file_exists($file)) {
49
-			return null;
50
-		}
43
+    /**
44
+     * @param string $file the xml file to be loaded
45
+     * @return null|array where null is an indicator for an error
46
+     */
47
+    public function parse($file) {
48
+        if (!file_exists($file)) {
49
+            return null;
50
+        }
51 51
 
52
-		if(!is_null($this->cache)) {
53
-			$fileCacheKey = $file . filemtime($file);
54
-			if ($cachedValue = $this->cache->get($fileCacheKey)) {
55
-				return json_decode($cachedValue, true);
56
-			}
57
-		}
52
+        if(!is_null($this->cache)) {
53
+            $fileCacheKey = $file . filemtime($file);
54
+            if ($cachedValue = $this->cache->get($fileCacheKey)) {
55
+                return json_decode($cachedValue, true);
56
+            }
57
+        }
58 58
 
59
-		libxml_use_internal_errors(true);
60
-		$loadEntities = libxml_disable_entity_loader(false);
61
-		$xml = simplexml_load_file($file);
59
+        libxml_use_internal_errors(true);
60
+        $loadEntities = libxml_disable_entity_loader(false);
61
+        $xml = simplexml_load_file($file);
62 62
 
63
-		libxml_disable_entity_loader($loadEntities);
64
-		if ($xml === false) {
65
-			libxml_clear_errors();
66
-			return null;
67
-		}
68
-		$array = $this->xmlToArray($xml);
63
+        libxml_disable_entity_loader($loadEntities);
64
+        if ($xml === false) {
65
+            libxml_clear_errors();
66
+            return null;
67
+        }
68
+        $array = $this->xmlToArray($xml);
69 69
 
70
-		if (is_null($array)) {
71
-			return null;
72
-		}
70
+        if (is_null($array)) {
71
+            return null;
72
+        }
73 73
 
74
-		if (!array_key_exists('info', $array)) {
75
-			$array['info'] = [];
76
-		}
77
-		if (!array_key_exists('remote', $array)) {
78
-			$array['remote'] = [];
79
-		}
80
-		if (!array_key_exists('public', $array)) {
81
-			$array['public'] = [];
82
-		}
83
-		if (!array_key_exists('types', $array)) {
84
-			$array['types'] = [];
85
-		}
86
-		if (!array_key_exists('repair-steps', $array)) {
87
-			$array['repair-steps'] = [];
88
-		}
89
-		if (!array_key_exists('install', $array['repair-steps'])) {
90
-			$array['repair-steps']['install'] = [];
91
-		}
92
-		if (!array_key_exists('pre-migration', $array['repair-steps'])) {
93
-			$array['repair-steps']['pre-migration'] = [];
94
-		}
95
-		if (!array_key_exists('post-migration', $array['repair-steps'])) {
96
-			$array['repair-steps']['post-migration'] = [];
97
-		}
98
-		if (!array_key_exists('live-migration', $array['repair-steps'])) {
99
-			$array['repair-steps']['live-migration'] = [];
100
-		}
101
-		if (!array_key_exists('uninstall', $array['repair-steps'])) {
102
-			$array['repair-steps']['uninstall'] = [];
103
-		}
104
-		if (!array_key_exists('background-jobs', $array)) {
105
-			$array['background-jobs'] = [];
106
-		}
107
-		if (!array_key_exists('two-factor-providers', $array)) {
108
-			$array['two-factor-providers'] = [];
109
-		}
110
-		if (!array_key_exists('commands', $array)) {
111
-			$array['commands'] = [];
112
-		}
113
-		if (!array_key_exists('activity', $array)) {
114
-			$array['activity'] = [];
115
-		}
116
-		if (!array_key_exists('filters', $array['activity'])) {
117
-			$array['activity']['filters'] = [];
118
-		}
119
-		if (!array_key_exists('settings', $array['activity'])) {
120
-			$array['activity']['settings'] = [];
121
-		}
122
-		if (!array_key_exists('providers', $array['activity'])) {
123
-			$array['activity']['providers'] = [];
124
-		}
125
-		if (!array_key_exists('settings', $array)) {
126
-			$array['settings'] = [];
127
-		}
128
-		if (!array_key_exists('admin', $array['settings'])) {
129
-			$array['settings']['admin'] = [];
130
-		}
131
-		if (!array_key_exists('admin-section', $array['settings'])) {
132
-			$array['settings']['admin-section'] = [];
133
-		}
134
-		if (!array_key_exists('personal', $array['settings'])) {
135
-			$array['settings']['personal'] = [];
136
-		}
137
-		if (!array_key_exists('personal-section', $array['settings'])) {
138
-			$array['settings']['personal-section'] = [];
139
-		}
74
+        if (!array_key_exists('info', $array)) {
75
+            $array['info'] = [];
76
+        }
77
+        if (!array_key_exists('remote', $array)) {
78
+            $array['remote'] = [];
79
+        }
80
+        if (!array_key_exists('public', $array)) {
81
+            $array['public'] = [];
82
+        }
83
+        if (!array_key_exists('types', $array)) {
84
+            $array['types'] = [];
85
+        }
86
+        if (!array_key_exists('repair-steps', $array)) {
87
+            $array['repair-steps'] = [];
88
+        }
89
+        if (!array_key_exists('install', $array['repair-steps'])) {
90
+            $array['repair-steps']['install'] = [];
91
+        }
92
+        if (!array_key_exists('pre-migration', $array['repair-steps'])) {
93
+            $array['repair-steps']['pre-migration'] = [];
94
+        }
95
+        if (!array_key_exists('post-migration', $array['repair-steps'])) {
96
+            $array['repair-steps']['post-migration'] = [];
97
+        }
98
+        if (!array_key_exists('live-migration', $array['repair-steps'])) {
99
+            $array['repair-steps']['live-migration'] = [];
100
+        }
101
+        if (!array_key_exists('uninstall', $array['repair-steps'])) {
102
+            $array['repair-steps']['uninstall'] = [];
103
+        }
104
+        if (!array_key_exists('background-jobs', $array)) {
105
+            $array['background-jobs'] = [];
106
+        }
107
+        if (!array_key_exists('two-factor-providers', $array)) {
108
+            $array['two-factor-providers'] = [];
109
+        }
110
+        if (!array_key_exists('commands', $array)) {
111
+            $array['commands'] = [];
112
+        }
113
+        if (!array_key_exists('activity', $array)) {
114
+            $array['activity'] = [];
115
+        }
116
+        if (!array_key_exists('filters', $array['activity'])) {
117
+            $array['activity']['filters'] = [];
118
+        }
119
+        if (!array_key_exists('settings', $array['activity'])) {
120
+            $array['activity']['settings'] = [];
121
+        }
122
+        if (!array_key_exists('providers', $array['activity'])) {
123
+            $array['activity']['providers'] = [];
124
+        }
125
+        if (!array_key_exists('settings', $array)) {
126
+            $array['settings'] = [];
127
+        }
128
+        if (!array_key_exists('admin', $array['settings'])) {
129
+            $array['settings']['admin'] = [];
130
+        }
131
+        if (!array_key_exists('admin-section', $array['settings'])) {
132
+            $array['settings']['admin-section'] = [];
133
+        }
134
+        if (!array_key_exists('personal', $array['settings'])) {
135
+            $array['settings']['personal'] = [];
136
+        }
137
+        if (!array_key_exists('personal-section', $array['settings'])) {
138
+            $array['settings']['personal-section'] = [];
139
+        }
140 140
 
141
-		if (array_key_exists('types', $array)) {
142
-			if (is_array($array['types'])) {
143
-				foreach ($array['types'] as $type => $v) {
144
-					unset($array['types'][$type]);
145
-					if (is_string($type)) {
146
-						$array['types'][] = $type;
147
-					}
148
-				}
149
-			} else {
150
-				$array['types'] = [];
151
-			}
152
-		}
153
-		if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) {
154
-			$array['repair-steps']['install'] = $array['repair-steps']['install']['step'];
155
-		}
156
-		if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) {
157
-			$array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step'];
158
-		}
159
-		if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) {
160
-			$array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step'];
161
-		}
162
-		if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) {
163
-			$array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step'];
164
-		}
165
-		if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) {
166
-			$array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step'];
167
-		}
168
-		if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) {
169
-			$array['background-jobs'] = $array['background-jobs']['job'];
170
-		}
171
-		if (isset($array['commands']['command']) && is_array($array['commands']['command'])) {
172
-			$array['commands'] = $array['commands']['command'];
173
-		}
174
-		if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) {
175
-			$array['activity']['filters'] = $array['activity']['filters']['filter'];
176
-		}
177
-		if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) {
178
-			$array['activity']['settings'] = $array['activity']['settings']['setting'];
179
-		}
180
-		if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) {
181
-			$array['activity']['providers'] = $array['activity']['providers']['provider'];
182
-		}
183
-		if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin'])
184
-			&& is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin'])
185
-			&& !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class'])
186
-		) {
187
-			$array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin'];
188
-		}
189
-		if (isset($array['settings']['admin']) && !is_array($array['settings']['admin'])) {
190
-			$array['settings']['admin'] = [$array['settings']['admin']];
191
-		}
192
-		if (isset($array['settings']['admin-section']) && !is_array($array['settings']['admin-section'])) {
193
-			$array['settings']['admin-section'] = [$array['settings']['admin-section']];
194
-		}
195
-		if (isset($array['settings']['personal']) && !is_array($array['settings']['personal'])) {
196
-			$array['settings']['personal'] = [$array['settings']['personal']];
197
-		}
198
-		if (isset($array['settings']['personal-section']) && !is_array($array['settings']['personal-section'])) {
199
-			$array['settings']['personal-section'] = [$array['settings']['personal-section']];
200
-		}
141
+        if (array_key_exists('types', $array)) {
142
+            if (is_array($array['types'])) {
143
+                foreach ($array['types'] as $type => $v) {
144
+                    unset($array['types'][$type]);
145
+                    if (is_string($type)) {
146
+                        $array['types'][] = $type;
147
+                    }
148
+                }
149
+            } else {
150
+                $array['types'] = [];
151
+            }
152
+        }
153
+        if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) {
154
+            $array['repair-steps']['install'] = $array['repair-steps']['install']['step'];
155
+        }
156
+        if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) {
157
+            $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step'];
158
+        }
159
+        if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) {
160
+            $array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step'];
161
+        }
162
+        if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) {
163
+            $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step'];
164
+        }
165
+        if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) {
166
+            $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step'];
167
+        }
168
+        if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) {
169
+            $array['background-jobs'] = $array['background-jobs']['job'];
170
+        }
171
+        if (isset($array['commands']['command']) && is_array($array['commands']['command'])) {
172
+            $array['commands'] = $array['commands']['command'];
173
+        }
174
+        if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) {
175
+            $array['activity']['filters'] = $array['activity']['filters']['filter'];
176
+        }
177
+        if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) {
178
+            $array['activity']['settings'] = $array['activity']['settings']['setting'];
179
+        }
180
+        if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) {
181
+            $array['activity']['providers'] = $array['activity']['providers']['provider'];
182
+        }
183
+        if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin'])
184
+            && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin'])
185
+            && !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class'])
186
+        ) {
187
+            $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin'];
188
+        }
189
+        if (isset($array['settings']['admin']) && !is_array($array['settings']['admin'])) {
190
+            $array['settings']['admin'] = [$array['settings']['admin']];
191
+        }
192
+        if (isset($array['settings']['admin-section']) && !is_array($array['settings']['admin-section'])) {
193
+            $array['settings']['admin-section'] = [$array['settings']['admin-section']];
194
+        }
195
+        if (isset($array['settings']['personal']) && !is_array($array['settings']['personal'])) {
196
+            $array['settings']['personal'] = [$array['settings']['personal']];
197
+        }
198
+        if (isset($array['settings']['personal-section']) && !is_array($array['settings']['personal-section'])) {
199
+            $array['settings']['personal-section'] = [$array['settings']['personal-section']];
200
+        }
201 201
 
202
-		if(!is_null($this->cache)) {
203
-			$this->cache->set($fileCacheKey, json_encode($array));
204
-		}
205
-		return $array;
206
-	}
202
+        if(!is_null($this->cache)) {
203
+            $this->cache->set($fileCacheKey, json_encode($array));
204
+        }
205
+        return $array;
206
+    }
207 207
 
208
-	/**
209
-	 * @param \SimpleXMLElement $xml
210
-	 * @return array
211
-	 */
212
-	public function xmlToArray($xml) {
213
-		if (!$xml->children()) {
214
-			return (string)$xml;
215
-		}
208
+    /**
209
+     * @param \SimpleXMLElement $xml
210
+     * @return array
211
+     */
212
+    public function xmlToArray($xml) {
213
+        if (!$xml->children()) {
214
+            return (string)$xml;
215
+        }
216 216
 
217
-		$array = [];
218
-		foreach ($xml->children() as $element => $node) {
219
-			$totalElement = count($xml->{$element});
217
+        $array = [];
218
+        foreach ($xml->children() as $element => $node) {
219
+            $totalElement = count($xml->{$element});
220 220
 
221
-			if (!isset($array[$element])) {
222
-				$array[$element] = $totalElement > 1 ? [] : "";
223
-			}
224
-			/** @var \SimpleXMLElement $node */
225
-			// Has attributes
226
-			if ($attributes = $node->attributes()) {
227
-				$data = [
228
-					'@attributes' => [],
229
-				];
230
-				if (!count($node->children())){
231
-					$value = (string)$node;
232
-					if (!empty($value)) {
233
-						$data['@value'] = (string)$node;
234
-					}
235
-				} else {
236
-					$data = array_merge($data, $this->xmlToArray($node));
237
-				}
238
-				foreach ($attributes as $attr => $value) {
239
-					$data['@attributes'][$attr] = (string)$value;
240
-				}
221
+            if (!isset($array[$element])) {
222
+                $array[$element] = $totalElement > 1 ? [] : "";
223
+            }
224
+            /** @var \SimpleXMLElement $node */
225
+            // Has attributes
226
+            if ($attributes = $node->attributes()) {
227
+                $data = [
228
+                    '@attributes' => [],
229
+                ];
230
+                if (!count($node->children())){
231
+                    $value = (string)$node;
232
+                    if (!empty($value)) {
233
+                        $data['@value'] = (string)$node;
234
+                    }
235
+                } else {
236
+                    $data = array_merge($data, $this->xmlToArray($node));
237
+                }
238
+                foreach ($attributes as $attr => $value) {
239
+                    $data['@attributes'][$attr] = (string)$value;
240
+                }
241 241
 
242
-				if ($totalElement > 1) {
243
-					$array[$element][] = $data;
244
-				} else {
245
-					$array[$element] = $data;
246
-				}
247
-				// Just a value
248
-			} else {
249
-				if ($totalElement > 1) {
250
-					$array[$element][] = $this->xmlToArray($node);
251
-				} else {
252
-					$array[$element] = $this->xmlToArray($node);
253
-				}
254
-			}
255
-		}
242
+                if ($totalElement > 1) {
243
+                    $array[$element][] = $data;
244
+                } else {
245
+                    $array[$element] = $data;
246
+                }
247
+                // Just a value
248
+            } else {
249
+                if ($totalElement > 1) {
250
+                    $array[$element][] = $this->xmlToArray($node);
251
+                } else {
252
+                    $array[$element] = $this->xmlToArray($node);
253
+                }
254
+            }
255
+        }
256 256
 
257
-		return $array;
258
-	}
257
+        return $array;
258
+    }
259 259
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 			return null;
50 50
 		}
51 51
 
52
-		if(!is_null($this->cache)) {
53
-			$fileCacheKey = $file . filemtime($file);
52
+		if (!is_null($this->cache)) {
53
+			$fileCacheKey = $file.filemtime($file);
54 54
 			if ($cachedValue = $this->cache->get($fileCacheKey)) {
55 55
 				return json_decode($cachedValue, true);
56 56
 			}
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 			$array['settings']['personal-section'] = [$array['settings']['personal-section']];
200 200
 		}
201 201
 
202
-		if(!is_null($this->cache)) {
202
+		if (!is_null($this->cache)) {
203 203
 			$this->cache->set($fileCacheKey, json_encode($array));
204 204
 		}
205 205
 		return $array;
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 	 */
212 212
 	public function xmlToArray($xml) {
213 213
 		if (!$xml->children()) {
214
-			return (string)$xml;
214
+			return (string) $xml;
215 215
 		}
216 216
 
217 217
 		$array = [];
@@ -227,16 +227,16 @@  discard block
 block discarded – undo
227 227
 				$data = [
228 228
 					'@attributes' => [],
229 229
 				];
230
-				if (!count($node->children())){
231
-					$value = (string)$node;
230
+				if (!count($node->children())) {
231
+					$value = (string) $node;
232 232
 					if (!empty($value)) {
233
-						$data['@value'] = (string)$node;
233
+						$data['@value'] = (string) $node;
234 234
 					}
235 235
 				} else {
236 236
 					$data = array_merge($data, $this->xmlToArray($node));
237 237
 				}
238 238
 				foreach ($attributes as $attr => $value) {
239
-					$data['@attributes'][$attr] = (string)$value;
239
+					$data['@attributes'][$attr] = (string) $value;
240 240
 				}
241 241
 
242 242
 				if ($totalElement > 1) {
Please login to merge, or discard this patch.