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

Method save

src/FileRise/Domain/SourceAdminService.php:23–69  ·  view source on GitHub ↗

* Persist source settings and run post-save health checks for enabled sources. * * @param array $body * @return array */

(array $body)

Source from the content-addressed store, hash-verified

21 * @return array<string,mixed>
22 */
23 public static function save(array $body): array
24 {
25 $didWrite = false;
26 $resultSource = null;
27
28 if (array_key_exists('enabled', $body)) {
29 $enabled = (bool)$body['enabled'];
30 $ok = SourcesConfig::saveEnabled($enabled);
31 if (!$ok) {
32 throw new RuntimeException('Failed to save sources setting', 500);
33 }
34 $didWrite = true;
35 }
36
37 if (isset($body['source'])) {
38 if (!is_array($body['source'])) {
39 throw new RuntimeException('Invalid source payload', 400);
40 }
41 $res = SourcesConfig::upsertSource($body['source']);
42 if (empty($res['ok'])) {
43 throw new RuntimeException((string)($res['error'] ?? 'Failed to save source'), 400);
44 }
45 $resultSource = isset($res['source']) && is_array($res['source']) ? $res['source'] : null;
46 $didWrite = true;
47 }
48
49 if (!$didWrite) {
50 throw new RuntimeException('No changes provided', 400);
51 }
52
53 $sourceFallback = (isset($body['source']) && is_array($body['source'])) ? $body['source'] : null;
54 $auto = self::autoTestAndMaybeDisable($resultSource, $sourceFallback);
55 $resultSource = $auto['resultSource'];
56
57 self::refreshPublicSiteConfig();
58
59 return [
60 'source' => $resultSource,
61 'autoTested' => $auto['autoTested'],
62 'autoTestOk' => $auto['autoTestOk'],
63 'autoTestLimited' => $auto['autoTestLimited'],
64 'autoTestError' => $auto['autoTestError'],
65 'autoTest' => $auto['autoTest'],
66 'autoDisabled' => $auto['autoDisabled'],
67 'autoDisableFailed' => $auto['autoDisableFailed'],
68 ];
69 }
70
71 /**
72 * Execute a source health check for one source id.

Callers 3

applyOidcGroupsToProMethod · 0.45
syncOidcGroupsToProMethod · 0.45
saveSourcesMethod · 0.45

Calls 4

saveEnabledMethod · 0.80
upsertSourceMethod · 0.80

Tested by

no test coverage detected