Completed
Pull Request — master (#4890)
by Blizzz
17:06
created
apps/federatedfilesharing/lib/Settings/PersonalSection.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -29,58 +29,58 @@
 block discarded – undo
29 29
 use OCP\Settings\IIconSection;
30 30
 
31 31
 class PersonalSection implements IIconSection {
32
-	/** @var IURLGenerator */
33
-	private $urlGenerator;
34
-	/** @var IL10N */
35
-	private $l;
32
+    /** @var IURLGenerator */
33
+    private $urlGenerator;
34
+    /** @var IL10N */
35
+    private $l;
36 36
 
37
-	public function __construct(IURLGenerator $urlGenerator, IL10N $l) {
38
-		$this->urlGenerator = $urlGenerator;
39
-		$this->l = $l;
40
-	}
37
+    public function __construct(IURLGenerator $urlGenerator, IL10N $l) {
38
+        $this->urlGenerator = $urlGenerator;
39
+        $this->l = $l;
40
+    }
41 41
 
42
-	/**
43
-	 * returns the relative path to an 16*16 icon describing the section.
44
-	 * e.g. '/core/img/places/files.svg'
45
-	 *
46
-	 * @returns string
47
-	 * @since 12
48
-	 */
49
-	public function getIcon() {
50
-		return $this->urlGenerator->imagePath('core', 'actions/share.svg');
51
-	}
42
+    /**
43
+     * returns the relative path to an 16*16 icon describing the section.
44
+     * e.g. '/core/img/places/files.svg'
45
+     *
46
+     * @returns string
47
+     * @since 12
48
+     */
49
+    public function getIcon() {
50
+        return $this->urlGenerator->imagePath('core', 'actions/share.svg');
51
+    }
52 52
 
53
-	/**
54
-	 * returns the ID of the section. It is supposed to be a lower case string,
55
-	 * e.g. 'ldap'
56
-	 *
57
-	 * @returns string
58
-	 * @since 9.1
59
-	 */
60
-	public function getID() {
61
-		return 'sharing';
62
-	}
53
+    /**
54
+     * returns the ID of the section. It is supposed to be a lower case string,
55
+     * e.g. 'ldap'
56
+     *
57
+     * @returns string
58
+     * @since 9.1
59
+     */
60
+    public function getID() {
61
+        return 'sharing';
62
+    }
63 63
 
64
-	/**
65
-	 * returns the translated name as it should be displayed, e.g. 'LDAP / AD
66
-	 * integration'. Use the L10N service to translate it.
67
-	 *
68
-	 * @return string
69
-	 * @since 9.1
70
-	 */
71
-	public function getName() {
72
-		return $this->l->t('Sharing');
73
-	}
64
+    /**
65
+     * returns the translated name as it should be displayed, e.g. 'LDAP / AD
66
+     * integration'. Use the L10N service to translate it.
67
+     *
68
+     * @return string
69
+     * @since 9.1
70
+     */
71
+    public function getName() {
72
+        return $this->l->t('Sharing');
73
+    }
74 74
 
75
-	/**
76
-	 * @return int whether the form should be rather on the top or bottom of
77
-	 * the settings navigation. The sections are arranged in ascending order of
78
-	 * the priority values. It is required to return a value between 0 and 99.
79
-	 *
80
-	 * E.g.: 70
81
-	 * @since 9.1
82
-	 */
83
-	public function getPriority() {
84
-		return 15;
85
-	}
75
+    /**
76
+     * @return int whether the form should be rather on the top or bottom of
77
+     * the settings navigation. The sections are arranged in ascending order of
78
+     * the priority values. It is required to return a value between 0 and 99.
79
+     *
80
+     * E.g.: 70
81
+     * @since 9.1
82
+     */
83
+    public function getPriority() {
84
+        return 15;
85
+    }
86 86
 }
Please login to merge, or discard this patch.
apps/federatedfilesharing/lib/Settings/Personal.php 1 patch
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -33,69 +33,69 @@
 block discarded – undo
33 33
 
34 34
 class Personal implements ISettings {
35 35
 
36
-	/** @var FederatedShareProvider */
37
-	private $federatedShareProvider;
38
-	/** @var IUserSession */
39
-	private $userSession;
40
-	/** @var IL10N */
41
-	private $l;
42
-	/** @var IURLGenerator */
43
-	private $urlGenerator;
44
-	/** @var \OC_Defaults */
45
-	private $defaults;
36
+    /** @var FederatedShareProvider */
37
+    private $federatedShareProvider;
38
+    /** @var IUserSession */
39
+    private $userSession;
40
+    /** @var IL10N */
41
+    private $l;
42
+    /** @var IURLGenerator */
43
+    private $urlGenerator;
44
+    /** @var \OC_Defaults */
45
+    private $defaults;
46 46
 
47
-	public function __construct(
48
-		FederatedShareProvider $federatedShareProvider, #
49
-		IUserSession $userSession,
50
-		IL10N $l,
51
-		IURLGenerator $urlGenerator,
52
-		\OC_Defaults $defaults
53
-	) {
54
-		$this->federatedShareProvider = $federatedShareProvider;
55
-		$this->userSession = $userSession;
56
-		$this->l = $l;
57
-		$this->urlGenerator = $urlGenerator;
58
-		$this->defaults = $defaults;
59
-	}
47
+    public function __construct(
48
+        FederatedShareProvider $federatedShareProvider, #
49
+        IUserSession $userSession,
50
+        IL10N $l,
51
+        IURLGenerator $urlGenerator,
52
+        \OC_Defaults $defaults
53
+    ) {
54
+        $this->federatedShareProvider = $federatedShareProvider;
55
+        $this->userSession = $userSession;
56
+        $this->l = $l;
57
+        $this->urlGenerator = $urlGenerator;
58
+        $this->defaults = $defaults;
59
+    }
60 60
 
61
-	/**
62
-	 * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
63
-	 * @since 9.1
64
-	 */
65
-	public function getForm() {
66
-		$cloudID = $this->userSession->getUser()->getCloudId();
67
-		$url = 'https://nextcloud.com/federation#' . $cloudID;
61
+    /**
62
+     * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
63
+     * @since 9.1
64
+     */
65
+    public function getForm() {
66
+        $cloudID = $this->userSession->getUser()->getCloudId();
67
+        $url = 'https://nextcloud.com/federation#' . $cloudID;
68 68
 
69
-		$parameters = [
70
-			'outgoingServer2serverShareEnabled' => $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(),
71
-			'message_with_URL' => $this->l->t('Share with me through my #Nextcloud Federated Cloud ID, see %s', [$url]),
72
-			'message_without_URL' => $this->l->t('Share with me through my #Nextcloud Federated Cloud ID', [$cloudID]),
73
-			'logoPath' => $this->urlGenerator->imagePath('core', 'logo-icon.svg'),
74
-			'reference' => $url,
75
-			'cloudId' => $cloudID,
76
-			'color' => $this->defaults->getColorPrimary(),
77
-			'textColor' => "#ffffff",
78
-		];
79
-		return new TemplateResponse('federatedfilesharing', 'settings-personal', $parameters, '');
80
-	}
69
+        $parameters = [
70
+            'outgoingServer2serverShareEnabled' => $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(),
71
+            'message_with_URL' => $this->l->t('Share with me through my #Nextcloud Federated Cloud ID, see %s', [$url]),
72
+            'message_without_URL' => $this->l->t('Share with me through my #Nextcloud Federated Cloud ID', [$cloudID]),
73
+            'logoPath' => $this->urlGenerator->imagePath('core', 'logo-icon.svg'),
74
+            'reference' => $url,
75
+            'cloudId' => $cloudID,
76
+            'color' => $this->defaults->getColorPrimary(),
77
+            'textColor' => "#ffffff",
78
+        ];
79
+        return new TemplateResponse('federatedfilesharing', 'settings-personal', $parameters, '');
80
+    }
81 81
 
82
-	/**
83
-	 * @return string the section ID, e.g. 'sharing'
84
-	 * @since 9.1
85
-	 */
86
-	public function getSection() {
87
-		return 'sharing';
88
-	}
82
+    /**
83
+     * @return string the section ID, e.g. 'sharing'
84
+     * @since 9.1
85
+     */
86
+    public function getSection() {
87
+        return 'sharing';
88
+    }
89 89
 
90
-	/**
91
-	 * @return int whether the form should be rather on the top or bottom of
92
-	 * the admin section. The forms are arranged in ascending order of the
93
-	 * priority values. It is required to return a value between 0 and 100.
94
-	 *
95
-	 * E.g.: 70
96
-	 * @since 9.1
97
-	 */
98
-	public function getPriority() {
99
-		return 40;
100
-	}
90
+    /**
91
+     * @return int whether the form should be rather on the top or bottom of
92
+     * the admin section. The forms are arranged in ascending order of the
93
+     * priority values. It is required to return a value between 0 and 100.
94
+     *
95
+     * E.g.: 70
96
+     * @since 9.1
97
+     */
98
+    public function getPriority() {
99
+        return 40;
100
+    }
101 101
 }
Please login to merge, or discard this patch.
apps/federatedfilesharing/lib/AppInfo/Application.php 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -34,86 +34,86 @@
 block discarded – undo
34 34
 
35 35
 class Application extends App {
36 36
 
37
-	/** @var FederatedShareProvider */
38
-	protected $federatedShareProvider;
37
+    /** @var FederatedShareProvider */
38
+    protected $federatedShareProvider;
39 39
 
40
-	public function __construct() {
41
-		parent::__construct('federatedfilesharing');
40
+    public function __construct() {
41
+        parent::__construct('federatedfilesharing');
42 42
 
43
-		$container = $this->getContainer();
44
-		$server = $container->getServer();
43
+        $container = $this->getContainer();
44
+        $server = $container->getServer();
45 45
 
46
-		$container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) {
47
-			$addressHandler = new AddressHandler(
48
-				$server->getURLGenerator(),
49
-				$server->getL10N('federatedfilesharing'),
50
-				$server->getCloudIdManager()
51
-			);
52
-			$notification = new Notifications(
53
-				$addressHandler,
54
-				$server->getHTTPClientService(),
55
-				$server->query(\OCP\OCS\IDiscoveryService::class),
56
-				\OC::$server->getJobList()
57
-			);
58
-			return new RequestHandlerController(
59
-				$c->query('AppName'),
60
-				$server->getRequest(),
61
-				$this->getFederatedShareProvider(),
62
-				$server->getDatabaseConnection(),
63
-				$server->getShareManager(),
64
-				$notification,
65
-				$addressHandler,
66
-				$server->getUserManager(),
67
-				$server->getCloudIdManager()
68
-			);
69
-		});
70
-	}
46
+        $container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) {
47
+            $addressHandler = new AddressHandler(
48
+                $server->getURLGenerator(),
49
+                $server->getL10N('federatedfilesharing'),
50
+                $server->getCloudIdManager()
51
+            );
52
+            $notification = new Notifications(
53
+                $addressHandler,
54
+                $server->getHTTPClientService(),
55
+                $server->query(\OCP\OCS\IDiscoveryService::class),
56
+                \OC::$server->getJobList()
57
+            );
58
+            return new RequestHandlerController(
59
+                $c->query('AppName'),
60
+                $server->getRequest(),
61
+                $this->getFederatedShareProvider(),
62
+                $server->getDatabaseConnection(),
63
+                $server->getShareManager(),
64
+                $notification,
65
+                $addressHandler,
66
+                $server->getUserManager(),
67
+                $server->getCloudIdManager()
68
+            );
69
+        });
70
+    }
71 71
 
