Passed
Push — master ( 4908d8...fbbdc6 )
by Joas
16:12 queued 12s
created
lib/private/AppConfig.php 1 patch
Indentation   +386 added lines, -386 removed lines patch added patch discarded remove patch
@@ -43,399 +43,399 @@
 block discarded – undo
43 43
  * database.
44 44
  */
45 45
 class AppConfig implements IAppConfig {
46
-	/** @var array[] */
47
-	protected $sensitiveValues = [
48
-		'circles' => [
49
-			'/^key_pairs$/',
50
-			'/^local_gskey$/',
51
-		],
52
-		'external' => [
53
-			'/^sites$/',
54
-		],
55
-		'integration_discourse' => [
56
-			'/^private_key$/',
57
-			'/^public_key$/',
58
-		],
59
-		'integration_dropbox' => [
60
-			'/^client_id$/',
61
-			'/^client_secret$/',
62
-		],
63
-		'integration_github' => [
64
-			'/^client_id$/',
65
-			'/^client_secret$/',
66
-		],
67
-		'integration_gitlab' => [
68
-			'/^client_id$/',
69
-			'/^client_secret$/',
70
-			'/^oauth_instance_url$/',
71
-		],
72
-		'integration_google' => [
73
-			'/^client_id$/',
74
-			'/^client_secret$/',
75
-		],
76
-		'integration_jira' => [
77
-			'/^client_id$/',
78
-			'/^client_secret$/',
79
-			'/^forced_instance_url$/',
80
-		],
81
-		'integration_onedrive' => [
82
-			'/^client_id$/',
83
-			'/^client_secret$/',
84
-		],
85
-		'integration_openproject' => [
86
-			'/^client_id$/',
87
-			'/^client_secret$/',
88
-			'/^oauth_instance_url$/',
89
-		],
90
-		'integration_reddit' => [
91
-			'/^client_id$/',
92
-			'/^client_secret$/',
93
-		],
94
-		'integration_suitecrm' => [
95
-			'/^client_id$/',
96
-			'/^client_secret$/',
97
-			'/^oauth_instance_url$/',
98
-		],
99
-		'integration_twitter' => [
100
-			'/^consumer_key$/',
101
-			'/^consumer_secret$/',
102
-			'/^followed_user$/',
103
-		],
104
-		'integration_zammad' => [
105
-			'/^client_id$/',
106
-			'/^client_secret$/',
107
-			'/^oauth_instance_url$/',
108
-		],
109
-		'notify_push' => [
110
-			'/^cookie$/',
111
-		],
112
-		'spreed' => [
113
-			'/^bridge_bot_password$/',
114
-			'/^hosted-signaling-server-(.*)$/',
115
-			'/^signaling_servers$/',
116
-			'/^signaling_ticket_secret$/',
117
-			'/^signaling_token_privkey_(.*)$/',
118
-			'/^signaling_token_pubkey_(.*)$/',
119
-			'/^sip_bridge_dialin_info$/',
120
-			'/^sip_bridge_shared_secret$/',
121
-			'/^stun_servers$/',
122
-			'/^turn_servers$/',
123
-			'/^turn_server_secret$/',
124
-		],
125
-		'support' => [
126
-			'/^last_response$/',
127
-			'/^potential_subscription_key$/',
128
-			'/^subscription_key$/',
129
-		],
130
-		'theming' => [
131
-			'/^imprintUrl$/',
132
-			'/^privacyUrl$/',
133
-			'/^slogan$/',
134
-			'/^url$/',
135
-		],
136
-		'user_ldap' => [
137
-			'/^(s..)?ldap_agent_password$/',
138
-		],
139
-		'user_saml' => [
140
-			'/^idp-x509cert$/',
141
-		],
142
-	];
143
-
144
-	/** @var Connection */
145
-	protected $conn;
146
-
147
-	/** @var array[] */
148
-	private $cache = [];
149
-
150
-	/** @var bool */
151
-	private $configLoaded = false;
152
-
153
-	/**
154
-	 * @param Connection $conn
155
-	 */
156
-	public function __construct(Connection $conn) {
157
-		$this->conn = $conn;
158
-	}
159
-
160
-	/**
161
-	 * @param string $app
162
-	 * @return array
163
-	 */
164
-	private function getAppValues($app) {
165
-		$this->loadConfigValues();
166
-
167
-		if (isset($this->cache[$app])) {
168
-			return $this->cache[$app];
169
-		}
170
-
171
-		return [];
172
-	}
173
-
174
-	/**
175
-	 * Get all apps using the config
176
-	 *
177
-	 * @return array an array of app ids
178
-	 *
179
-	 * This function returns a list of all apps that have at least one
180
-	 * entry in the appconfig table.
181
-	 */
182
-	public function getApps() {
183
-		$this->loadConfigValues();
184
-
185
-		return $this->getSortedKeys($this->cache);
186
-	}
187
-
188
-	/**
189
-	 * Get the available keys for an app
190
-	 *
191
-	 * @param string $app the app we are looking for
192
-	 * @return array an array of key names
193
-	 *
194
-	 * This function gets all keys of an app. Please note that the values are
195
-	 * not returned.
196
-	 */
197
-	public function getKeys($app) {
198
-		$this->loadConfigValues();
199
-
200
-		if (isset($this->cache[$app])) {
201
-			return $this->getSortedKeys($this->cache[$app]);
202
-		}
203
-
204
-		return [];
205
-	}
206
-
207
-	public function getSortedKeys($data) {
208
-		$keys = array_keys($data);
209
-		sort($keys);
210
-		return $keys;
211
-	}
212
-
213
-	/**
214
-	 * Gets the config value
215
-	 *
216
-	 * @param string $app app
217
-	 * @param string $key key
218
-	 * @param string $default = null, default value if the key does not exist
219
-	 * @return string the value or $default
220
-	 *
221
-	 * This function gets a value from the appconfig table. If the key does
222
-	 * not exist the default value will be returned
223
-	 */
224
-	public function getValue($app, $key, $default = null) {
225
-		$this->loadConfigValues();
226
-
227
-		if ($this->hasKey($app, $key)) {
228
-			return $this->cache[$app][$key];
229
-		}
230
-
231
-		return $default;
232
-	}
233
-
234
-	/**
235
-	 * check if a key is set in the appconfig
236
-	 *
237
-	 * @param string $app
238
-	 * @param string $key
239
-	 * @return bool
240
-	 */
241
-	public function hasKey($app, $key) {
242
-		$this->loadConfigValues();
243
-
244
-		return isset($this->cache[$app][$key]);
245
-	}
246
-
247
-	/**
248
-	 * Sets a value. If the key did not exist before it will be created.
249
-	 *
250
-	 * @param string $app app
251
-	 * @param string $key key
252
-	 * @param string|float|int $value value
253
-	 * @return bool True if the value was inserted or updated, false if the value was the same
254
-	 */
255
-	public function setValue($app, $key, $value) {
256
-		if (!$this->hasKey($app, $key)) {
257
-			$inserted = (bool) $this->conn->insertIfNotExist('*PREFIX*appconfig', [
258
-				'appid' => $app,
259
-				'configkey' => $key,
260
-				'configvalue' => $value,
261
-			], [
262
-				'appid',
263
-				'configkey',
264
-			]);
265
-
266
-			if ($inserted) {
267
-				if (!isset($this->cache[$app])) {
268
-					$this->cache[$app] = [];
269
-				}
270
-
271
-				$this->cache[$app][$key] = $value;
272
-				return true;
273
-			}
274
-		}
275
-
276
-		$sql = $this->conn->getQueryBuilder();
277
-		$sql->update('appconfig')
278
-			->set('configvalue', $sql->createNamedParameter($value))
279
-			->where($sql->expr()->eq('appid', $sql->createNamedParameter($app)))
280
-			->andWhere($sql->expr()->eq('configkey', $sql->createNamedParameter($key)));
281
-
282
-		/*
46
+    /** @var array[] */
47
+    protected $sensitiveValues = [
48
+        'circles' => [
49
+            '/^key_pairs$/',
50
+            '/^local_gskey$/',
51
+        ],
52
+        'external' => [
53
+            '/^sites$/',
54
+        ],
55
+        'integration_discourse' => [
56
+            '/^private_key$/',
57
+            '/^public_key$/',
58
+        ],
59
+        'integration_dropbox' => [
60
+            '/^client_id$/',
61
+            '/^client_secret$/',
62
+        ],
63
+        'integration_github' => [
64
+            '/^client_id$/',
65
+            '/^client_secret$/',
66
+        ],
67
+        'integration_gitlab' => [
68
+            '/^client_id$/',
69
+            '/^client_secret$/',
70
+            '/^oauth_instance_url$/',
71
+        ],
72
+        'integration_google' => [
73
+            '/^client_id$/',
74
+            '/^client_secret$/',
75
+        ],
76
+        'integration_jira' => [
77
+            '/^client_id$/',
78
+            '/^client_secret$/',
79
+            '/^forced_instance_url$/',
80
+        ],
81
+        'integration_onedrive' => [
82
+            '/^client_id$/',
83
+            '/^client_secret$/',
84
+        ],
85
+        'integration_openproject' => [
86
+            '/^client_id$/',
87
+            '/^client_secret$/',
88
+            '/^oauth_instance_url$/',
89
+        ],
90
+        'integration_reddit' => [
91
+            '/^client_id$/',
92
+            '/^client_secret$/',
93
+        ],
94
+        'integration_suitecrm' => [
95
+            '/^client_id$/',
96
+            '/^client_secret$/',
97
+            '/^oauth_instance_url$/',
98
+        ],
99
+        'integration_twitter' => [
100
+            '/^consumer_key$/',
101
+            '/^consumer_secret$/',
102
+            '/^followed_user$/',
103
+        ],
104
+        'integration_zammad' => [
105
+            '/^client_id$/',
106
+            '/^client_secret$/',
107
+            '/^oauth_instance_url$/',
108
+        ],
109
+        'notify_push' => [
110
+            '/^cookie$/',
111
+        ],
112
+        'spreed' => [
113
+            '/^bridge_bot_password$/',
114
+            '/^hosted-signaling-server-(.*)$/',
115
+            '/^signaling_servers$/',
116
+            '/^signaling_ticket_secret$/',
117
+            '/^signaling_token_privkey_(.*)$/',
118
+            '/^signaling_token_pubkey_(.*)$/',
119
+            '/^sip_bridge_dialin_info$/',
120
+            '/^sip_bridge_shared_secret$/',
121
+            '/^stun_servers$/',
122
+            '/^turn_servers$/',
123
+            '/^turn_server_secret$/',
124
+        ],
125
+        'support' => [
126
+            '/^last_response$/',
127
+            '/^potential_subscription_key$/',
128
+            '/^subscription_key$/',
129
+        ],
130
+        'theming' => [
131
+            '/^imprintUrl$/',
132
+            '/^privacyUrl$/',
133
+            '/^slogan$/',
134
+            '/^url$/',
135
+        ],
136
+        'user_ldap' => [
137
+            '/^(s..)?ldap_agent_password$/',
138
+        ],
139
+        'user_saml' => [
140
+            '/^idp-x509cert$/',
141
+        ],
142
+    ];
143
+
144
+    /** @var Connection */
145
+    protected $conn;
146
+
147
+    /** @var array[] */
148
+    private $cache = [];
149
+
150
+    /** @var bool */
151
+    private $configLoaded = false;
152
+
153
+    /**
154
+     * @param Connection $conn
155
+     */
156
+    public function __construct(Connection $conn) {
157
+        $this->conn = $conn;
158
+    }
159
+
160
+    /**
161
+     * @param string $app
162
+     * @return array
163
+     */
164
+    private function getAppValues($app) {
165
+        $this->loadConfigValues();
166
+
167
+        if (isset($this->cache[$app])) {
168
+            return $this->cache[$app];
169
+        }
170
+
171
+        return [];
172
+    }
173
+
174
+    /**
175
+     * Get all apps using the config
176
+     *
177
+     * @return array an array of app ids
178
+     *
179
+     * This function returns a list of all apps that have at least one
180
+     * entry in the appconfig table.
181
+     */
182
+    public function getApps() {
183
+        $this->loadConfigValues();
184
+
185
+        return $this->getSortedKeys($this->cache);
186
+    }
187
+
188
+    /**
189
+     * Get the available keys for an app
190
+     *
191
+     * @param string $app the app we are looking for
192
+     * @return array an array of key names
193
+     *
194
+     * This function gets all keys of an app. Please note that the values are
195
+     * not returned.
196
+     */
197
+    public function getKeys($app) {
198
+        $this->loadConfigValues();
199
+
200
+        if (isset($this->cache[$app])) {
201
+            return $this->getSortedKeys($this->cache[$app]);
202
+        }
203
+
204
+        return [];
205
+    }
206
+
207
+    public function getSortedKeys($data) {
208
+        $keys = array_keys($data);
209
+        sort($keys);
210
+        return $keys;
211
+    }
212
+
213
+    /**
214
+     * Gets the config value
215
+     *
216
+     * @param string $app app
217
+     * @param string $key key
218
+     * @param string $default = null, default value if the key does not exist
219
+     * @return string the value or $default
220
+     *
221
+     * This function gets a value from the appconfig table. If the key does
222
+     * not exist the default value will be returned
223
+     */
224
+    public function getValue($app, $key, $default = null) {
225
+        $this->loadConfigValues();
226
+
227
+        if ($this->hasKey($app, $key)) {
228
+            return $this->cache[$app][$key];
229
+        }
230
+
231
+        return $default;
232
+    }
233
+
234
+    /**
235
+     * check if a key is set in the appconfig
236
+     *
237
+     * @param string $app
238
+     * @param string $key
239
+     * @return bool
240
+     */
241
+    public function hasKey($app, $key) {
242
+        $this->loadConfigValues();
243
+
244
+        return isset($this->cache[$app][$key]);
245
+    }
246
+
247
+    /**
248
+     * Sets a value. If the key did not exist before it will be created.
249
+     *
250
+     * @param string $app app
251
+     * @param string $key key
252
+     * @param string|float|int $value value
253
+     * @return bool True if the value was inserted or updated, false if the value was the same
254
+     */
255
+    public function setValue($app, $key, $value) {
256
+        if (!$this->hasKey($app, $key)) {
257
+            $inserted = (bool) $this->conn->insertIfNotExist('*PREFIX*appconfig', [
258
+                'appid' => $app,
259
+                'configkey' => $key,
260
+                'configvalue' => $value,
261
+            ], [
262
+                'appid',
263
+                'configkey',
264
+            ]);
265
+
266
+            if ($inserted) {
267
+                if (!isset($this->cache[$app])) {
268
+                    $this->cache[$app] = [];
269
+                }
270
+
271
+                $this->cache[$app][$key] = $value;
272
+                return true;
273
+            }
274
+        }
275
+
276
+        $sql = $this->conn->getQueryBuilder();
277
+        $sql->update('appconfig')
278
+            ->set('configvalue', $sql->createNamedParameter($value))
279
+            ->where($sql->expr()->eq('appid', $sql->createNamedParameter($app)))
280
+            ->andWhere($sql->expr()->eq('configkey', $sql->createNamedParameter($key)));
281
+
282
+        /*
283 283
 		 * Only limit to the existing value for non-Oracle DBs:
284 284
 		 * http://docs.oracle.com/cd/E11882_01/server.112/e26088/conditions002.htm#i1033286
285 285
 		 * > Large objects (LOBs) are not supported in comparison conditions.
286 286
 		 */
287
-		if (!($this->conn instanceof OracleConnection)) {
288
-			/*
287
+        if (!($this->conn instanceof OracleConnection)) {
288
+            /*
289 289
 			 * Only update the value when it is not the same
290 290
 			 * Note that NULL requires some special handling. Since comparing
291 291
 			 * against null can have special results.
292 292
 			 */
293 293
 
294
-			if ($value === null) {
295
-				$sql->andWhere(
296
-					$sql->expr()->isNotNull('configvalue')
297
-				);
298
-			} else {
299
-				$sql->andWhere(
300
-					$sql->expr()->orX(
301
-						$sql->expr()->isNull('configvalue'),
302
-						$sql->expr()->neq('configvalue', $sql->createNamedParameter($value), IQueryBuilder::PARAM_STR)
303
-					)
304
-				);
305
-			}
306
-		}
307
-
308
-		$changedRow = (bool) $sql->execute();
309
-
310
-		$this->cache[$app][$key] = $value;
311
-
312
-		return $changedRow;
313
-	}
314
-
315
-	/**
316
-	 * Deletes a key
317
-	 *
318
-	 * @param string $app app
319
-	 * @param string $key key
320
-	 * @return boolean
321
-	 */
322
-	public function deleteKey($app, $key) {
323
-		$this->loadConfigValues();
324
-
325
-		$sql = $this->conn->getQueryBuilder();
326
-		$sql->delete('appconfig')
327
-			->where($sql->expr()->eq('appid', $sql->createParameter('app')))
328
-			->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey')))
329
-			->setParameter('app', $app)
330
-			->setParameter('configkey', $key);
331
-		$sql->execute();
332
-
333
-		unset($this->cache[$app][$key]);
334
-		return false;
335
-	}
336
-
337
-	/**
338
-	 * Remove app from appconfig
339
-	 *
340
-	 * @param string $app app
341
-	 * @return boolean
342
-	 *
343
-	 * Removes all keys in appconfig belonging to the app.
344
-	 */
345
-	public function deleteApp($app) {
346
-		$this->loadConfigValues();
347
-
348
-		$sql = $this->conn->getQueryBuilder();
349
-		$sql->delete('appconfig')
350
-			->where($sql->expr()->eq('appid', $sql->createParameter('app')))
351
-			->setParameter('app', $app);
352
-		$sql->execute();
353
-
354
-		unset($this->cache[$app]);
355
-		return false;
356
-	}
357
-
358
-	/**
359
-	 * get multiple values, either the app or key can be used as wildcard by setting it to false
360
-	 *
361
-	 * @param string|false $app
362
-	 * @param string|false $key
363
-	 * @return array|false
364
-	 */
365
-	public function getValues($app, $key) {
366
-		if (($app !== false) === ($key !== false)) {
367
-			return false;
368
-		}
369
-
370
-		if ($key === false) {
371
-			return $this->getAppValues($app);
372
-		} else {
373
-			$appIds = $this->getApps();
374
-			$values = array_map(function ($appId) use ($key) {
375
-				return isset($this->cache[$appId][$key]) ? $this->cache[$appId][$key] : null;
376
-			}, $appIds);
377
-			$result = array_combine($appIds, $values);
378
-
379
-			return array_filter($result);
380
-		}
381
-	}
382
-
383
-	/**
384
-	 * get all values of the app or and filters out sensitive data
385
-	 *
386
-	 * @param string $app
387
-	 * @return array
388
-	 */
389
-	public function getFilteredValues($app) {
390
-		$values = $this->getValues($app, false);
391
-
392
-		if (isset($this->sensitiveValues[$app])) {
393
-			foreach ($this->sensitiveValues[$app] as $sensitiveKeyExp) {
394
-				$sensitiveKeys = preg_grep($sensitiveKeyExp, array_keys($values));
395
-				foreach ($sensitiveKeys as $sensitiveKey) {
396
-					$values[$sensitiveKey] = IConfig::SENSITIVE_VALUE;
397
-				}
398
-			}
399
-		}
400
-
401
-		return $values;
402
-	}
403
-
404
-	/**
405
-	 * Load all the app config values
406
-	 */
407
-	protected function loadConfigValues() {
408
-		if ($this->configLoaded) {
409
-			return;
410
-		}
411
-
412
-		$this->cache = [];
413
-
414
-		$sql = $this->conn->getQueryBuilder();
415
-		$sql->select('*')
416
-			->from('appconfig');
417
-		$result = $sql->execute();
418
-
419
-		// we are going to store the result in memory anyway
420
-		$rows = $result->fetchAll();
421
-		foreach ($rows as $row) {
422
-			if (!isset($this->cache[$row['appid']])) {
423
-				$this->cache[(string)$row['appid']] = [];
424
-			}
425
-
426
-			$this->cache[(string)$row['appid']][(string)$row['configkey']] = (string)$row['configvalue'];
427
-		}
428
-		$result->closeCursor();
429
-
430
-		$this->configLoaded = true;
431
-	}
432
-
433
-
434
-	/**
435
-	 * Clear all the cached app config values
436
-	 * New cache will be generated next time a config value is retrieved
437
-	 */
438
-	public function clearCachedConfig(): void {
439
-		$this->configLoaded = false;
440
-	}
294
+            if ($value === null) {
295
+                $sql->andWhere(
296
+                    $sql->expr()->isNotNull('configvalue')
297
+                );
298
+            } else {
299
+                $sql->andWhere(
300
+                    $sql->expr()->orX(
301
+                        $sql->expr()->isNull('configvalue'),
302
+                        $sql->expr()->neq('configvalue', $sql->createNamedParameter($value), IQueryBuilder::PARAM_STR)
303
+                    )
304
+                );
305
+            }
306
+        }
307
+
308
+        $changedRow = (bool) $sql->execute();
309
+
310
+        $this->cache[$app][$key] = $value;
311
+
312
+        return $changedRow;
313
+    }
314
+
315
+    /**
316
+     * Deletes a key
317
+     *
318
+     * @param string $app app
319
+     * @param string $key key
320
+     * @return boolean
321
+     */
322
+    public function deleteKey($app, $key) {
323
+        $this->loadConfigValues();
324
+
325
+        $sql = $this->conn->getQueryBuilder();
326
+        $sql->delete('appconfig')
327
+            ->where($sql->expr()->eq('appid', $sql->createParameter('app')))
328
+            ->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey')))
329
+            ->setParameter('app', $app)
330
+            ->setParameter('configkey', $key);
331
+        $sql->execute();
332
+
333
+        unset($this->cache[$app][$key]);
334
+        return false;
335
+    }
336
+
337
+    /**
338
+     * Remove app from appconfig
339
+     *
340
+     * @param string $app app
341
+     * @return boolean
342
+     *
343
+     * Removes all keys in appconfig belonging to the app.
344
+     */
345
+    public function deleteApp($app) {
346
+        $this->loadConfigValues();
347
+
348
+        $sql = $this->conn->getQueryBuilder();
349
+        $sql->delete('appconfig')
350
+            ->where($sql->expr()->eq('appid', $sql->createParameter('app')))
351
+            ->setParameter('app', $app);
352
+        $sql->execute();
353
+
354
+        unset($this->cache[$app]);
355
+        return false;
356
+    }
357
+
358
+    /**
359
+     * get multiple values, either the app or key can be used as wildcard by setting it to false
360
+     *
361
+     * @param string|false $app
362
+     * @param string|false $key
363
+     * @return array|false
364
+     */
365
+    public function getValues($app, $key) {
366
+        if (($app !== false) === ($key !== false)) {
367
+            return false;
368
+        }
369
+
370
+        if ($key === false) {
371
+            return $this->getAppValues($app);
372
+        } else {
373
+            $appIds = $this->getApps();
374
+            $values = array_map(function ($appId) use ($key) {
375
+                return isset($this->cache[$appId][$key]) ? $this->cache[$appId][$key] : null;
376
+            }, $appIds);
377
+            $result = array_combine($appIds, $values);
378
+
379
+            return array_filter($result);
380
+        }
381
+    }
382
+
383
+    /**
384
+     * get all values of the app or and filters out sensitive data
385
+     *
386
+     * @param string $app
387
+     * @return array
388
+     */
389
+    public function getFilteredValues($app) {
390
+        $values = $this->getValues($app, false);
391
+
392
+        if (isset($this->sensitiveValues[$app])) {
393
+            foreach ($this->sensitiveValues[$app] as $sensitiveKeyExp) {
394
+                $sensitiveKeys = preg_grep($sensitiveKeyExp, array_keys($values));
395
+                foreach ($sensitiveKeys as $sensitiveKey) {
396
+                    $values[$sensitiveKey] = IConfig::SENSITIVE_VALUE;
397
+                }
398
+            }
399
+        }
400
+
401
+        return $values;
402
+    }
403
+
404
+    /**
405
+     * Load all the app config values
406
+     */
407
+    protected function loadConfigValues() {
408
+        if ($this->configLoaded) {
409
+            return;
410
+        }
411
+
412
+        $this->cache = [];
413
+
414
+        $sql = $this->conn->getQueryBuilder();
415
+        $sql->select('*')
416
+            ->from('appconfig');
417
+        $result = $sql->execute();
418
+
419
+        // we are going to store the result in memory anyway
420
+        $rows = $result->fetchAll();
421
+        foreach ($rows as $row) {
422
+            if (!isset($this->cache[$row['appid']])) {
423
+                $this->cache[(string)$row['appid']] = [];
424
+            }
425
+
426
+            $this->cache[(string)$row['appid']][(string)$row['configkey']] = (string)$row['configvalue'];
427
+        }
428
+        $result->closeCursor();
429
+
430
+        $this->configLoaded = true;
431
+    }
432
+
433
+
434
+    /**
435
+     * Clear all the cached app config values
436
+     * New cache will be generated next time a config value is retrieved
437
+     */
438
+    public function clearCachedConfig(): void {
439
+        $this->configLoaded = false;
440
+    }
441 441
 }
