Update: 2026-07-05 18:25:17
This commit is contained in:
@@ -41,14 +41,14 @@ $BATCH_LIMIT = 500; // أقصى عدد ركاب لكل تشغيل
|
|||||||
$sql = "
|
$sql = "
|
||||||
SELECT
|
SELECT
|
||||||
p.id AS passenger_id,
|
p.id AS passenger_id,
|
||||||
p.country_code,
|
IFNULL(MAX(pol.country_code), 'JO') AS country_code,
|
||||||
t.token,
|
t.token,
|
||||||
MAX(pol.created_at) AS last_active
|
MAX(pol.created_at) AS last_active
|
||||||
FROM passengers p
|
FROM passengers p
|
||||||
JOIN tokens t ON t.passengerID = p.id
|
JOIN tokens t ON t.passengerID = p.id
|
||||||
LEFT JOIN passenger_opening_locations pol ON pol.passenger_id = p.id
|
LEFT JOIN passenger_opening_locations pol ON pol.passenger_id = p.id
|
||||||
WHERE p.status = 'notDeleted'
|
WHERE p.status = 'notDeleted'
|
||||||
GROUP BY p.id, p.country_code, t.token
|
GROUP BY p.id, t.token
|
||||||
HAVING
|
HAVING
|
||||||
last_active IS NULL
|
last_active IS NULL
|
||||||
OR last_active < DATE_SUB(NOW(), INTERVAL :days DAY)
|
OR last_active < DATE_SUB(NOW(), INTERVAL :days DAY)
|
||||||
@@ -56,37 +56,11 @@ $sql = "
|
|||||||
LIMIT :limit
|
LIMIT :limit
|
||||||
";
|
";
|
||||||
|
|
||||||
try {
|
$stmt = $con->prepare($sql);
|
||||||
$stmt = $con->prepare($sql);
|
$stmt->bindValue(':days', $INACTIVE_DAYS, PDO::PARAM_INT);
|
||||||
$stmt->bindValue(':days', $INACTIVE_DAYS, PDO::PARAM_INT);
|
$stmt->bindValue(':limit', $BATCH_LIMIT, PDO::PARAM_INT);
|
||||||
$stmt->bindValue(':limit', $BATCH_LIMIT, PDO::PARAM_INT);
|
$stmt->execute();
|
||||||
$stmt->execute();
|
$inactivePassengers = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
$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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($inactivePassengers)) {
|
if (empty($inactivePassengers)) {
|
||||||
echo "[ReEngagement] No inactive passengers found. All good!\n";
|
echo "[ReEngagement] No inactive passengers found. All good!\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user