MCPcopy Create free account
hub / github.com/error311/FileRise / updateConfig

Method updateConfig

src/FileRise/Domain/AdminModel.php:408–737  ·  view source on GitHub ↗

* Updates the admin configuration file. * * @param array $configUpdate The configuration to update. * @return array Returns an array with "success" on success or "error" on failure. */

(array $configUpdate)

Source from the content-addressed store, hash-verified

406 * @return array Returns an array with "success" on success or "error" on failure.
407 */
408 public static function updateConfig(array $configUpdate): array
409 {
410 // Ensure encryption key exists
411 if (empty($GLOBALS['encryptionKey']) || !is_string($GLOBALS['encryptionKey'])) {
412 return ["error" => "Server encryption key is not configured."];
413 }
414
415 // Only enforce OIDC fields when OIDC is enabled
416 $oidcDisabled = isset($configUpdate['loginOptions']['disableOIDCLogin'])
417 ? (bool)$configUpdate['loginOptions']['disableOIDCLogin']
418 : true; // default to disabled when not present
419
420 if (!$oidcDisabled) {
421 $oidc = $configUpdate['oidc'] ?? [];
422 $publicClient = !empty($oidc['publicClient']);
423 $required = ['providerUrl', 'clientId', 'redirectUri'];
424
425 // Confidential clients still require a secret
426 if (!$publicClient) {
427 $required[] = 'clientSecret';
428 }
429
430 foreach ($required as $k) {
431 if (empty($oidc[$k]) || !is_string($oidc[$k])) {
432 return ["error" => "Incomplete OIDC configuration (enable OIDC requires providerUrl, clientId, redirectUri" . ($publicClient ? '' : ', clientSecret') . "). If you want a blank secret, enable Public Client or disable OIDC login."];
433 }
434 }
435
436 // Normalize secret handling for public clients (strip it when flagged)
437 if ($publicClient) {
438 $configUpdate['oidc']['clientSecret'] = '';
439 }
440 $configUpdate['oidc']['publicClient'] = $publicClient;
441 }
442
443 // Ensure enableWebDAV flag is boolean (default to false if missing)
444 $configUpdate['enableWebDAV'] = isset($configUpdate['enableWebDAV'])
445 ? (bool)$configUpdate['enableWebDAV']
446 : false;
447 $configUpdate['safeUploadPolicy'] = UploadNamePolicy::normalizeMode(
448 $configUpdate['safeUploadPolicy'] ?? UploadNamePolicy::MODE_STRICT
449 );
450
451 // Validate sharedMaxUploadSize if provided
452 if (array_key_exists('sharedMaxUploadSize', $configUpdate)) {
453 $raw = $configUpdate['sharedMaxUploadSize'];
454
455 // If blank or zero, treat as "no override" and drop the key
456 if ($raw === '' || $raw === null || (int)$raw <= 0) {
457 unset($configUpdate['sharedMaxUploadSize']);
458 } else {
459 $sms = filter_var(
460 $raw,
461 FILTER_VALIDATE_INT,
462 ["options" => ["min_range" => 1]]
463 );
464 if ($sms === false) {
465 return ["error" => "Invalid sharedMaxUploadSize."];

Callers 1

updateConfig.phpFile · 0.45

Calls 13

parseSizeMethod · 0.95
sanitizeHttpUrlMethod · 0.95
sanitizeLogoUrlMethod · 0.95
sanitizeColorHexMethod · 0.95
sanitizeCssBackgroundMethod · 0.95
sanitizeTaglineMethod · 0.95
sanitizeFooterHtmlMethod · 0.95
sanitizeIgnoreRegexMethod · 0.95
buildPublicSubsetMethod · 0.95
writeSiteConfigMethod · 0.95
encryptDataFunction · 0.85

Tested by

no test coverage detected