Please login to merge, or discard this patch.
lib/private/Repair/NC21/ValidatePhoneNumber.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -34,55 +34,55 @@
 block discarded – undo
34 34
 use OCP\Migration\IRepairStep;
35 35
 
36 36
 class ValidatePhoneNumber implements IRepairStep {
37
-	/** @var IConfig */
38
-	protected $config;
39
-	/** @var IUserManager */
40
-	protected $userManager;
41
-	/** @var IAccountManager */
42
-	private $accountManager;
37
+    /** @var IConfig */
38
+    protected $config;
39
+    /** @var IUserManager */
40
+    protected $userManager;
41
+    /** @var IAccountManager */
42
+    private $accountManager;
43 43
 
44
-	public function __construct(IUserManager $userManager,
45
-								IAccountManager $accountManager,
46
-								IConfig $config) {
47
-		$this->config = $config;
48
-		$this->userManager = $userManager;
49
-		$this->accountManager = $accountManager;
50
-	}
44
+    public function __construct(IUserManager $userManager,
45
+                                IAccountManager $accountManager,
46
+                                IConfig $config) {
47
+        $this->config = $config;
48
+        $this->userManager = $userManager;
49
+        $this->accountManager = $accountManager;
50
+    }
51 51
 
52
-	public function getName(): string {
53
-		return 'Validate the phone number and store it in a known format for search';
54
-	}
52
+    public function getName(): string {
53
+        return 'Validate the phone number and store it in a known format for search';
54
+    }
55 55
 
56
-	public function run(IOutput $output): void {
57
-		if ($this->config->getSystemValueString('default_phone_region', '') === '') {
58
-			$output->warning('Can not validate phone numbers without `default_phone_region` being set in the config file');
59
-			return;
60
-		}
56
+    public function run(IOutput $output): void {
57
+        if ($this->config->getSystemValueString('default_phone_region', '') === '') {
58
+            $output->warning('Can not validate phone numbers without `default_phone_region` being set in the config file');
59
+            return;
60
+        }
61 61
 
62
-		$numUpdated = 0;
63
-		$numRemoved = 0;
62
+        $numUpdated = 0;
63
+        $numRemoved = 0;
64 64
 
65
-		$this->userManager->callForSeenUsers(function (IUser $user) use (&$numUpdated, &$numRemoved) {
66
-			$account = $this->accountManager->getAccount($user);
67
-			$property = $account->getProperty(IAccountManager::PROPERTY_PHONE);
65
+        $this->userManager->callForSeenUsers(function (IUser $user) use (&$numUpdated, &$numRemoved) {
66
+            $account = $this->accountManager->getAccount($user);
67
+            $property = $account->getProperty(IAccountManager::PROPERTY_PHONE);
68 68
 
69
-			if ($property->getValue() !== '') {
70
-				$this->accountManager->updateAccount($account);
71
-				$updatedAccount = $this->accountManager->getAccount($user);
72
-				$updatedProperty = $updatedAccount->getProperty(IAccountManager::PROPERTY_PHONE);
69
+            if ($property->getValue() !== '') {
70
+                $this->accountManager->updateAccount($account);
71
+                $updatedAccount = $this->accountManager->getAccount($user);
72
+                $updatedProperty = $updatedAccount->getProperty(IAccountManager::PROPERTY_PHONE);
73 73
 
74
-				if ($property->getValue() !== $updatedProperty->getValue()) {
75
-					if ($updatedProperty->getValue() === '') {
76
-						$numRemoved++;
77
-					} else {
78
-						$numUpdated++;
79
-					}
80
-				}
81
-			}
82
-		});
74
+                if ($property->getValue() !== $updatedProperty->getValue()) {
75
+                    if ($updatedProperty->getValue() === '') {
76
+                        $numRemoved++;
77
+                    } else {
78
+                        $numUpdated++;
79
+                    }
80
+                }
81
+            }
82
+        });
83 83
 
84
-		if ($numRemoved > 0 || $numUpdated > 0) {
85
-			$output->info('Updated ' . $numUpdated . ' entries and cleaned ' . $numRemoved . ' invalid phone numbers');
86
-		}
87
-	}
84
+        if ($numRemoved > 0 || $numUpdated > 0) {
85
+            $output->info('Updated ' . $numUpdated . ' entries and cleaned ' . $numRemoved . ' invalid phone numbers');
86
+        }
87
+    }
88 88
 }
