up
This commit is contained in:
@@ -355,6 +355,39 @@ try {
|
||||
// Datos base para insertar
|
||||
// content: nombre de archivo o caption (nunca JSON)
|
||||
// media_url: ID de WhatsApp si está disponible, sino la URL original
|
||||
// local_file: ruta relativa del archivo local si existe
|
||||
// local_thumb: miniatura (por ahora usar mismo archivo para imágenes/videos)
|
||||
|
||||
// Intentar determinar ruta local desde mediaUrl si no se definió antes
|
||||
if (!isset($localFilePath) && $mediaUrl) {
|
||||
try {
|
||||
error_log("send_media_message.php - Intentando extraer local_file desde mediaUrl: " . $mediaUrl);
|
||||
$parsedUrl = parse_url($mediaUrl);
|
||||
$path = $parsedUrl['path'] ?? '';
|
||||
error_log("send_media_message.php - Path extraído: " . $path);
|
||||
// Si la URL apunta a /uploads/, construir ruta local
|
||||
if (strpos($path, '/uploads/') === 0) {
|
||||
$uploadDir = __DIR__ . '/../uploads/';
|
||||
$filename_from_url = basename($path);
|
||||
$testPath = $uploadDir . $filename_from_url;
|
||||
error_log("send_media_message.php - Testeando archivo local: " . $testPath);
|
||||
if (file_exists($testPath)) {
|
||||
$localFilePath = $testPath;
|
||||
error_log("send_media_message.php - ✅ Archivo local encontrado: " . $localFilePath);
|
||||
} else {
|
||||
error_log("send_media_message.php - ❌ Archivo local NO existe: " . $testPath);
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("send_media_message.php - Error parseando mediaUrl: " . $e->getMessage());
|
||||
}
|
||||
} else {
|
||||
error_log("send_media_message.php - localFilePath ya definido o mediaUrl vacío. localFilePath=" . (isset($localFilePath) ? $localFilePath : 'NULL') . ", mediaUrl=" . ($mediaUrl ?? 'NULL'));
|
||||
}
|
||||
|
||||
$localFileRelative = (isset($localFilePath) && file_exists($localFilePath)) ? str_replace(__DIR__ . '/../', '', $localFilePath) : null;
|
||||
error_log("send_media_message.php - local_file relativo para BD: " . ($localFileRelative ?? 'NULL'));
|
||||
|
||||
$conversationData = [
|
||||
'user_id' => $user['id'],
|
||||
'message_id' => $sentMessageId,
|
||||
@@ -363,6 +396,9 @@ try {
|
||||
'content' => $content,
|
||||
'media_url' => isset($uploaded_media_id) ? $uploaded_media_id : $mediaUrl,
|
||||
'whatsapp_media_id' => $uploaded_media_id ?? null,
|
||||
'local_file' => $localFileRelative,
|
||||
'local_thumb' => ($mediaType === 'image' || $mediaType === 'video') ? $localFileRelative : null,
|
||||
'filename' => $filename ?? null,
|
||||
'status' => 'sent',
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
];
|
||||
@@ -372,8 +408,10 @@ try {
|
||||
error_log(" - content: " . $content);
|
||||
error_log(" - media_url: " . ($conversationData['media_url'] ?? 'null'));
|
||||
error_log(" - whatsapp_media_id: " . ($conversationData['whatsapp_media_id'] ?? 'null'));
|
||||
error_log(" - local_file: " . ($conversationData['local_file'] ?? 'null'));
|
||||
error_log(" - local_thumb: " . ($conversationData['local_thumb'] ?? 'null'));
|
||||
error_log(" - media_type: " . $mediaType);
|
||||
smm_log("Saving to DB - content: {$content}, media_url: " . ($conversationData['media_url'] ?? 'null'));
|
||||
smm_log("Saving to DB - content: {$content}, media_url: " . ($conversationData['media_url'] ?? 'null') . ", local_file: " . ($conversationData['local_file'] ?? 'null') . ", local_thumb: " . ($conversationData['local_thumb'] ?? 'null'));
|
||||
|
||||
try {
|
||||
$db->insert('conversations', $conversationData);
|
||||
|
||||
Reference in New Issue
Block a user