Passed
Push — master ( c92e71...89beee )
by Jonathan
25:53
created

AlterRoleModule::down()   A

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;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Facades\Schema was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
4
use Illuminate\Database\Schema\Blueprint;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Schema\Blueprint was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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;
27
        $descriptionField->save();
28
29
        Field::create([
30
            'module_id' => $roleModule->id,
31
            'block_id' => $descriptionField->block_id,
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" ];
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 ];
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" ];
67
        $filter->save();
68
    }
69
}
70