72
-	/**
73
-	 * get instance of federated share provider
74
-	 *
75
-	 * @return FederatedShareProvider
76
-	 */
77
-	public function getFederatedShareProvider() {
78
-		if ($this->federatedShareProvider === null) {
79
-			$this->initFederatedShareProvider();
80
-		}
81
-		return $this->federatedShareProvider;
82
-	}
72
+    /**
73
+     * get instance of federated share provider
74
+     *
75
+     * @return FederatedShareProvider
76
+     */
77
+    public function getFederatedShareProvider() {
78
+        if ($this->federatedShareProvider === null) {
79
+            $this->initFederatedShareProvider();
80
+        }
81
+        return $this->federatedShareProvider;
82
+    }
83 83
 
84
-	/**
85
-	 * initialize federated share provider
86
-	 */
87
-	protected function initFederatedShareProvider() {
88
-		$c = $this->getContainer();
89
-		$addressHandler = new \OCA\FederatedFileSharing\AddressHandler(
90
-			\OC::$server->getURLGenerator(),
91
-			\OC::$server->getL10N('federatedfilesharing'),
92
-			\OC::$server->getCloudIdManager()
93
-		);
94
-		$notifications = new \OCA\FederatedFileSharing\Notifications(
95
-			$addressHandler,
96
-			\OC::$server->getHTTPClientService(),
97
-			\OC::$server->query(\OCP\OCS\IDiscoveryService::class),
98
-			\OC::$server->getJobList()
99
-		);
100
-		$tokenHandler = new \OCA\FederatedFileSharing\TokenHandler(
101
-			\OC::$server->getSecureRandom()
102
-		);
84
+    /**
85
+     * initialize federated share provider
86
+     */
87
+    protected function initFederatedShareProvider() {
88
+        $c = $this->getContainer();
89
+        $addressHandler = new \OCA\FederatedFileSharing\AddressHandler(
90
+            \OC::$server->getURLGenerator(),
91
+            \OC::$server->getL10N('federatedfilesharing'),
92
+            \OC::$server->getCloudIdManager()
93
+        );
94
+        $notifications = new \OCA\FederatedFileSharing\Notifications(
95
+            $addressHandler,
96
+            \OC::$server->getHTTPClientService(),
97
+            \OC::$server->query(\OCP\OCS\IDiscoveryService::class),
98
+            \OC::$server->getJobList()
99
+        );
100
+        $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler(
101
+            \OC::$server->getSecureRandom()
102
+        );
103 103
 
104
-		$this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider(
105
-			\OC::$server->getDatabaseConnection(),
106
-			$addressHandler,
107
-			$notifications,
108
-			$tokenHandler,
109
-			\OC::$server->getL10N('federatedfilesharing'),
110
-			\OC::$server->getLogger(),
111
-			\OC::$server->getLazyRootFolder(),
112
-			\OC::$server->getConfig(),
113
-			\OC::$server->getUserManager(),
114
-			\OC::$server->getCloudIdManager(),
115
-			$c->query(IConfig::class)
116
-		);
117
-	}
104
+        $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider(
105
+            \OC::$server->getDatabaseConnection(),
106
+            $addressHandler,
107
+            $notifications,
108
+            $tokenHandler,
109
+            \OC::$server->getL10N('federatedfilesharing'),
110
+            \OC::$server->getLogger(),
111
+            \OC::$server->getLazyRootFolder(),
112
+            \OC::$server->getConfig(),
113
+            \OC::$server->getUserManager(),
114
+            \OC::$server->getCloudIdManager(),
115
+            $c->query(IConfig::class)
116
+        );
117
+    }
118 118
 
