up
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config/config.php';
|
||||
$db = Database::getInstance();
|
||||
$rows = $db->fetchAll("SELECT id, message_type, media_url, filename, message_id, created_at FROM conversations WHERE (message_type IN ('image','video','audio')) AND (local_file IS NULL OR local_file = '') AND (media_url IS NOT NULL AND media_url != '') ORDER BY created_at DESC LIMIT 200");
|
||||
$inserted = 0;
|
||||
foreach ($rows as $r) {
|
||||
$media = $r['media_url'];
|
||||
$data = ['conversation_id' => $r['id'], 'subdir' => date('Y/m'), 'status' => 'pending', 'created_at' => date('Y-m-d H:i:s')];
|
||||
if (preg_match('#^https?://#i', $media)) {
|
||||
$data['media_url'] = $media;
|
||||
} else {
|
||||
// assume media id
|
||||
$data['media_id'] = $media;
|
||||
}
|
||||
try {
|
||||
$db->insert('media_queue', $data);
|
||||
$inserted++;
|
||||
} catch (Exception $e) {
|
||||
// ignore duplicates
|
||||
}
|
||||
}
|
||||
echo "Inserted: $inserted jobs\n";
|
||||
@@ -10,9 +10,25 @@ $rows = $db->fetchAll('SELECT * FROM media_queue WHERE status = ? ORDER BY creat
|
||||
$ms = new MediaService();
|
||||
foreach ($rows as $r) {
|
||||
try {
|
||||
$res = $ms->fetchAndStoreFromGraph($r['media_id'], $r['subdir'] ?? date('Y/m'));
|
||||
$res = null;
|
||||
if (!empty($r['media_id'])) {
|
||||
$res = $ms->fetchAndStoreFromGraph($r['media_id'], $r['subdir'] ?? date('Y/m'));
|
||||
} elseif (!empty($r['media_url'])) {
|
||||
$res = $ms->fetchAndStoreFromUrl($r['media_url'], $r['subdir'] ?? date('Y/m'));
|
||||
}
|
||||
|
||||
if ($res) {
|
||||
// Actualizar fila media_queue
|
||||
$db->update('media_queue', ['status' => 'done', 'result' => json_encode($res)], 'id = :id', ['id' => $r['id']]);
|
||||
// Actualizar conversations si tenemos conversation_id
|
||||
if (!empty($r['conversation_id'])) {
|
||||
$update = [];
|
||||
if (!empty($res['local_file'])) $update['local_file'] = $res['local_file'];
|
||||
if (!empty($res['local_thumb'])) $update['local_thumb'] = $res['local_thumb'];
|
||||
if (!empty($update)) {
|
||||
$db->update('conversations', $update, 'id = :id', ['id' => $r['conversation_id']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$db->update('media_queue', ['status' => 'failed', 'result' => json_encode(['error' => $e->getMessage()])], 'id = :id', ['id' => $r['id']]);
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config/config.php';
|
||||
$db = Database::getInstance();
|
||||
$rows = $db->fetchAll('SELECT id,media_id,media_url,conversation_id,status,created_at FROM media_queue ORDER BY created_at ASC LIMIT 100');
|
||||
echo json_encode($rows, JSON_PRETTY_PRINT) . "\n";
|
||||
Reference in New Issue
Block a user