58 lines
1.6 KiB
PHP
58 lines
1.6 KiB
PHP
<?php
|
|
/**
|
|
* Batch migration: enkripsi T_OrderDeliveryDestination (email/HP pengiriman hasil)
|
|
* Jalankan via: php scripts/migrate_encrypt_orderdelivery.php
|
|
* Aman dijalankan berulang: skip row yang sudah ada _enc-nya
|
|
*/
|
|
|
|
$env_file = __DIR__ . '/../.env';
|
|
if (!file_exists($env_file)) {
|
|
die("ERROR: .env tidak ditemukan\n");
|
|
}
|
|
foreach (file($env_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $l) {
|
|
if (strpos(trim($l), '#') === 0) continue;
|
|
[$k, $v] = array_map('trim', explode('=', $l, 2));
|
|
if ($k !== '') $_ENV[$k] = $v;
|
|
}
|
|
|
|
define('BASEPATH', true);
|
|
require __DIR__ . '/../application/libraries/Ibl_encryptor.php';
|
|
$enc = new Ibl_encryptor();
|
|
|
|
include __DIR__ . '/../application/config/database.php';
|
|
$cfg = $db['default'];
|
|
$pdo = new PDO(
|
|
"mysql:host={$cfg['hostname']};dbname={$cfg['database']};charset=utf8",
|
|
$cfg['username'],
|
|
$cfg['password'],
|
|
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
|
|
);
|
|
|
|
echo "=== Migrasi t_orderdelivery ===\n";
|
|
$total = 0;
|
|
$stmt = $pdo->prepare(
|
|
"UPDATE t_orderdelivery SET T_OrderDeliveryDestination_enc = ? WHERE T_OrderDeliveryID = ?"
|
|
);
|
|
|
|
while (true) {
|
|
$rows = $pdo->query(
|
|
"SELECT T_OrderDeliveryID, T_OrderDeliveryDestination
|
|
FROM t_orderdelivery
|
|
WHERE T_OrderDeliveryDestination_enc IS NULL
|
|
LIMIT 500"
|
|
)->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
if (empty($rows)) break;
|
|
|
|
foreach ($rows as $row) {
|
|
$stmt->execute([
|
|
$enc->encrypt((string)($row['T_OrderDeliveryDestination'] ?? '')),
|
|
$row['T_OrderDeliveryID'],
|
|
]);
|
|
$total++;
|
|
}
|
|
echo " {$total} rows...\n";
|
|
}
|
|
|
|
echo "t_orderdelivery selesai: {$total} rows\n";
|