119 119
 }
Please login to merge, or discard this patch.
lib/private/Settings/Manager.php 1 patch
Indentation   +486 added lines, -486 removed lines patch added patch discarded remove patch
@@ -42,490 +42,490 @@
 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 (isset($settings[IManager::KEY_ADMIN_SECTION])) {
131
-			$this->setupSectionEntry($settings[IManager::KEY_ADMIN_SECTION], 'admin');
132
-		}
133
-		if (isset($settings[IManager::KEY_ADMIN_SETTINGS])) {
134
-			$this->setupSettingsEntry($settings[IManager::KEY_ADMIN_SETTINGS], 'admin');
135
-		}
136
-
137
-		if (isset($settings[IManager::KEY_PERSONAL_SECTION])) {
138
-			$this->setupSectionEntry($settings[IManager::KEY_PERSONAL_SECTION], 'personal');
139
-		}
140
-		if (isset($settings[IManager::KEY_PERSONAL_SETTINGS])) {
141
-			$this->setupSettingsEntry($settings[IManager::KEY_PERSONAL_SETTINGS], 'personal');
142
-		}
143
-	}
144
-
145
-	/**
146
-	 * attempts to remove an apps section and/or settings entry. A listener is
147
-	 * added centrally making sure that this method is called ones an app was
148
-	 * disabled.
149
-	 *
150
-	 * @param string $appId
151
-	 * @since 9.1.0
152
-	 */
153
-	public function onAppDisabled($appId) {
154
-		$appInfo = \OC_App::getAppInfo($appId); // hello static legacy
155
-
156
-		if (isset($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) {
157
-			$this->mapper->remove(Mapper::TABLE_ADMIN_SECTIONS, trim($appInfo['settings'][IManager::KEY_ADMIN_SECTION], '\\'));
158
-		}
159
-		if (isset($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) {
160
-			$this->mapper->remove(Mapper::TABLE_ADMIN_SETTINGS, trim($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS], '\\'));
161
-		}
162
-
163
-		if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SECTION])) {
164
-			$this->mapper->remove(Mapper::TABLE_PERSONAL_SECTIONS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SECTION], '\\'));
165
-		}
166
-		if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS])) {
167
-			$this->mapper->remove(Mapper::TABLE_PERSONAL_SETTINGS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS], '\\'));
168
-		}
169
-	}
170
-
171
-	public function checkForOrphanedClassNames() {
172
-		$tables = [Mapper::TABLE_ADMIN_SECTIONS, Mapper::TABLE_ADMIN_SETTINGS, Mapper::TABLE_PERSONAL_SECTIONS, Mapper::TABLE_PERSONAL_SETTINGS];
173
-		foreach ($tables as $table) {
174
-			$classes = $this->mapper->getClasses($table);
175
-			foreach ($classes as $className) {
176
-				try {
177
-					\OC::$server->query($className);
178
-				} catch (QueryException $e) {
179
-					$this->mapper->remove($table, $className);
180
-				}
181
-			}
182
-		}
183
-	}
184
-
185
-	/**
186
-	 * @param string $sectionClassName
187
-	 * @param string $type either 'admin' or 'personal'
188
-	 */
189
-	private function setupSectionEntry($sectionClassName, $type) {
190
-		if (!class_exists($sectionClassName)) {
191
-			$this->log->debug('Could not find ' . ucfirst($type) . ' section class ' . $sectionClassName);
192
-			return;
193
-		}
194
-		try {
195
-			$section = $this->query($sectionClassName);
196
-		} catch (QueryException $e) {
197
-			// cancel
198
-			return;
199
-		}
200
-
201
-		if (!$section instanceof ISection) {
202
-			$this->log->error(
203
-				ucfirst($type) .' section instance must implement \OCP\ISection. Invalid class: {class}',
204
-				['class' => $sectionClassName]
205
-			);
206
-			return;
207
-		}
208
-		$table = $this->getSectionTableForType($type);
209
-		if(!$this->hasSection(get_class($section), $table)) {
210
-			$this->addSection($section, $table);
211
-		} else {
212
-			$this->updateSection($section, $table);
213
-		}
214
-	}
215
-
216
-	private function addSection(ISection $section, $table) {
217
-		$this->mapper->add($table, [
218
-			'id' => $section->getID(),
219
-			'class' => get_class($section),
220
-			'priority' => $section->getPriority(),
221
-		]);
222
-	}
223
-
224
-	private function addSettings(ISettings $settings, $table) {
225
-		$this->mapper->add($table, [
226
-			'class' => get_class($settings),
227
-			'section' => $settings->getSection(),
228
-			'priority' => $settings->getPriority(),
229
-		]);
230
-	}
231
-
232
-	private function updateSettings(ISettings $settings, $table) {
233
-		$this->mapper->update(
234
-			$table,
235
-			'class',
236
-			get_class($settings),
237
-			[
238
-				'section' => $settings->getSection(),
239
-				'priority' => $settings->getPriority(),
240
-			]
241
-		);
242
-	}
243
-
244
-	private function updateSection(ISection $section, $table) {
245
-		$this->mapper->update(
246
-			$table,
247
-			'class',
248
-			get_class($section),
249
-			[
250
-				'id' => $section->getID(),
251
-				'priority' => $section->getPriority(),
252
-			]
253
-		);
254
-	}
255
-
256
-	/**
257
-	 * @param string $className
258
-	 * @param string $table
259
-	 * @return bool
260
-	 */
261
-	private function hasSection($className, $table) {
262
-		return $this->mapper->has($table, $className);
263
-	}
264
-
265
-	/**
266
-	 * @param string $className
267
-	 * @return bool
268
-	 */
269
-	private function hasSettings($className, $table) {
270
-		return $this->mapper->has($table, $className);
271
-	}
272
-
273
-	private function setupSettingsEntry($settingsClassName, $type) {
274
-		if (!class_exists($settingsClassName)) {
275
-			$this->log->debug('Could not find ' . $type . ' section class ' . $settingsClassName);
276
-			return;
277
-		}
278
-
279
-		try {
280
-			/** @var ISettings $settings */
281
-			$settings = $this->query($settingsClassName);
282
-		} catch (QueryException $e) {
283
-			// cancel
284
-			return;
285
-		}
286
-
287
-		if (!$settings instanceof ISettings) {
288
-			$this->log->error(
289
-				ucfirst($type) . ' section instance must implement \OCP\Settings\ISettings. Invalid class: {class}',
290
-				['class' => $settingsClassName]
291
-			);
292
-			return;
293
-		}
294
-		$table = $this->getSettingsTableForType($type);
295
-		if (!$this->hasSettings(get_class($settings), $table)) {
296
-			$this->addSettings($settings, $table);
297
-		} else {
298
-			$this->updateSettings($settings, $table);
299
-		}
300
-	}
301
-
302
-	private function getSectionTableForType($type) {
303
-		if($type === 'admin') {
304
-			return Mapper::TABLE_ADMIN_SECTIONS;
305
-		} else if($type === 'personal') {
306
-			return Mapper::TABLE_PERSONAL_SECTIONS;
307
-		}
308
-		throw new \InvalidArgumentException('"admin" or "personal" expected');
309
-	}
310
-
311
-	private function getSettingsTableForType($type) {
312
-		if($type === 'admin') {
313
-			return Mapper::TABLE_ADMIN_SETTINGS;
314
-		} else if($type === 'personal') {
315
-			return Mapper::TABLE_PERSONAL_SETTINGS;
316
-		}
317
-		throw new \InvalidArgumentException('"admin" or "personal" expected');
318
-	}
319
-
320
-	private function query($className) {
321
-		try {
322
-			return \OC::$server->query($className);
323
-		} catch (QueryException $e) {
324
-			$this->log->logException($e);
325
-			throw $e;
326
-		}
327
-	}
328
-
329
-	/**
330
-	 * @inheritdoc
331
-	 */
332
-	public function getAdminSections() {
333
-		// built-in sections
334
-		$sections = [
335
-			0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))],
336
-			5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))],
337
-			10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
338
-			45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
339
-			98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
340
-			99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))],
341
-		];
342
-
343
-		$rows = $this->mapper->getAdminSectionsFromDB();
344
-
345
-		foreach ($rows as $row) {
346
-			if (!isset($sections[$row['priority']])) {
347
-				$sections[$row['priority']] = [];
348
-			}
349
-			try {
350
-				$sections[$row['priority']][] = $this->query($row['class']);
351
-			} catch (QueryException $e) {
352
-				// skip
353
-			}
354
-		}
355
-
356
-		ksort($sections);
357
-
358
-		return $sections;
359
-	}
360
-
361
-	/**
362
-	 * @param string $section
363
-	 * @return ISection[]
364
-	 */
365
-	private function getBuiltInAdminSettings($section) {
366
-		$forms = [];
367
-		try {
368
-			if ($section === 'server') {
369
-				/** @var ISettings $form */
370
-				$form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l);
371
-				$forms[$form->getPriority()] = [$form];
372
-				$form = new Admin\ServerDevNotice();
373
-				$forms[$form->getPriority()] = [$form];
374
-			}
375
-			if ($section === 'encryption') {
376
-				/** @var ISettings $form */
377
-				$form = new Admin\Encryption($this->encryptionManager, $this->userManager);
378
-				$forms[$form->getPriority()] = [$form];
379
-			}
380
-			if ($section === 'sharing') {
381
-				/** @var ISettings $form */
382
-				$form = new Admin\Sharing($this->config);
383
-				$forms[$form->getPriority()] = [$form];
384
-			}
385
-			if ($section === 'additional') {
386
-				/** @var ISettings $form */
387
-				$form = new Admin\Additional($this->config);
388
-				$forms[$form->getPriority()] = [$form];
389
-			}
390
-			if ($section === 'tips-tricks') {
391
-				/** @var ISettings $form */
392
-				$form = new Admin\TipsTricks($this->config);
393
-				$forms[$form->getPriority()] = [$form];
394
-			}
395
-		} catch (QueryException $e) {
396
-			// skip
397
-		}
398
-		return $forms;
399
-	}
400
-
401
-	/**
402
-	 * @param string $section
403
-	 * @return ISection[]
404
-	 */
405
-	private function getBuiltInPersonalSettings($section) {
406
-		$forms = [];
407
-		try {
408
-			if ($section === 'personal-info') {
409
-				/** @var ISettings $form */
410
-				$form = new Personal\PersonalInfo(
411
-					$this->config,
412
-					$this->userManager,
413
-					$this->groupManager,
414
-					$this->accountManager,
415
-					$this->appManager,
416
-					$this->l10nFactory,
417
-					$this->l
418
-				);
419
-				$forms[$form->getPriority()] = [$form];
420
-			}
421
-			if($section === 'security') {
422
-				/** @var ISettings $form */
423
-				$form = new Personal\Security();
424
-				$forms[$form->getPriority()] = [$form];
425
-			}
426
-			if($section === 'sync-clients') {
427
-				/** @var ISettings $form */
428
-				$form = new Personal\SyncClients($this->config, $this->defaults);
429
-				$forms[$form->getPriority()] = [$form];
430
-			}
431
-			if ($section === 'additional') {
432
-				/** @var ISettings $form */
433
-				$form = new Personal\Additional($this->config);
434
-				$forms[$form->getPriority()] = [$form];
435
-			}
436
-		} catch (QueryException $e) {
437
-			// skip
438
-		}
439
-		return $forms;
440
-	}
441
-
442
-	/**
443
-	 * @inheritdoc
444
-	 */
445
-	public function getAdminSettings($section) {
446
-		$settings = $this->getBuiltInAdminSettings($section);
447
-		$dbRows = $this->mapper->getAdminSettingsFromDB($section);
448
-
449
-		foreach ($dbRows as $row) {
450
-			if (!isset($settings[$row['priority']])) {
451
-				$settings[$row['priority']] = [];
452
-			}
453
-			try {
454
-				$settings[$row['priority']][] = $this->query($row['class']);
455
-			} catch (QueryException $e) {
456
-				// skip
457
-			}
458
-		}
459
-
460
-		ksort($settings);
461
-		return $settings;
462
-	}
463
-
464
-	/**
465
-	 * @inheritdoc
466
-	 */
467
-	public function getPersonalSections() {
468
-		$sections = [
469
-			0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))],
470
-			5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))],
471
-			15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))],
472
-		];
473
-
474
-		$legacyForms = \OC_App::getForms('personal');
475
-		if(count($legacyForms) > 0 && $this->hasLegacyPersonalSettingsToRender($legacyForms)) {
476
-			$sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))];
477
-		}
478
-
479
-		$rows = $this->mapper->getPersonalSectionsFromDB();
480
-
481
-		foreach ($rows as $row) {
482
-			if (!isset($sections[$row['priority']])) {
483
-				$sections[$row['priority']] = [];
484
-			}
485
-			try {
486
-				$sections[$row['priority']][] = $this->query($row['class']);
487
-			} catch (QueryException $e) {
488
-				// skip
489
-			}
490
-		}
491
-
492
-		ksort($sections);
493
-
494
-		return $sections;
495
-	}
496
-
497
-	/**
498
-	 * @param $forms
499
-	 * @return bool
500
-	 */
501
-	private function hasLegacyPersonalSettingsToRender($forms) {
502
-		foreach ($forms as $form) {
503
-			if(trim($form) !== '') {
504
-				return true;
505
-			}
506
-		}
507
-		return false;
508
-	}
509
-
510
-	/**
511
-	 * @inheritdoc
512
-	 */
513
-	public function getPersonalSettings($section) {
514
-		$settings = $this->getBuiltInPersonalSettings($section);
515
-		$dbRows = $this->mapper->getPersonalSettingsFromDB($section);
516
-
517
-		foreach ($dbRows as $row) {
518
-			if (!isset($settings[$row['priority']])) {
519
-				$settings[$row['priority']] = [];
520
-			}
521
-			try {
522
-				$settings[$row['priority']][] = $this->query($row['class']);
523
-			} catch (QueryException $e) {
524
-				// skip
525
-			}
526
-		}
527
-
528
-		ksort($settings);
529
-		return $settings;
530
-	}
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 (isset($settings[IManager::KEY_ADMIN_SECTION])) {
131
+            $this->setupSectionEntry($settings[IManager::KEY_ADMIN_SECTION], 'admin');
132
+        }
133
+        if (isset($settings[IManager::KEY_ADMIN_SETTINGS])) {
134
+            $this->setupSettingsEntry($settings[IManager::KEY_ADMIN_SETTINGS], 'admin');
135
+        }
136
+
137
+        if (isset($settings[IManager::KEY_PERSONAL_SECTION])) {
138
+            $this->setupSectionEntry($settings[IManager::KEY_PERSONAL_SECTION], 'personal');
139
+        }
140
+        if (isset($settings[IManager::KEY_PERSONAL_SETTINGS])) {
141
+            $this->setupSettingsEntry($settings[IManager::KEY_PERSONAL_SETTINGS], 'personal');
142
+        }
143
+    }
144
+
145
+    /**
146
+     * attempts to remove an apps section and/or settings entry. A listener is
147
+     * added centrally making sure that this method is called ones an app was
148
+     * disabled.
149
+     *
150
+     * @param string $appId
151
+     * @since 9.1.0
152
+     */
153
+    public function onAppDisabled($appId) {
154
+        $appInfo = \OC_App::getAppInfo($appId); // hello static legacy
155
+
156
+        if (isset($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) {
157
+            $this->mapper->remove(Mapper::TABLE_ADMIN_SECTIONS, trim($appInfo['settings'][IManager::KEY_ADMIN_SECTION], '\\'));
158
+        }
159
+        if (isset($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) {
160
+            $this->mapper->remove(Mapper::TABLE_ADMIN_SETTINGS, trim($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS], '\\'));
161
+        }
162
+
163
+        if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SECTION])) {
164
+            $this->mapper->remove(Mapper::TABLE_PERSONAL_SECTIONS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SECTION], '\\'));
165
+        }
166
+        if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS])) {
167
+            $this->mapper->remove(Mapper::TABLE_PERSONAL_SETTINGS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS], '\\'));
168
+        }
169
+    }
170
+
171
+    public function checkForOrphanedClassNames() {
172
+        $tables = [Mapper::TABLE_ADMIN_SECTIONS, Mapper::TABLE_ADMIN_SETTINGS, Mapper::TABLE_PERSONAL_SECTIONS, Mapper::TABLE_PERSONAL_SETTINGS];
173
+        foreach ($tables as $table) {
174
+            $classes = $this->mapper->getClasses($table);
175
+            foreach ($classes as $className) {
176
+                try {
177
+                    \OC::$server->query($className);
178
+                } catch (QueryException $e) {
179
+                    $this->mapper->remove($table, $className);
180
+                }
181
+            }
182
+        }
183
+    }
184
+
185
+    /**
186
+     * @param string $sectionClassName
187
+     * @param string $type either 'admin' or 'personal'
188
+     */
189
+    private function setupSectionEntry($sectionClassName, $type) {
190
+        if (!class_exists($sectionClassName)) {
191
+            $this->log->debug('Could not find ' . ucfirst($type) . ' section class ' . $sectionClassName);
192
+            return;
193
+        }
194
+        try {
195
+            $section = $this->query($sectionClassName);
196
+        } catch (QueryException $e) {
197
+            // cancel
198
+            return;
199
+        }
200
+
201
+        if (!$section instanceof ISection) {
202
+            $this->log->error(
203
+                ucfirst($type) .' section instance must implement \OCP\ISection. Invalid class: {class}',
204
+                ['class' => $sectionClassName]
205
+            );
206
+            return;
207
+        }
208
+        $table = $this->getSectionTableForType($type);
209
+        if(!$this->hasSection(get_class($section), $table)) {
210
+            $this->addSection($section, $table);
211
+        } else {
212
+            $this->updateSection($section, $table);
213
+        }
214
+    }
215
+
216
+    private function addSection(ISection $section, $table) {
217
+        $this->mapper->add($table, [
218
+            'id' => $section->getID(),
219
+            'class' => get_class($section),
220
+            'priority' => $section->getPriority(),
221
+        ]);
222
+    }
223
+
224
+    private function addSettings(ISettings $settings, $table) {
225
+        $this->mapper->add($table, [
226
+            'class' => get_class($settings),
227
+            'section' => $settings->getSection(),
228
+            'priority' => $settings->getPriority(),
229
+        ]);
230
+    }
231
+
232
+    private function updateSettings(ISettings $settings, $table) {
233
+        $this->mapper->update(
234
+            $table,
235
+            'class',
236
+            get_class($settings),
237
+            [
238
+                'section' => $settings->getSection(),
239
+                'priority' => $settings->getPriority(),
240
+            ]
241
+        );
242
+    }
243
+
244
+    private function updateSection(ISection $section, $table) {
245
+        $this->mapper->update(
246
+            $table,
247
+            'class',
248
+            get_class($section),
249
+            [
250
+                'id' => $section->getID(),
251
+                'priority' => $section->getPriority(),
252
+            ]
253
+        );
254
+    }
255
+
256
+    /**
257
+     * @param string $className
258
+     * @param string $table
259
+     * @return bool
260
+     */
261
+    private function hasSection($className, $table) {
262
+        return $this->mapper->has($table, $className);
263
+    }
264
+
265
+    /**
266
+     * @param string $className
267
+     * @return bool
268
+     */
269
+    private function hasSettings($className, $table) {
270
+        return $this->mapper->has($table, $className);
271
+    }
272
+
273
+    private function setupSettingsEntry($settingsClassName, $type) {
274
+        if (!class_exists($settingsClassName)) {
275
+            $this->log->debug('Could not find ' . $type . ' section class ' . $settingsClassName);
276
+            return;
277
+        }
278
+
279
+        try {
280
+            /** @var ISettings $settings */
281
+            $settings = $this->query($settingsClassName);
282
+        } catch (QueryException $e) {
283
+            // cancel
284
+            return;
285
+        }
286
+
287
+        if (!$settings instanceof ISettings) {
288
+            $this->log->error(
289
+                ucfirst($type) . ' section instance must implement \OCP\Settings\ISettings. Invalid class: {class}',
290
+                ['class' => $settingsClassName]
291
+            );
292
+            return;
293
+        }
294
+        $table = $this->getSettingsTableForType($type);
295
+        if (!$this->hasSettings(get_class($settings), $table)) {
296
+            $this->addSettings($settings, $table);
297
+        } else {
298
+            $this->updateSettings($settings, $table);
299
+        }
300
+    }
301
+
302
+    private function getSectionTableForType($type) {
303
+        if($type === 'admin') {
304
+            return Mapper::TABLE_ADMIN_SECTIONS;
305
+        } else if($type === 'personal') {
306
+            return Mapper::TABLE_PERSONAL_SECTIONS;
307
+        }
308
+        throw new \InvalidArgumentException('"admin" or "personal" expected');
309
+    }
310
+
311
+    private function getSettingsTableForType($type) {
312
+        if($type === 'admin') {
313
+            return Mapper::TABLE_ADMIN_SETTINGS;
314
+        } else if($type === 'personal') {
315
+            return Mapper::TABLE_PERSONAL_SETTINGS;
316
+        }
317
+        throw new \InvalidArgumentException('"admin" or "personal" expected');
318
+    }
319
+
320
+    private function query($className) {
321
+        try {
322
+            return \OC::$server->query($className);
323
+        } catch (QueryException $e) {
324
+            $this->log->logException($e);
325
+            throw $e;
326
+        }
327
+    }
328
+
329
+    /**
330
+     * @inheritdoc
331
+     */
332
+    public function getAdminSections() {
333
+        // built-in sections
334
+        $sections = [
335
+            0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))],
336
+            5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))],
337
+            10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
338
+            45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
339
+            98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
340
+            99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))],
341
+        ];
342
+
343
+        $rows = $this->mapper->getAdminSectionsFromDB();
344
+
345
+        foreach ($rows as $row) {
346
+            if (!isset($sections[$row['priority']])) {
347
+                $sections[$row['priority']] = [];
348
+            }
349
+            try {
350
+                $sections[$row['priority']][] = $this->query($row['class']);
351
+            } catch (QueryException $e) {
352
+                // skip
353
+            }
354
+        }
355
+
356
+        ksort($sections);
357
+
358
+        return $sections;
359
+    }
360
+
361
+    /**
362
+     * @param string $section
363
+     * @return ISection[]
364
+     */
365
+    private function getBuiltInAdminSettings($section) {
366
+        $forms = [];
367
+        try {
368
+            if ($section === 'server') {
369
+                /** @var ISettings $form */
370
+                $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l);
371
+                $forms[$form->getPriority()] = [$form];
372
+                $form = new Admin\ServerDevNotice();
373
+                $forms[$form->getPriority()] = [$form];
374
+            }
375
+            if ($section === 'encryption') {
376
+                /** @var ISettings $form */
377
+                $form = new Admin\Encryption($this->encryptionManager, $this->userManager);
378
+                $forms[$form->getPriority()] = [$form];
379
+            }
380
+            if ($section === 'sharing') {
381
+                /** @var ISettings $form */
382
+                $form = new Admin\Sharing($this->config);
383
+                $forms[$form->getPriority()] = [$form];
384
+            }
385
+            if ($section === 'additional') {
386
+                /** @var ISettings $form */
387
+                $form = new Admin\Additional($this->config);
388
+                $forms[$form->getPriority()] = [$form];
389
+            }
390
+            if ($section === 'tips-tricks') {
391
+                /** @var ISettings $form */
392
+                $form = new Admin\TipsTricks($this->config);
393
+                $forms[$form->getPriority()] = [$form];
394
+            }
395
+        } catch (QueryException $e) {
396
+            // skip
397
+        }
398
+        return $forms;
399
+    }
400
+
401
+    /**
402
+     * @param string $section
403
+     * @return ISection[]
404
+     */
405
+    private function getBuiltInPersonalSettings($section) {
406
+        $forms = [];
407
+        try {
408
+            if ($section === 'personal-info') {
409
+                /** @var ISettings $form */
410
+                $form = new Personal\PersonalInfo(
411
+                    $this->config,
412
+                    $this->userManager,
413
+                    $this->groupManager,
414
+                    $this->accountManager,
415
+                    $this->appManager,
416
+                    $this->l10nFactory,
417
+                    $this->l
418
+                );
419
+                $forms[$form->getPriority()] = [$form];
420
+            }
421
+            if($section === 'security') {
422
+                /** @var ISettings $form */
423
+                $form = new Personal\Security();
424
+                $forms[$form->getPriority()] = [$form];
425
+            }
426
+            if($section === 'sync-clients') {
427
+                /** @var ISettings $form */
428
+                $form = new Personal\SyncClients($this->config, $this->defaults);
429
+                $forms[$form->getPriority()] = [$form];
430
+            }
431
+            if ($section === 'additional') {
432
+                /** @var ISettings $form */
433
+                $form = new Personal\Additional($this->config);
434
+                $forms[$form->getPriority()] = [$form];
435
+            }
436
+        } catch (QueryException $e) {
437
+            // skip
438
+        }
439
+        return $forms;
440
+    }
441
+
442
+    /**
443
+     * @inheritdoc
444
+     */
445
+    public function getAdminSettings($section) {
446
+        $settings = $this->getBuiltInAdminSettings($section);
447
+        $dbRows = $this->mapper->getAdminSettingsFromDB($section);
448
+
449
+        foreach ($dbRows as $row) {
450
+            if (!isset($settings[$row['priority']])) {
451
+                $settings[$row['priority']] = [];
452
+            }
453
+            try {
454
+                $settings[$row['priority']][] = $this->query($row['class']);
455
+            } catch (QueryException $e) {
456
+                // skip
457
+            }
458
+        }
459
+
460
+        ksort($settings);
461
+        return $settings;
462
+    }
463
+
464
+    /**
465
+     * @inheritdoc
466
+     */
467
+    public function getPersonalSections() {
468
+        $sections = [
469
+            0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))],
470
+            5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))],
471
+            15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))],
472
+        ];
473
+
474
+        $legacyForms = \OC_App::getForms('personal');
475
+        if(count($legacyForms) > 0 && $this->hasLegacyPersonalSettingsToRender($legacyForms)) {
476
+            $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))];
477
+        }
478
+
479
+        $rows = $this->mapper->getPersonalSectionsFromDB();
480
+
481
+        foreach ($rows as $row) {
482
+            if (!isset($sections[$row['priority']])) {
483
+                $sections[$row['priority']] = [];
484
+            }
485
+            try {
486
+                $sections[$row['priority']][] = $this->query($row['class']);
487
+            } catch (QueryException $e) {
488
+                // skip
489
+            }
490
+        }
491
+
492
+        ksort($sections);
493
+
494
+        return $sections;
495
+    }
496
+
497
+    /**
498
+     * @param $forms
499
+     * @return bool
500
+     */
501
+    private function hasLegacyPersonalSettingsToRender($forms) {
502
+        foreach ($forms as $form) {
503
+            if(trim($form) !== '') {
504
+                return true;
505
+            }
506
+        }
507
+        return false;
508
+    }
509
+
510
+    /**
511
+     * @inheritdoc
512
+     */
513
+    public function getPersonalSettings($section) {
514
+        $settings = $this->getBuiltInPersonalSettings($section);
515
+        $dbRows = $this->mapper->getPersonalSettingsFromDB($section);
516
+
517
+        foreach ($dbRows as $row) {
518
+            if (!isset($settings[$row['priority']])) {
519
+                $settings[$row['priority']] = [];
520
+            }
521
+            try {
522
+                $settings[$row['priority']][] = $this->query($row['class']);
523
+            } catch (QueryException $e) {
524
+                // skip
525
+            }
526
+        }
527
+
528
+        ksort($settings);
529
+        return $settings;
530
+    }
531 531
 }
