AddDomainFields::up()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 17
rs 9.8666
cc 2
nc 2
nop 0
1
<?php
2
3
use Uccello\Core\Database\Migrations\Migration;
4
use Uccello\Core\Models\Field;
5
use Uccello\Core\Models\Module;
6
7
class AddDomainFields extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        $modules = [ 'user', 'group', 'role', 'profile' ];
17
18
        foreach ($modules as $moduleName) {
19
            $module = Module::where('name', $moduleName)->first();
20
            $block = $module->blocks->where('label', 'block.general')->first();
21
22
            // Field domain
23
            Field::create([
24
                'module_id' => $module->id,
25
                'block_id' => $block->id,
26
                'name' => 'domain',
27
                'uitype_id' => uitype('entity')->id,
28
                'displaytype_id' => displaytype('list_only')->id,
29
                'sequence' => $block->fields->count(),
30
                'data' => json_decode('{"module":"domain"}')
31
            ]);
32
        }
33
34
    }
35
36
    /**
37
     * Reverse the migrations.
38
     *
39
     * @return void
40
     */
41
    public function down()
42
    {
43
        $modules = [ 'user', 'group', 'role', 'profile' ];
44
45
        foreach ($modules as $moduleName) {
46
            $module = Module::where('name', $moduleName)->first();
47
48
            $module->fields()
49
                ->where('module_id', $module->id)
50
                ->where('name', 'domain')
51
                ->delete();
52
        }
53
    }
54
}
55