Passed
Branch main (b90ec4)
by Thierry
20:23 queued 14:04
created

CopyClosingsToAttrs   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 34
rs 10
c 1
b 0
f 0
wmc 2
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\DB;
7
use Siak\Tontine\Model\Closing;
8
9
class CopyClosingsToAttrs extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'closing:copy-to-attrs';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Copy the closings from their own table to the tontine attributes';
24
25
    /**
26
     * Execute the console command.
27
     *
28
      * @return int
29
     */
30
    public function handle()
31
    {
32
        DB::transaction(function() {
33
            foreach(Closing::savings()->with('fund.tontine')->cursor() as $closing)
34
            {
35
                $tontine = $closing->fund->tontine;
36
                $properties = $tontine->properties;
37
                $properties['closings'][$closing->session_id][$closing->fund_id] = $closing->profit;
38
                $tontine->saveProperties($properties);
39
            }
40
        });
41
42
        return Command::SUCCESS;
43
    }
44
}
45