Please login to merge, or discard this patch.
apps/dav/lib/Migration/RemoveObjectProperties.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -27,39 +27,39 @@
 block discarded – undo
27 27
 use OCP\Migration\IRepairStep;
28 28
 
29 29
 class RemoveObjectProperties implements IRepairStep {
30
-	private const RESOURCE_TYPE_PROPERTY = '{DAV:}resourcetype';
31
-	private const ME_CARD_PROPERTY = '{http://calendarserver.org/ns/}me-card';
32
-	private const CALENDAR_TRANSP_PROPERTY = '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp';
30
+    private const RESOURCE_TYPE_PROPERTY = '{DAV:}resourcetype';
31
+    private const ME_CARD_PROPERTY = '{http://calendarserver.org/ns/}me-card';
32
+    private const CALENDAR_TRANSP_PROPERTY = '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp';
33 33
 
34
-	/** @var IDBConnection */
35
-	private $connection;
34
+    /** @var IDBConnection */
35
+    private $connection;
36 36
 
37
-	/**
38
-	 * RemoveObjectProperties constructor.
39
-	 *
40
-	 * @param IDBConnection $connection
41
-	 */
42
-	public function __construct(IDBConnection $connection) {
43
-		$this->connection = $connection;
44
-	}
37
+    /**
38
+     * RemoveObjectProperties constructor.
39
+     *
40
+     * @param IDBConnection $connection
41
+     */
42
+    public function __construct(IDBConnection $connection) {
43
+        $this->connection = $connection;
44
+    }
45 45
 
46
-	/**
47
-	 * @inheritdoc
48
-	 */
49
-	public function getName() {
50
-		return 'Remove invalid object properties';
51
-	}
46
+    /**
47
+     * @inheritdoc
48
+     */
49
+    public function getName() {
50
+        return 'Remove invalid object properties';
51
+    }
52 52
 
53
-	/**
54
-	 * @inheritdoc
55
-	 */
56
-	public function run(IOutput $output) {
57
-		$query = $this->connection->getQueryBuilder();
58
-		$updated = $query->delete('properties')
59
-			->where($query->expr()->in('propertyname', $query->createNamedParameter([self::RESOURCE_TYPE_PROPERTY, self::ME_CARD_PROPERTY, self::CALENDAR_TRANSP_PROPERTY], IQueryBuilder::PARAM_STR_ARRAY)))
60
-			->andWhere($query->expr()->eq('propertyvalue', $query->createNamedParameter('Object'), IQueryBuilder::PARAM_STR))
61
-			->executeStatement();
53
+    /**
54
+     * @inheritdoc
55
+     */
56
+    public function run(IOutput $output) {
57
+        $query = $this->connection->getQueryBuilder();
58
+        $updated = $query->delete('properties')
59
+            ->where($query->expr()->in('propertyname', $query->createNamedParameter([self::RESOURCE_TYPE_PROPERTY, self::ME_CARD_PROPERTY, self::CALENDAR_TRANSP_PROPERTY], IQueryBuilder::PARAM_STR_ARRAY)))
60
+            ->andWhere($query->expr()->eq('propertyvalue', $query->createNamedParameter('Object'), IQueryBuilder::PARAM_STR))
61
+            ->executeStatement();
62 62
 
63
-		$output->info("$updated invalid object properties removed.");
64
-	}
63
+        $output->info("$updated invalid object properties removed.");
64
+    }
65 65
 }
