Regenerate map PNGs unconditionally on article save

This commit is contained in:
hbrain 2026-05-31 15:36:11 +02:00
parent f95b5d4f0b
commit d7e94a4a75

32
new.php
View file

@ -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;