Skip to content

Commit

Permalink
-[x] feat: script to populate default value in organization settings
Browse files Browse the repository at this point in the history
  • Loading branch information
aashish-t-magar committed Jan 23, 2024
1 parent 7bfad9f commit fd69ca0
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions app/Console/Commands/SettingPopulateActivityDefaultValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

/**
* Class SettingPopulateActivityDefaultValue.
*/
class SettingPopulateActivityDefaultValue extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'populate:activity-default-value';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Populates settings table activity default value column with new keys';

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
DB::table('settings')->chunkById(10, function ($settings) {
foreach ($settings as $setting) {
$activityDefaultValue = json_decode($setting->activity_default_values, true) ?? [];
$newFields = [
'linked_data_uri' => '',
'default_collaboration_type' => '',
'default_flow_type' => '',
'default_finance_type' => '',
'default_aid_type' => '',
'default_tied_status' => '',
'hierarchy' => $activityDefaultValue['hierarchy'] ?? '',
'humanitarian' => $activityDefaultValue['humanitarian'] ?? '',
'budget_not_provided' => $activityDefaultValue['budget_not_provided'] ?? '',
];
DB::table('settings')->where('id', $setting->id)->update(['activity_default_values' => json_encode($newFields)]);
}
});
}
}

0 comments on commit fd69ca0

Please sign in to comment.