Please login to merge, or discard this patch.
settings/templates/settings/empty.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,5 +21,5 @@
 block discarded – undo
21 21
  *
22 22
  */
23 23
 
24
-	# used for Personal/Additional settings as fallback for legacy settings
24
+    # used for Personal/Additional settings as fallback for legacy settings
25 25
 ?>
Please login to merge, or discard this patch.
apps/twofactor_backupcodes/lib/Settings/PersonalSection.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -32,67 +32,67 @@
 block discarded – undo
32 32
 
33 33
 class PersonalSection implements IIconSection {
34 34
 
35
-	/** @var IURLGenerator */
36
-	private $urlGenerator;
37
-	/** @var IL10N */
38
-	private $l;
39
-	/** @var BackupCodesProvider */
40
-	private $provider;
41
-	/** @var IUserSession */
42
-	private $userSession;
35
+    /** @var IURLGenerator */
36
+    private $urlGenerator;
37
+    /** @var IL10N */
38
+    private $l;
39
+    /** @var BackupCodesProvider */
40
+    private $provider;
41
+    /** @var IUserSession */
42
+    private $userSession;
43 43
 
44
-	public function __construct(IURLGenerator $urlGenerator, IL10N $l, BackupCodesProvider $provider, IUserSession $userSession) {
45
-		$this->urlGenerator = $urlGenerator;
46
-		$this->l = $l;
47
-		$this->provider = $provider;
48
-		$this->userSession = $userSession;
49
-	}
44
+    public function __construct(IURLGenerator $urlGenerator, IL10N $l, BackupCodesProvider $provider, IUserSession $userSession) {
45
+        $this->urlGenerator = $urlGenerator;
46
+        $this->l = $l;
47
+        $this->provider = $provider;
48
+        $this->userSession = $userSession;
49
+    }
50 50
 
51
-	/**
52
-	 * returns the relative path to an 16*16 icon describing the section.
53
-	 * e.g. '/core/img/places/files.svg'
54
-	 *
55
-	 * @returns string
56
-	 * @since 12
57
-	 */
58
-	public function getIcon() {
59
-		return $this->urlGenerator->imagePath('settings', 'password.svg');
60
-	}
51
+    /**
52
+     * returns the relative path to an 16*16 icon describing the section.
53
+     * e.g. '/core/img/places/files.svg'
54
+     *
55
+     * @returns string
56
+     * @since 12
57
+     */
58
+    public function getIcon() {
59
+        return $this->urlGenerator->imagePath('settings', 'password.svg');
60
+    }
61 61
 
62
-	/**
63
-	 * returns the ID of the section. It is supposed to be a lower case string,
64
-	 * e.g. 'ldap'
65
-	 *
66
-	 * @returns string
67
-	 * @since 9.1
68
-	 */
69
-	public function getID() {
70
-		if (!$this->provider->isActive($this->userSession->getUser())) {
71
-			return null;
72
-		}
73
-		return 'twofactor';
74
-	}
62
+    /**
63
+     * returns the ID of the section. It is supposed to be a lower case string,
64
+     * e.g. 'ldap'
65
+     *
66
+     * @returns string
67
+     * @since 9.1
68
+     */
69
+    public function getID() {
70
+        if (!$this->provider->isActive($this->userSession->getUser())) {
71
+            return null;
72
+        }
73
+        return 'twofactor';
74
+    }
75 75
 
76
-	/**
77
-	 * returns the translated name as it should be displayed, e.g. 'LDAP / AD
78
-	 * integration'. Use the L10N service to translate it.
79
-	 *
80
-	 * @return string
81
-	 * @since 9.1
82
-	 */
83
-	public function getName() {
84
-		return $this->l->t('Second factor auth');
85
-	}
76
+    /**
77
+     * returns the translated name as it should be displayed, e.g. 'LDAP / AD
78
+     * integration'. Use the L10N service to translate it.
79
+     *
80
+     * @return string
81
+     * @since 9.1
82
+     */
83
+    public function getName() {
84
+        return $this->l->t('Second factor auth');
85
+    }
86 86
 
87
-	/**
88
-	 * @return int whether the form should be rather on the top or bottom of
89
-	 * the settings navigation. The sections are arranged in ascending order of
90
-	 * the priority values. It is required to return a value between 0 and 99.
91
-	 *
92
-	 * E.g.: 70
93
-	 * @since 9.1
94
-	 */
95
-	public function getPriority() {
96
-		return 8;
97
-	}
87
+    /**
88
+     * @return int whether the form should be rather on the top or bottom of
89
+     * the settings navigation. The sections are arranged in ascending order of
90
+     * the priority values. It is required to return a value between 0 and 99.
91
+     *
92
+     * E.g.: 70
93
+     * @since 9.1
94
+     */
95
+    public function getPriority() {
96
+        return 8;
97
+    }
98 98
 }
