Passed
Push — master ( 532076...f1d3c8 )
by Jonathan
11:51
created

GenerateUuidCacheCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 11
c 1
b 0
f 0
dl 0
loc 41
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 10 3
A __construct() 0 3 1
1
<?php
2
3
namespace Uccello\Core\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Uccello\Core\Models\Module;
7
8
class GenerateUuidCacheCommand extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'uccello:uuid';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Generate cache for uuid';
23
24
    /**
25
     * Create a new command instance.
26
     *
27
     * @return void
28
     */
29
    public function __construct()
30
    {
31
        parent::__construct();
32
    }
33
34
    /**
35
     * Execute the console command.
36
     *
37
     * @return mixed
38
     */
39
    public function handle()
40
    {
41
        $modules = Module::whereNotNull('model_class')->get();
42
        foreach ($modules as $module) {
43
            $this->info('Generating cache for <comment>'.$module->name.'</comment>');
44
45
            $modelClass = $module->model_class;
46
            $modelClass::chunkById(300, function ($records) {
47
                foreach ($records as $record) {
48
                    $record->uuid; // Automaticaly generate cache (see \Uccello\Core\Support\Traits\UccelloModule getUuidAttribute())
49
                }
50
            });
51
        }
52
    }
53
}
54