(string $id)
| 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 | { |
no test coverage detected