mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
New sorry voucher campaign setup
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UpdateVoucherCampaignsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (env('APP_ENV') !== 'production') {
|
||||
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']);
|
||||
DB::table('voucher_campaigns')->where('id', 4)->update(['campaign_id' => 'camp_zsUnlrlJB1G0TCu7YeLluAdR']);
|
||||
DB::table('voucher_campaigns')->where('id', 5)->update(['campaign_id' => 'camp_8ntTRkr3E5h0Ul1dR4UW8SBl']);
|
||||
DB::table('voucher_campaigns')->where('id', 6)->update(['campaign_id' => 'camp_YIHTJ3UxxjQDahWfrRaEwUil']);
|
||||
DB::table('voucher_campaigns')->where('id', 7)->update(['campaign_id' => 'camp_dNiljXXYU4CEfk2SwSRvgjHB']);
|
||||
|
||||
$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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
if (env('APP_ENV') !== 'production') {
|
||||
DB::table('voucher_campaigns')->where('id', 1)->update(['campaign_id' => '']);
|
||||
DB::table('voucher_campaigns')->where('id', 2)->update(['campaign_id' => '']);
|
||||
DB::table('voucher_campaigns')->where('id', 3)->update(['campaign_id' => '']);
|
||||
DB::table('voucher_campaigns')->where('id', 4)->update(['campaign_id' => '']);
|
||||
DB::table('voucher_campaigns')->where('id', 5)->update(['campaign_id' => '']);
|
||||
DB::table('voucher_campaigns')->where('id', 6)->update(['campaign_id' => '']);
|
||||
DB::table('voucher_campaigns')->where('id', 7)->update(['campaign_id' => '']);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user