Total Complexity | 5 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class CopyClosingsToTable extends Command |
||
11 | { |
||
12 | /** |
||
13 | * The name and signature of the console command. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $signature = 'closing:copy-to-table'; |
||
18 | |||
19 | /** |
||
20 | * The console command description. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $description = 'Copy the closings from the tontine attributes to their own table'; |
||
25 | |||
26 | /** |
||
27 | * Execute the console command. |
||
28 | * |
||
29 | * @return int |
||
30 | */ |
||
31 | public function handle() |
||
32 | { |
||
33 | DB::transaction(function() { |
||
34 | foreach(Tontine::cursor() as $tontine) |
||
35 | { |
||
36 | $closings = $tontine->properties['closings'] ?? []; |
||
37 | foreach($closings as $sessionId => $funds) |
||
38 | { |
||
39 | foreach($funds as $fundId => $profitAmount) |
||
40 | { |
||
41 | Closing::updateOrCreate([ |
||
42 | 'type' => Closing::TYPE_ROUND, |
||
43 | 'session_id' => $sessionId, |
||
44 | 'fund_id' => $fundId ?: $tontine->default_fund->id, |
||
45 | ], [ |
||
46 | 'options' => [ |
||
47 | 'profit' => [ |
||
48 | 'amount' => $profitAmount, |
||
49 | ], |
||
50 | ], |
||
51 | ]); |
||
52 | } |
||
53 | } |
||
54 | } |
||
55 | }); |
||
56 | |||
57 | return Command::SUCCESS; |
||
58 | } |
||
60 |