From d7e94a4a75471e5ef3fa7cc9e2c8d89760b9a9b2 Mon Sep 17 00:00:00 2001 From: hbrain Date: Sun, 31 May 2026 15:36:11 +0200 Subject: [PATCH] Regenerate map PNGs unconditionally on article save --- new.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/new.php b/new.php index 0cfa3bc..7ce8bcf 100644 --- a/new.php +++ b/new.php @@ -416,6 +416,36 @@ function input_dir_output($dir){ $state = input_dir_state($dir); return basename((string)($state['output'] ?? '')); } +function regenerate_input_dir_maps($dir, $config){ + $python = trim((string)shell_exec('command -v python3 2>/dev/null')); + $script = __DIR__ . '/bin/gpsmap.py'; + if ($python === '' || !is_file($script)) return; + + $state = input_dir_state($dir); + $targets = []; + foreach (['output', 'preview_output'] as $key) { + $name = basename((string)($state[$key] ?? '')); + if ($name === '') continue; + $targets[] = $config['videos_dir'] . '/' . pathinfo($name, PATHINFO_FILENAME) . '.png'; + } + + // Fallback target if no output filename is known yet. + if (!$targets) { + $targets[] = $config['videos_dir'] . '/' . basename((string)$dir) . '.png'; + } + + $targets = array_values(array_unique($targets)); + + foreach ($targets as $outPng) { + $cmd = escapeshellarg($python) . ' ' . escapeshellarg($script) . ' ' . escapeshellarg($dir) . ' ' . escapeshellarg($outPng) . ' 2>&1'; + $output = (string)shell_exec($cmd); + if (is_file($outPng)) { + @chmod($outPng, 0664); + } else { + error_log('[mvlog] map regenerate failed for '.basename((string)$dir).' target='.basename((string)$outPng).' output='.trim($output)."\n", 3, '/var/log/mvlog_map.log'); + } + } +} function cached_video_metadata($output, $fallback){ $meta = ['title'=>$fallback['title'] ?? '', 'date'=>$fallback['date'] ?? '', 'location'=>$fallback['place'] ?? '', 'description'=>$fallback['description'] ?? '']; $cacheFile = __DIR__ . '/cache/videos.json'; @@ -572,6 +602,8 @@ try { write_data($dir, $_POST); save_uploads('media', $dir, $allowedMedia); save_uploads('audio', $dir, $allowedAudio); + // Always regenerate map image(s) on Save changes. + regenerate_input_dir_maps($dir, $config); if (!empty($_POST['ajax'])) ajax_json(['ok'=>true, 'message'=>'Updated input directory: in-dir/' . basename($dir), 'dir'=>basename($dir)]); header('Location: new.php?tab=edit'); exit;