Fix: include public/avatars in backups and restoration, add graceful fallback for missing contact photos

This commit is contained in:
sorcier committed 2026-11-02 19:29:38 +01:00
1 parent 2bd1ae0777
commit 45011d8c59
4 files changed
+56 -13

No files matched your search

+22 -6
View File
@@ -133,7 +133,20 @@ class PhonebookManager
$sql .= " ORDER BY display_name COLLATE NOCASE ASC";
$stmt = $db->prepare($sql);
$stmt->execute($params);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
$contacts = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Vérification de la présence réelle du fichier sur le disque
foreach ($contacts as &$c) {
if (!empty($c['photo_url'])) {
$filename = basename((string)$c['photo_url']);
if (!file_exists(self::AVATARS_DIR . '/' . $filename)) {
$c['photo_url'] = '';
}
}
}
unset($c);
return $contacts;
}
/**
@@ -306,11 +319,14 @@ class PhonebookManager
$entry->addChild('Email', htmlspecialchars($email, ENT_XML1, 'UTF-8'));
}
if ($photo !== '') {
$fullPhotoUrl = (strpos($photo, '://') === false)
? rtrim($baseUrl, '/') . '/' . ltrim($photo, '/')
: $photo;
$entry->addChild('Photo', htmlspecialchars($fullPhotoUrl, ENT_XML1, 'UTF-8'));
$entry->addChild('Picture', htmlspecialchars($fullPhotoUrl, ENT_XML1, 'UTF-8'));
$photoFile = basename($photo);
if (file_exists(self::AVATARS_DIR . '/' . $photoFile)) {
$fullPhotoUrl = (strpos($photo, '://') === false)
? rtrim($baseUrl, '/') . '/' . ltrim($photo, '/')
: $photo;
$entry->addChild('Photo', htmlspecialchars($fullPhotoUrl, ENT_XML1, 'UTF-8'));
$entry->addChild('Picture', htmlspecialchars($fullPhotoUrl, ENT_XML1, 'UTF-8'));
}
}
}