Fix WebDAV backup error handling and license_info table queries

- Wrap license_info queries in try-catch for backup export functions
- Add detailed error messages to WebDAV backup responses (URL, HTTP code)
- Include WebDAV response body in error messages for debugging
- Update JS to display detailed error info in the UI

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Purple
2026-01-18 13:48:56 +00:00
parent 1421e8fdaa
commit 3ae39830e2
2 changed files with 35 additions and 7 deletions

View File

@@ -3770,9 +3770,14 @@ function handleBackupExport($db) {
$stmt = $db->query("SELECT id, email, role, display_name, active, created_at FROM admin_users ORDER BY id");
$backup['users'] = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Export license info
$stmt = $db->query("SELECT * FROM license_info WHERE is_active = 1 ORDER BY id DESC LIMIT 1");
$backup['license'] = $stmt->fetch(PDO::FETCH_ASSOC);
// Export license info (if table exists)
try {
$stmt = $db->query("SELECT * FROM license_info WHERE is_active = 1 ORDER BY id DESC LIMIT 1");
$backup['license'] = $stmt->fetch(PDO::FETCH_ASSOC);
} catch (Exception $e) {
// Table may not exist yet
$backup['license'] = null;
}
jsonResponse([
'success' => true,
@@ -3973,6 +3978,15 @@ function handleWebDAVBackup($db) {
$stmt = $db->query("SELECT id, email, role, display_name, active, created_at FROM admin_users ORDER BY id");
$backup['users'] = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Export license info (if table exists)
try {
$stmt = $db->query("SELECT * FROM license_info WHERE is_active = 1 ORDER BY id DESC LIMIT 1");
$backup['license'] = $stmt->fetch(PDO::FETCH_ASSOC);
} catch (Exception $e) {
// Table may not exist yet
$backup['license'] = null;
}
$jsonData = json_encode($backup, JSON_PRETTY_PRINT);
// Generate filename with timestamp
@@ -4018,10 +4032,16 @@ function handleWebDAVBackup($db) {
jsonResponse([
'success' => true,
'message' => 'Backup uploaded successfully',
'filename' => $filename
'filename' => $filename,
'url' => $webdavUrl
]);
} else {
jsonResponse(['error' => "WebDAV upload failed with HTTP $httpCode"], 500);
// Include response body for debugging
$errorMsg = "WebDAV upload failed with HTTP $httpCode";
if (!empty($response)) {
$errorMsg .= ": " . substr($response, 0, 200);
}
jsonResponse(['error' => $errorMsg, 'url' => $webdavUrl, 'http_code' => $httpCode], 500);
}
} catch (Exception $e) {

View File

@@ -1616,14 +1616,22 @@ async function backupToWebDAV() {
}
if (!data.success) {
throw new Error(data.error || "WebDAV backup failed");
// Include extra details if available
let errorMsg = data.error || "WebDAV backup failed";
if (data.url) {
errorMsg += ` (URL: ${data.url})`;
}
if (data.http_code) {
errorMsg += ` (HTTP: ${data.http_code})`;
}
throw new Error(errorMsg);
}
statusDiv.innerHTML = `<div style="padding: 12px; background: var(--success-bg); border: 1px solid var(--success); border-radius: var(--radius-md);"><strong style="color: var(--success);">Backup uploaded successfully!</strong><br><small>Filename: ${escapeHtml(data.filename)}</small></div>`;
showNotification("Backup uploaded to WebDAV", "success");
} catch (error) {
console.error("WebDAV backup error:", error);
statusDiv.innerHTML = `<div style="padding: 12px; background: var(--error-bg); border: 1px solid var(--error); border-radius: var(--radius-md);"><strong style="color: var(--error);">WebDAV backup failed:</strong> ${escapeHtml(error.message)}</div>`;
statusDiv.innerHTML = `<div style="padding: 12px; background: var(--error-bg); border: 1px solid var(--error); border-radius: var(--radius-md); word-break: break-word;"><strong style="color: var(--error);">WebDAV backup failed:</strong> ${escapeHtml(error.message)}</div>`;
}
}