AlterRoleModule::down()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 19
rs 9.8666
1
<?php
2
3
use Illuminate\Support\Facades\Schema;
4
use Illuminate\Database\Schema\Blueprint;
5
use Uccello\Core\Database\Migrations\Migration;
6
use Uccello\Core\Models\Field;
7
use Uccello\Core\Models\Filter;
8
use Uccello\Core\Models\Module;
9
10
class AlterRoleModule extends Migration
11
{
12
    /**
13
     * Run the migrations.
14
     *
15
     * @return void
16
     */
17
    public function up()
18
    {
19
        Schema::table($this->tablePrefix.'roles', function(Blueprint $table) {
20
            $table->boolean('see_descendants_records')->after('description')->default(false);
21
        });
22
23
        $roleModule = Module::where('name', 'role')->first();
24
25
        $descriptionField = Field::where('module_id', $roleModule->id)->where('name', 'description')->first();
26
        $descriptionField->data = null;
0 ignored issues
show
Bug introduced by
The property data does not seem to exist on Uccello\Core\Models\Field. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
27
        $descriptionField->save();
28
29
        Field::create([
30
            'module_id' => $roleModule->id,
31
            'block_id' => $descriptionField->block_id,
0 ignored issues
show
Bug introduced by
The property block_id does not exist on Uccello\Core\Models\Field. Did you mean block?
Loading history...
32
            'name' => 'see_descendants_records',
33
            'uitype_id' => uitype('boolean')->id,
34
            'displaytype_id' => displaytype('everywhere')->id,
35
            'sequence' => 3,
36
            'data' => [ 'info' => 'field_info.see_descendants_records']
37
        ]);
38
39
        $filter = Filter::where('module_id', $roleModule->id)->where('name', 'filter.all')->first();
40
        $filter->columns = [ "name", "parent", "description", "see_descendants_records" ];
0 ignored issues
show
Bug introduced by
The property columns does not seem to exist on Uccello\Core\Models\Filter. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
41
        $filter->save();
42
    }
43
44
    /**
45
     * Reverse the migrations.
46
     *
47
     * @return void
48
     */
49
    public function down()
50
    {
51
        Schema::table($this->tablePrefix.'roles', function(Blueprint $table) {
52
            $table->dropColumn('see_descendants_records');
53
        });
54
55
        $roleModule = Module::where('name', 'role')->first();
56
57
        $descriptionField = Field::where('module_id', $roleModule->id)->where('name', 'description')->first();
58
        $descriptionField->data = [ 'large' => true ];
0 ignored issues
show
Bug introduced by
The property data does not seem to exist on Uccello\Core\Models\Field. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
59
        $descriptionField->save();
60
61
        Field::where('module_id', $roleModule->id)
62
            ->where('name', 'see_descendants_records')
63
            ->delete();
64
65
        $filter = Filter::where('module_id', $roleModule->id)->where('name', 'filter.all')->first();
66
        $filter->columns = [ "name", "description", "parent" ];
0 ignored issues
show
Bug introduced by
The property columns does not seem to exist on Uccello\Core\Models\Filter. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
67
        $filter->save();
68
    }
69
}
70