Add --verify to the backfill script

Confirms a value is findable through the blind index after backfilling,
without opening the console or the database. Prints matched row ids only.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Hamza-Ayed
2026-07-25 15:59:50 +03:00
co-authored by Claude Opus 5
parent 761b957c96
commit 15f55ff3e4
+38 -1
View File
@@ -25,7 +25,7 @@ if (PHP_SAPI !== 'cli') {
require_once __DIR__ . '/../core/bootstrap.php'; require_once __DIR__ . '/../core/bootstrap.php';
require_once __DIR__ . '/../core/Security/BlindIndex.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']); $dryRun = isset($options['dry-run']);
$force = isset($options['force']); $force = isset($options['force']);
$only = $options['table'] ?? null; $only = $options['table'] ?? null;
@@ -42,6 +42,43 @@ try {
$con = Database::get('main'); $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 = [ $targets = [
'driver' => [ 'driver' => [
'phone_bidx' => ['scope' => 'driver.phone', 'columns' => ['phone']], 'phone_bidx' => ['scope' => 'driver.phone', 'columns' => ['phone']],