Skip to content

Commit cabcc13

Browse files
committed
fix(files-external): do not load lazy appconfig from construct
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent c53a9bf commit cabcc13

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

apps/files_external/lib/Service/BackendService.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ class BackendService {
3535
/** Priority constants for PriorityTrait */
3636
public const PRIORITY_DEFAULT = 100;
3737

38-
/** @var bool */
39-
private $userMountingAllowed = true;
40-
38+
private ?bool $userMountingAllowed = null;
4139
/** @var string[] */
42-
private $userMountingBackends = [];
40+
private array $userMountingBackends = [];
4341

4442
/** @var Backend[] */
4543
private $backends = [];
@@ -59,16 +57,8 @@ class BackendService {
5957
private $configHandlers = [];
6058

6159
public function __construct(
62-
protected IAppConfig $appConfig,
60+
protected readonly IAppConfig $appConfig,
6361
) {
64-
// Load config values
65-
$this->userMountingAllowed = $appConfig->getValueBool('files_external', ConfigLexicon::ALLOW_USER_MOUNTING);
66-
$this->userMountingBackends = explode(',', $appConfig->getValueString('files_external', ConfigLexicon::USER_MOUNTING_BACKENDS));
67-
68-
// if no backend is in the list an empty string is in the array and user mounting is disabled
69-
if ($this->userMountingBackends === ['']) {
70-
$this->userMountingAllowed = false;
71-
}
7262
}
7363

7464
/**
@@ -249,6 +239,7 @@ public function getAuthMechanism($identifier) {
249239
* @return bool
250240
*/
251241
public function isUserMountingAllowed() {
242+
$this->loadUserMountingConfig();
252243
return $this->userMountingAllowed;
253244
}
254245

@@ -259,6 +250,7 @@ public function isUserMountingAllowed() {
259250
* @return bool
260251
*/
261252
protected function isAllowedUserBackend(Backend $backend) {
253+
$this->loadUserMountingConfig();
262254
if ($this->userMountingAllowed
263255
&& array_intersect($backend->getIdentifierAliases(), $this->userMountingBackends)
264256
) {
@@ -339,4 +331,22 @@ public function getConfigHandlers() {
339331
$this->loadConfigHandlers();
340332
return $this->configHandlers;
341333
}
334+
335+
/**
336+
* retrieve and cache config value related to user mounting
337+
*/
338+
private function loadUserMountingConfig(): void {
339+
if ($this->userMountingAllowed !== null) {
340+
return;
341+
}
342+
343+
// Load config values
344+
$this->userMountingAllowed = $this->appConfig->getValueBool('files_external', ConfigLexicon::ALLOW_USER_MOUNTING);
345+
$this->userMountingBackends = explode(',', $this->appConfig->getValueString('files_external', ConfigLexicon::USER_MOUNTING_BACKENDS));
346+
347+
// if no backend is in the list an empty string is in the array and user mounting is disabled
348+
if ($this->userMountingBackends === ['']) {
349+
$this->userMountingAllowed = false;
350+
}
351+
}
342352
}

0 commit comments

Comments
 (0)