diff --git a/scripts/migrate_encrypt_results.php b/scripts/migrate_encrypt_results.php index 13ca05f0..0a1d79d0 100644 --- a/scripts/migrate_encrypt_results.php +++ b/scripts/migrate_encrypt_results.php @@ -32,13 +32,17 @@ $pdo = new PDO( $batch = 500; // Helper: migrate tabel dengan field-field sederhana (tanpa bidx) -function migrate_simple(PDO $pdo, Ibl_encryptor $enc, string $table, string $pk, array $fields, string $check_field): void +function migrate_simple(PDO $pdo, Ibl_encryptor $enc, $table, $pk, $fields, $check_field) { echo "=== {$table} ===\n"; - $total = 0; - $cols_sel = implode(', ', array_merge([$pk], $fields)); - $sets = implode(', ', array_map(fn($f) => "{$f}_enc = ?", $fields)); - $stmt = $pdo->prepare("UPDATE {$table} SET {$sets} WHERE {$pk} = ?"); + $total = 0; + $cols_sel = implode(', ', array_merge([$pk], $fields)); + $set_parts = array(); + foreach ($fields as $f) { + $set_parts[] = "{$f}_enc = ?"; + } + $sets = implode(', ', $set_parts); + $stmt = $pdo->prepare("UPDATE {$table} SET {$sets} WHERE {$pk} = ?"); while (true) { $rows = $pdo->query( @@ -48,7 +52,10 @@ function migrate_simple(PDO $pdo, Ibl_encryptor $enc, string $table, string $pk, if (empty($rows)) break; foreach ($rows as $row) { - $params = array_map(fn($f) => $enc->encrypt((string)($row[$f] ?? '')), $fields); + $params = array(); + foreach ($fields as $f) { + $params[] = $enc->encrypt((string)(isset($row[$f]) ? $row[$f] : '')); + } $params[] = $row[$pk]; $stmt->execute($params); $total++;