Files
Siro/backend/serviceapp/getJsonFile.php
T
Hamza-AyedandClaude Opus 5 35a66935aa Repair verification joins broken by the OTP key change; extend backfill
Storing the verification phone as a keyed HMAC fixed OTP lookups but broke
every query that joined those tables back to the account, because
phone_verification*.phone_number no longer holds the same value as
driver.phone / passengers.phone. Six joins were affected, and four of them
feed the `verified` flag that the rider and driver apps check at sign-in — so
this was already failing under the current CBC mode, not only after a switch
to GCM.

Accounts now carry phone_key, computed exactly as otpPhoneKey() does, and the
joins match on it. It is written at registration for both apps and populated
for existing rows by the backfill.

The backfill also covers the columns added for the remaining lookups:
users.email_bidx/phone_bidx and driver.national_bidx, which were migrated but
never populated, and honours a per-field prefix so phone_key reproduces
otpPhoneKey's exact output.

Insert column/value counts verified with a paren-aware parser after editing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-25 16:40:53 +03:00

89 lines
2.7 KiB
PHP

<?php
require_once __DIR__ . '/../get_connect.php';
// اسم الملف النصي الذي سيتم حفظ البيانات فيه
$filename = "drivers_list.txt";
/*
المطلوب:
- جلب أرقام الهاتف من phone_verification غير الموجودة في driver
- فك تشفير الهاتف (والإيميل إن لزم)
- حفظ النتيجة في ملف نصي (رقم الهاتف والملاحظة)
*/
$sql = "
SELECT
pv.id,
pv.phone_number,
pv.email,
pv.token_code,
pv.created_at,
n.note
FROM
phone_verification pv
LEFT JOIN
driver d ON pv.phone_number = d.phone_key
LEFT JOIN
notesForDriverService n ON pv.phone_number = n.phone
WHERE
d.phone IS NULL
AND (n.note != 'delete' OR n.note IS NULL)
-- تمت إضافة هذا الشرط بناءً على طلبك (آخر 5 أيام)
-- AND pv.created_at >= DATE_SUB(NOW(), INTERVAL 5 DAY)
ORDER BY
pv.created_at DESC;
";
$stmt = $con->prepare($sql);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
// فتح الملف للكتابة (Mode 'w' يقوم بإنشاء الملف أو مسح محتواه السابق والكتابة من جديد)
$fileHandle = fopen($filename, 'w');
// التحقق من أن الملف فُتح بنجاح
if ($fileHandle) {
foreach ($rows as $r) {
$phone = "";
$note = "No Note"; // القيمة الافتراضية إذا لم توجد ملاحظة
// 1. فك تشفير رقم الهاتف
if (isset($r['phone_number']) && $r['phone_number'] != null) {
$phone = $encryptionHelper->decryptData($r['phone_number']);
}
// 2. تجهيز نص الملاحظة
if (isset($r['note']) && $r['note'] != null) {
$note = $r['note'];
}
// 3. تنسيق السطر الذي سيتم حفظه
// الشكل: Phone: 0123456789 | Note: مهتم بالتسجيل
$line = "Phone: " . $phone . " | Note: " . $note . PHP_EOL;
// 4. الكتابة داخل الملف
fwrite($fileHandle, $line);
}
// إغلاق الملف بعد الانتهاء
fclose($fileHandle);
// طباعة رسالة نجاح مع رابط للملف (اختياري)
echo json_encode([
"status" => "success",
"message" => "File created successfully",
"file" => $filename,
"count" => count($rows)
]);
} else {
jsonError("Unable to open file for writing.");
}
} else {
jsonError("No phone numbers found in the last 5 days");
}
?>