diff --git a/include/webdav_scan_diagnostic.inc.php b/include/webdav_scan_diagnostic.inc.php new file mode 100644 index 0000000..b9aa2c3 --- /dev/null +++ b/include/webdav_scan_diagnostic.inc.php @@ -0,0 +1,79 @@ +&1', + $output, + $exit + ); + $text = trim(implode("\n", $output)); + $decoded = $text !== '' ? json_decode($text, true) : null; + if (!is_array($decoded)) + { + $decoded = array( + 'ok'=>false, + 'connection_id'=>$connection_id, + 'fatal'=>'Diagnose lieferte kein gueltiges JSON.', + 'raw'=>$text, + ); + } + $decoded['exit_code'] = (int)$exit; + $reports[] = $decoded; + if ($exit !== 0 || empty($decoded['ok'])) $failed = true; + } + + if (!$reports) throw new RuntimeException('Keine aktive WebDAV-Verbindung gefunden.'); + + $parts = array(); + foreach ($reports as $report) + { + $id = (int)($report['connection_id'] ?? 0); + if (!empty($report['fatal'])) + { + $parts[] = 'WebDAV #'.$id.': FEHLER: '.(string)$report['fatal'].' (Exit '.(int)$report['exit_code'].')'; + continue; + } + $parts[] = sprintf( + 'WebDAV #%d: Mapping %d Dateien, Shadow %d Links, %d passend, %d defekt, %d ohne Mapping, %d doppelt (Exit %d).', + $id, + (int)($report['mapping_files'] ?? 0), + (int)($report['shadow_links'] ?? 0), + (int)($report['matched'] ?? 0), + (int)($report['broken'] ?? 0), + (int)($report['unmapped'] ?? 0), + (int)($report['duplicates'] ?? 0), + (int)$report['exit_code'] + ); + } + + return array( + 'message'=>($failed ? 'Scan-Test fehlgeschlagen. ' : 'Scan-Test erfolgreich. ').implode(' ', $parts), + ); +}