Please login to merge, or discard this patch.
apps/twofactor_backupcodes/lib/Settings/Personal.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -32,51 +32,51 @@
 block discarded – undo
32 32
 
33 33
 class Personal implements ISettings {
34 34
 
35
-	/** @var Application */
36
-	private $app;
37
-	/** @var BackupCodesProvider */
38
-	private $provider;
39
-	/** @var IUserSession */
40
-	private $userSession;
35
+    /** @var Application */
36
+    private $app;
37
+    /** @var BackupCodesProvider */
38
+    private $provider;
39
+    /** @var IUserSession */
40
+    private $userSession;
41 41
 
42
-	public function __construct(Application $app, BackupCodesProvider $provider, IUserSession $userSession) {
43
-		$this->app = $app;
44
-		$this->provider = $provider;
45
-		$this->userSession = $userSession;
46
-	}
42
+    public function __construct(Application $app, BackupCodesProvider $provider, IUserSession $userSession) {
43
+        $this->app = $app;
44
+        $this->provider = $provider;
45
+        $this->userSession = $userSession;
46
+    }
47 47
 
48
-	/**
49
-	 * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
50
-	 * @since 9.1
51
-	 */
52
-	public function getForm() {
53
-		$templateOwner = 'settings';
54
-		$templateName = 'settings/empty';
55
-		if ($this->provider->isActive($this->userSession->getUser())) {
56
-			$templateOwner = $this->app->getContainer()->getAppName();
57
-			$templateName = 'personal';
58
-		}
48
+    /**
49
+     * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
50
+     * @since 9.1
51
+     */
52
+    public function getForm() {
53
+        $templateOwner = 'settings';
54
+        $templateName = 'settings/empty';
55
+        if ($this->provider->isActive($this->userSession->getUser())) {
56
+            $templateOwner = $this->app->getContainer()->getAppName();
57
+            $templateName = 'personal';
58
+        }
59 59
 
60
-		return new TemplateResponse($templateOwner, $templateName, [], '');
61
-	}
60
+        return new TemplateResponse($templateOwner, $templateName, [], '');
61
+    }
62 62
 
63
-	/**
64
-	 * @return string the section ID, e.g. 'sharing'
65
-	 * @since 9.1
66
-	 */
67
-	public function getSection() {
68
-		return 'twofactor';
69
-	}
63
+    /**
64
+     * @return string the section ID, e.g. 'sharing'
65
+     * @since 9.1
66
+     */
67
+    public function getSection() {
68
+        return 'twofactor';
69
+    }
70 70
 
71
-	/**
72
-	 * @return int whether the form should be rather on the top or bottom of
73
-	 * the admin section. The forms are arranged in ascending order of the
74
-	 * priority values. It is required to return a value between 0 and 100.
75
-	 *
76
-	 * E.g.: 70
77
-	 * @since 9.1
78
-	 */
79
-	public function getPriority() {
80
-		return 85;
81
-	}
71
+    /**
72
+     * @return int whether the form should be rather on the top or bottom of
73
+     * the admin section. The forms are arranged in ascending order of the
74
+     * priority values. It is required to return a value between 0 and 100.
75
+     *
76
+     * E.g.: 70
77
+     * @since 9.1
78
+     */
79
+    public function getPriority() {
80
+        return 85;
81
+    }
82 82
 }
