From df11e32e70ca3abebccf948a89f7868e33d5d3c8 Mon Sep 17 00:00:00 2001 From: Bashy Date: Wed, 27 May 2026 11:21:43 +0300 Subject: [PATCH] Fix write_config silently swallowing errors in botcompose MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Matches the pattern in botconfig.php — returns bool and reports failure to the caller so the UI shows the real error instead of false success. Co-Authored-By: Claude Sonnet 4.6 --- web/api/botcompose.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/web/api/botcompose.php b/web/api/botcompose.php index ddd8de8..d51eb9c 100644 --- a/web/api/botcompose.php +++ b/web/api/botcompose.php @@ -21,10 +21,11 @@ function read_config(string $path): ?array { return is_array($data) ? $data : null; } -function write_config(string $path, array $data): void { +function write_config(string $path, array $data): bool { $tmp = $path . '.tmp'; - file_put_contents($tmp, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); - rename($tmp, $path); + $ok = file_put_contents($tmp, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)) !== false; + if ($ok) $ok = rename($tmp, $path); + return (bool)$ok; } function read_dot_env(string $path): array { @@ -63,7 +64,9 @@ if ($action === 'rss_repost') { if (!isset($config['rss'][$feed_name])) { echo json_encode(['error' => 'Feed not found']); exit; } $config['rss'][$feed_name]['last_id'] = ''; - write_config($config_path, $config); + if (!write_config($config_path, $config)) { + echo json_encode(['error' => 'Failed to write config.json — check file permissions']); exit; + } Audit::log($db, 'botcompose_rss_repost', $pid, $feed_name); echo json_encode(['ok' => true, 'message' => 'Last ID cleared — bot will repost on next poll (within 5 min)']);