Voucherify data patch for development environment only

This commit is contained in:
Dillon Ngo
2024-10-14 03:17:28 +08:00
parent 87087f5502
commit 5d6d6552ea
@@ -16,7 +16,31 @@ class UpdateVoucherCampaignsTable extends Migration
DB::table('voucher_campaigns')->where('id', 1)->update(['campaign_id' => 'camp_snxv2JQlh5v9LEDBbIBOnibD']);
DB::table('voucher_campaigns')->where('id', 2)->update(['campaign_id' => 'camp_lEM7WhLHFlhcRKRR0C4bXH0F']);
DB::table('voucher_campaigns')->where('id', 3)->update(['campaign_id' => 'camp_JP9qBGBYEinVjzAE1vjynMe0']);
$voucherCampaignIds = [1, 2, 3];
foreach ($voucherCampaignIds as $id) {
$campaignId = DB::table('voucher_campaigns')->where('id', $id)->value('campaign_id');
$ownerId = DB::table('voucher_campaigns')->where('id', $id)->value('id');
$upperCampaignId = strtoupper($campaignId);
$keysToUpdate = DB::table('key_value_pairs')
->where('key', 'like', '%_TOTAL%')
->where('owner_type', 'App\Models\VoucherCampaign')
->where('owner_id', (int) $ownerId)
->get();
foreach ($keysToUpdate as $entry) {
$parts = explode('_', $entry->key);
$lastTwoParts = array_slice($parts, -2); // Get the last two elements
$newKey = "{$upperCampaignId}_" . implode('_', $lastTwoParts);
DB::table('key_value_pairs')
->where('id', $entry->id)
->update(['key' => $newKey]);
}
}
}
}
/**