Please login to merge, or discard this patch.
apps/twofactor_backupcodes/lib/AppInfo/Application.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -28,27 +28,27 @@
 block discarded – undo
28 28
 use OCP\Util;
29 29
 
30 30
 class Application extends App {
31
-	public function __construct () {
32
-		parent::__construct('twofactor_backupcodes');
33
-	}
31
+    public function __construct () {
32
+        parent::__construct('twofactor_backupcodes');
33
+    }
34 34
 
35
-	/**
36
-	 * Register the different app parts
37
-	 */
38
-	public function register() {
39
-		$this->registerHooksAndEvents();
40
-	}
35
+    /**
36
+     * Register the different app parts
37
+     */
38
+    public function register() {
39
+        $this->registerHooksAndEvents();
40
+    }
41 41
 
42
-	/**
43
-	 * Register the hooks and events
44
-	 */
45
-	public function registerHooksAndEvents() {
46
-		Util::connectHook('OC_User', 'post_deleteUser', $this, 'deleteUser');
47
-	}
42
+    /**
43
+     * Register the hooks and events
44
+     */
45
+    public function registerHooksAndEvents() {
46
+        Util::connectHook('OC_User', 'post_deleteUser', $this, 'deleteUser');
47
+    }
48 48
 
49
-	public function deleteUser($params) {
50
-		/** @var BackupCodeMapper $mapper */
51
-		$mapper = $this->getContainer()->query(BackupCodeMapper::class);
52
-		$mapper->deleteCodesByUserId($params['uid']);
53
-	}
49
+    public function deleteUser($params) {
50
+        /** @var BackupCodeMapper $mapper */
51
+        $mapper = $this->getContainer()->query(BackupCodeMapper::class);
52
+        $mapper->deleteCodesByUserId($params['uid']);
53
+    }
54 54
 }
Please login to merge, or discard this patch.