Fix: include public/avatars in backups and restoration, add graceful fallback for missing contact photos
This commit is contained in:
1 parent
2bd1ae0777
commit
45011d8c59
4 files changed
+56
-13
No files matched your search
+23
-1
@@ -257,7 +257,16 @@ class BackupManager
|
||||
}
|
||||
$manifestFiles['asterisk_custom_conf'] = ['count' => count(glob($destConfs . '/*'))];
|
||||
|
||||
// F. Création du Manifeste
|
||||
// F. Avatars et photos des contacts de l'annuaire (/var/www/nexus-pbx/public/avatars/)
|
||||
$publicAvatars = '/var/www/nexus-pbx/public/avatars';
|
||||
if (is_dir($publicAvatars)) {
|
||||
$destAvatars = $stageDir . '/public_avatars';
|
||||
mkdir($destAvatars, 0755, true);
|
||||
self::copyDirectoryRecursive($publicAvatars, $destAvatars);
|
||||
$manifestFiles['public_avatars'] = ['count' => count(glob($destAvatars . '/*'))];
|
||||
}
|
||||
|
||||
// G. Création du Manifeste
|
||||
$manifest = [
|
||||
'nexus_version' => self::VERSION,
|
||||
'created_at' => date('c'),
|
||||
@@ -573,6 +582,19 @@ class BackupManager
|
||||
}
|
||||
}
|
||||
|
||||
// 9b. Restauration des avatars et photos des contacts de l'annuaire
|
||||
if (is_dir($stageDir . '/public_avatars')) {
|
||||
$destAvatars = '/var/www/nexus-pbx/public/avatars';
|
||||
if (!is_dir($destAvatars)) {
|
||||
@mkdir($destAvatars, 0775, true);
|
||||
}
|
||||
self::copyDirectoryRecursive($stageDir . '/public_avatars', $destAvatars, true);
|
||||
@chown($destAvatars, 'www-data');
|
||||
@chgrp($destAvatars, 'asterisk');
|
||||
exec("chown -R www-data:asterisk " . escapeshellarg($destAvatars));
|
||||
exec("chmod -R 775 " . escapeshellarg($destAvatars));
|
||||
}
|
||||
|
||||
// 10. Régénération intégrale des configurations Asterisk avec la nouvelle base restaurée
|
||||
Database::resetConnection();
|
||||
$dbFresh = Database::getConnection(true);
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user