From 1b112f08ee01ce94bc32dfcbc57a64206f5425db Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Sun, 5 Jul 2026 18:25:17 +0300 Subject: [PATCH] Update: 2026-07-05 18:25:17 --- backend/bot/cron_passenger_reengagement.php | 40 ++++----------------- 1 file changed, 7 insertions(+), 33 deletions(-) diff --git a/backend/bot/cron_passenger_reengagement.php b/backend/bot/cron_passenger_reengagement.php index f18052f2..6d38698d 100644 --- a/backend/bot/cron_passenger_reengagement.php +++ b/backend/bot/cron_passenger_reengagement.php @@ -41,14 +41,14 @@ $BATCH_LIMIT = 500; // أقصى عدد ركاب لكل تشغيل $sql = " SELECT p.id AS passenger_id, - p.country_code, + IFNULL(MAX(pol.country_code), 'JO') AS country_code, t.token, MAX(pol.created_at) AS last_active FROM passengers p JOIN tokens t ON t.passengerID = p.id LEFT JOIN passenger_opening_locations pol ON pol.passenger_id = p.id WHERE p.status = 'notDeleted' - GROUP BY p.id, p.country_code, t.token + GROUP BY p.id, t.token HAVING last_active IS NULL OR last_active < DATE_SUB(NOW(), INTERVAL :days DAY) @@ -56,37 +56,11 @@ $sql = " LIMIT :limit "; -try { - $stmt = $con->prepare($sql); - $stmt->bindValue(':days', $INACTIVE_DAYS, PDO::PARAM_INT); - $stmt->bindValue(':limit', $BATCH_LIMIT, PDO::PARAM_INT); - $stmt->execute(); - $inactivePassengers = $stmt->fetchAll(PDO::FETCH_ASSOC); -} catch (PDOException $e) { - // Fallback: جدول passenger_opening_locations قد لا يملك passenger_id عمود — نستخدم start_location - $sqlFallback = " - SELECT - p.id AS passenger_id, - p.country_code, - t.token, - MAX(pol.date) AS last_active - FROM passengers p - JOIN tokens t ON t.passengerID = p.id - LEFT JOIN passenger_opening_locations pol ON pol.start_location = p.id - WHERE p.status = 'notDeleted' - GROUP BY p.id, p.country_code, t.token - HAVING - last_active IS NULL - OR last_active < DATE_SUB(NOW(), INTERVAL :days DAY) - ORDER BY last_active ASC - LIMIT :limit - "; - $stmt = $con->prepare($sqlFallback); - $stmt->bindValue(':days', $INACTIVE_DAYS, PDO::PARAM_INT); - $stmt->bindValue(':limit', $BATCH_LIMIT, PDO::PARAM_INT); - $stmt->execute(); - $inactivePassengers = $stmt->fetchAll(PDO::FETCH_ASSOC); -} +$stmt = $con->prepare($sql); +$stmt->bindValue(':days', $INACTIVE_DAYS, PDO::PARAM_INT); +$stmt->bindValue(':limit', $BATCH_LIMIT, PDO::PARAM_INT); +$stmt->execute(); +$inactivePassengers = $stmt->fetchAll(PDO::FETCH_ASSOC); if (empty($inactivePassengers)) { echo "[ReEngagement] No inactive passengers found. All good!\n";