Please login to merge, or discard this patch.
core/Command/Maintenance/Repair.php 2 patches
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -47,102 +47,102 @@
 block discarded – undo
47 47
 use Symfony\Component\Console\Output\OutputInterface;
48 48
 
49 49
 class Repair extends Command {
50
-	protected \OC\Repair $repair;
51
-	protected IConfig $config;
52
-	private IEventDispatcher $dispatcher;
53
-	private ProgressBar $progress;
54
-	private OutputInterface $output;
55
-	private IAppManager $appManager;
56
-	protected bool $errored = false;
50
+    protected \OC\Repair $repair;
51
+    protected IConfig $config;
52
+    private IEventDispatcher $dispatcher;
53
+    private ProgressBar $progress;
54
+    private OutputInterface $output;
55
+    private IAppManager $appManager;
56
+    protected bool $errored = false;
57 57
 
58
-	public function __construct(\OC\Repair $repair, IConfig $config, IEventDispatcher $dispatcher, IAppManager $appManager) {
59
-		$this->repair = $repair;
60
-		$this->config = $config;
61
-		$this->dispatcher = $dispatcher;
62
-		$this->appManager = $appManager;
63
-		parent::__construct();
64
-	}
58
+    public function __construct(\OC\Repair $repair, IConfig $config, IEventDispatcher $dispatcher, IAppManager $appManager) {
59
+        $this->repair = $repair;
60
+        $this->config = $config;
61
+        $this->dispatcher = $dispatcher;
62
+        $this->appManager = $appManager;
63
+        parent::__construct();
64
+    }
65 65
 
66
-	protected function configure() {
67
-		$this
68
-			->setName('maintenance:repair')
69
-			->setDescription('repair this installation')
70
-			->addOption(
71
-				'include-expensive',
72
-				null,
73
-				InputOption::VALUE_NONE,
74
-				'Use this option when you want to include resource and load expensive tasks');
75
-	}
66
+    protected function configure() {
67
+        $this
68
+            ->setName('maintenance:repair')
69
+            ->setDescription('repair this installation')
70
+            ->addOption(
71
+                'include-expensive',
72
+                null,
73
+                InputOption::VALUE_NONE,
74
+                'Use this option when you want to include resource and load expensive tasks');
75
+    }
76 76
 
77
-	protected function execute(InputInterface $input, OutputInterface $output): int {
78
-		$repairSteps = $this->repair::getRepairSteps();
77
+    protected function execute(InputInterface $input, OutputInterface $output): int {
78
+        $repairSteps = $this->repair::getRepairSteps();
79 79
 
80
-		if ($input->getOption('include-expensive')) {
81
-			$repairSteps = array_merge($repairSteps, $this->repair::getExpensiveRepairSteps());
82
-		}
80
+        if ($input->getOption('include-expensive')) {
81
+            $repairSteps = array_merge($repairSteps, $this->repair::getExpensiveRepairSteps());
82
+        }
83 83
 
84
-		foreach ($repairSteps as $step) {
85
-			$this->repair->addStep($step);
86
-		}
84
+        foreach ($repairSteps as $step) {
85
+            $this->repair->addStep($step);
86
+        }
87 87
 
88
-		$apps = $this->appManager->getInstalledApps();
89
-		foreach ($apps as $app) {
90
-			if (!$this->appManager->isEnabledForUser($app)) {
91
-				continue;
92
-			}
93
-			$info = $this->appManager->getAppInfo($app);
94
-			if (!is_array($info)) {
95
-				continue;
96
-			}
97
-			\OC_App::loadApp($app);
98
-			$steps = $info['repair-steps']['post-migration'];
99
-			foreach ($steps as $step) {
100
-				try {
101
-					$this->repair->addStep($step);
102
-				} catch (Exception $ex) {
103
-					$output->writeln("<error>Failed to load repair step for $app: {$ex->getMessage()}</error>");
104
-				}
105
-			}
106
-		}
88
+        $apps = $this->appManager->getInstalledApps();
89
+        foreach ($apps as $app) {
90
+            if (!$this->appManager->isEnabledForUser($app)) {
91
+                continue;
92
+            }
93
+            $info = $this->appManager->getAppInfo($app);
94
+            if (!is_array($info)) {
95
+                continue;
96
+            }
97
+            \OC_App::loadApp($app);
98
+            $steps = $info['repair-steps']['post-migration'];
99
+            foreach ($steps as $step) {
100
+                try {
101
+                    $this->repair->addStep($step);
102
+                } catch (Exception $ex) {
103
+                    $output->writeln("<error>Failed to load repair step for $app: {$ex->getMessage()}</error>");
104
+                }
105
+            }
106
+        }
107 107
 
108 108
 
109 109
 
110
-		$maintenanceMode = $this->config->getSystemValueBool('maintenance');
111
-		$this->config->setSystemValue('maintenance', true);
110
+        $maintenanceMode = $this->config->getSystemValueBool('maintenance');
111
+        $this->config->setSystemValue('maintenance', true);
112 112
 
113
-		$this->progress = new ProgressBar($output);
114
-		$this->output = $output;
115
-		$this->dispatcher->addListener(RepairStartEvent::class, [$this, 'handleRepairFeedBack']);
116
-		$this->dispatcher->addListener(RepairAdvanceEvent::class, [$this, 'handleRepairFeedBack']);
117
-		$this->dispatcher->addListener(RepairFinishEvent::class, [$this, 'handleRepairFeedBack']);
118
-		$this->dispatcher->addListener(RepairStepEvent::class, [$this, 'handleRepairFeedBack']);
119
-		$this->dispatcher->addListener(RepairInfoEvent::class, [$this, 'handleRepairFeedBack']);
120
-		$this->dispatcher->addListener(RepairWarningEvent::class, [$this, 'handleRepairFeedBack']);
121
-		$this->dispatcher->addListener(RepairErrorEvent::class, [$this, 'handleRepairFeedBack']);
113
+        $this->progress = new ProgressBar($output);
114
+        $this->output = $output;
115
+        $this->dispatcher->addListener(RepairStartEvent::class, [$this, 'handleRepairFeedBack']);
116
+        $this->dispatcher->addListener(RepairAdvanceEvent::class, [$this, 'handleRepairFeedBack']);
117
+        $this->dispatcher->addListener(RepairFinishEvent::class, [$this, 'handleRepairFeedBack']);
118
+        $this->dispatcher->addListener(RepairStepEvent::class, [$this, 'handleRepairFeedBack']);
119
+        $this->dispatcher->addListener(RepairInfoEvent::class, [$this, 'handleRepairFeedBack']);
120
+        $this->dispatcher->addListener(RepairWarningEvent::class, [$this, 'handleRepairFeedBack']);
121
+        $this->dispatcher->addListener(RepairErrorEvent::class, [$this, 'handleRepairFeedBack']);
122 122
 
123
-		$this->repair->run();
123
+        $this->repair->run();
124 124
 
125
-		$this->config->setSystemValue('maintenance', $maintenanceMode);
126
-		return $this->errored ? 1 : 0;
127
-	}
125
+        $this->config->setSystemValue('maintenance', $maintenanceMode);
126
+        return $this->errored ? 1 : 0;
127
+    }
128 128
 
129
-	public function handleRepairFeedBack(Event $event): void {
130
-		if ($event instanceof RepairStartEvent) {
131
-			$this->progress->start($event->getMaxStep());
132
-		} elseif ($event instanceof RepairAdvanceEvent) {
133
-			$this->progress->advance($event->getIncrement());
134
-		} elseif ($event instanceof RepairFinishEvent) {
135
-			$this->progress->finish();
136
-			$this->output->writeln('');
137
-		} elseif ($event instanceof RepairStepEvent) {
138
-			$this->output->writeln('<info> - ' . $event->getStepName() . '</info>');
139
-		} elseif ($event instanceof RepairInfoEvent) {
140
-			$this->output->writeln('<info>     - ' . $event->getMessage() . '</info>');
141
-		} elseif ($event instanceof RepairWarningEvent) {
142
-			$this->output->writeln('<comment>     - WARNING: ' . $event->getMessage() . '</comment>');
143
-		} elseif ($event instanceof RepairErrorEvent) {
144
-			$this->output->writeln('<error>     - ERROR: ' . $event->getMessage() . '</error>');
145
-			$this->errored = true;
146
-		}
147
-	}
129
+    public function handleRepairFeedBack(Event $event): void {
130
+        if ($event instanceof RepairStartEvent) {
131
+            $this->progress->start($event->getMaxStep());
132
+        } elseif ($event instanceof RepairAdvanceEvent) {
133
+            $this->progress->advance($event->getIncrement());
134
+        } elseif ($event instanceof RepairFinishEvent) {
135
+            $this->progress->finish();
136
+            $this->output->writeln('');
137
+        } elseif ($event instanceof RepairStepEvent) {
138
+            $this->output->writeln('<info> - ' . $event->getStepName() . '</info>');
139
+        } elseif ($event instanceof RepairInfoEvent) {
140
+            $this->output->writeln('<info>     - ' . $event->getMessage() . '</info>');
141
+        } elseif ($event instanceof RepairWarningEvent) {
142
+            $this->output->writeln('<comment>     - WARNING: ' . $event->getMessage() . '</comment>');
143
+        } elseif ($event instanceof RepairErrorEvent) {
144
+            $this->output->writeln('<error>     - ERROR: ' . $event->getMessage() . '</error>');
145
+            $this->errored = true;
146
+        }
147
+    }
148 148
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -135,13 +135,13 @@
 block discarded – undo
135 135
 			$this->progress->finish();
136 136
 			$this->output->writeln('');
137 137
 		} elseif ($event instanceof RepairStepEvent) {
138
-			$this->output->writeln('<info> - ' . $event->getStepName() . '</info>');
138
+			$this->output->writeln('<info> - '.$event->getStepName().'</info>');
139 139
 		} elseif ($event instanceof RepairInfoEvent) {
140
-			$this->output->writeln('<info>     - ' . $event->getMessage() . '</info>');
140
+			$this->output->writeln('<info>     - '.$event->getMessage().'</info>');
141 141
 		} elseif ($event instanceof RepairWarningEvent) {
142
-			$this->output->writeln('<comment>     - WARNING: ' . $event->getMessage() . '</comment>');
142
+			$this->output->writeln('<comment>     - WARNING: '.$event->getMessage().'</comment>');
143 143
 		} elseif ($event instanceof RepairErrorEvent) {
144
-			$this->output->writeln('<error>     - ERROR: ' . $event->getMessage() . '</error>');
144
+			$this->output->writeln('<error>     - ERROR: '.$event->getMessage().'</error>');
145 145
 			$this->errored = true;
146 146
 		}
147 147
 	}
Please login to merge, or discard this patch.