diff --git a/backend/scripts/backfill_blind_index.php b/backend/scripts/backfill_blind_index.php index e0218dd0..b87bfb9a 100644 --- a/backend/scripts/backfill_blind_index.php +++ b/backend/scripts/backfill_blind_index.php @@ -25,7 +25,7 @@ if (PHP_SAPI !== 'cli') { require_once __DIR__ . '/../core/bootstrap.php'; require_once __DIR__ . '/../core/Security/BlindIndex.php'; -$options = getopt('', ['dry-run', 'force', 'table::', 'batch::']); +$options = getopt('', ['dry-run', 'force', 'verify::', 'table::', 'batch::']); $dryRun = isset($options['dry-run']); $force = isset($options['force']); $only = $options['table'] ?? null; @@ -42,6 +42,43 @@ try { $con = Database::get('main'); + +/** + * --verify=<قيمة>: يبحث عن رقم/بريد عبر الفهرس ويطبع النتيجة، للتأكد من أن + * البحث يعمل فعلاً بعد التعبئة دون فتح واجهة أو قاعدة بيانات. + * لا يطبع أي بيانات حساسة كاملة. + */ +if (isset($options['verify'])) { + $needle = (string) $options['verify']; + if ($needle === '') exit("Usage: --verify=0791234567\n"); + + $con = Database::get('main'); + $found = false; + + foreach ([['driver', 'driver.phone', 'phone_bidx'], + ['driver', 'driver.email', 'email_bidx'], + ['passengers', 'passengers.phone', 'phone_bidx'], + ['passengers', 'passengers.email', 'email_bidx']] as [$table, $scope, $column]) { + $idx = $blind->index($scope, $needle); + if (!$idx) continue; + + $st = $con->prepare("SELECT id FROM `$table` WHERE `$column` = ? LIMIT 5"); + $st->execute([$idx]); + $ids = $st->fetchAll(PDO::FETCH_COLUMN); + + if ($ids) { + $found = true; + echo "✔ $table via $column → " . count($ids) . " match(es): " . implode(', ', $ids) . "\n"; + } + } + + if (!$found) { + echo "✘ no match for that value in any indexed column.\n"; + echo " Check that the value is correct and that the backfill has run.\n"; + } + exit; +} + $targets = [ 'driver' => [ 'phone_bidx' => ['scope' => 'driver.phone', 'columns' => ['phone']],