From 5d6d6552eafefce908bf36670f20bfc5b2c10041 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Mon, 14 Oct 2024 03:17:28 +0800 Subject: [PATCH] Voucherify data patch for development environment only --- ..._183417_update_voucher_campaigns_table.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/database/migrations/2024_08_24_183417_update_voucher_campaigns_table.php b/database/migrations/2024_08_24_183417_update_voucher_campaigns_table.php index 45bf8584..c24f918f 100644 --- a/database/migrations/2024_08_24_183417_update_voucher_campaigns_table.php +++ b/database/migrations/2024_08_24_183417_update_voucher_campaigns_table.php @@ -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]); + } + } } + } /**