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

Method deleteSource

src/FileRise/Storage/SourcesConfig.php:445–473  ·  view source on GitHub ↗
(string $id)

Source from the content-addressed store, hash-verified

443 }
444
445 public static function deleteSource(string $id): array
446 {
447 if (self::proSourcesAvailable()) {
448 return ProSources::deleteSource($id);
449 }
450
451 $id = trim($id);
452 if ($id === '' || !preg_match('/^[A-Za-z0-9_-]{1,64}$/', $id)) {
453 return ['ok' => false, 'error' => 'Invalid source id'];
454 }
455 if ($id === self::DEFAULT_ID) {
456 return ['ok' => false, 'error' => 'Cannot delete the default Local source'];
457 }
458
459 $raw = self::loadRaw();
460 $sourceMap = self::rawSourceMap($raw);
461 if (!isset($sourceMap[$id])) {
462 return ['ok' => true];
463 }
464
465 unset($sourceMap[$id]);
466 $raw['sources'] = $sourceMap;
467
468 if (!self::saveRaw($raw)) {
469 return ['ok' => false, 'error' => 'Failed to delete source'];
470 }
471
472 return ['ok' => true];
473 }
474
475 private static function loadRaw(): array
476 {

Callers 1

delete.phpFile · 0.45

Calls 4

proSourcesAvailableMethod · 0.95
loadRawMethod · 0.95
rawSourceMapMethod · 0.95
saveRawMethod · 0.95

Tested by

no test coverage detected