Completed
Pull Request — master (#186)
by Vladimir
28:22 queued 13:18
created

MapsStatusColumnConversion::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
dl 21
loc 21
rs 9.3142
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
5 View Code Duplication
class MapsStatusColumnConversion extends AbstractMigration
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6
{
7
    public function up()
8
    {
9
        $mapsTable = $this->table('maps');
10
        $mapsTable
11
            ->addColumn('is_inactive', 'boolean', [
12
                'after' => 'game_mode',
13
                'null' => false,
14
                'default' => false,
15
                'comment' => 'Whether or not this map has been marked as inactive, meaning a map is no longer in active rotation on servers',
16
            ])
17
            ->addColumn('is_deleted', 'boolean', [
18
                'after' => 'is_inactive',
19
                'null' => false,
20
                'default' => false,
21
                'comment' => 'Whether or not this map has been soft deleted'
22
            ])
23
            ->update()
24
        ;
25
26
        $this->query("UPDATE maps SET is_inactive = 1 WHERE status = 'hidden' OR status = 'disabled';");
27
        $this->query("UPDATE maps SET is_deleted = 1 WHERE status = 'deleted';");
28
29
        $mapsTable
30
            ->removeColumn('status')
31
            ->update()
32
        ;
33
    }
34
35
    public function down()
36
    {
37
        $mapsTable = $this->table('maps');
38
        $mapsTable
39
            ->addColumn('status', 'set', [
40
                'values' => ['active', 'hidden', 'disabled', 'deleted'],
41
                'null' => false,
42
                'default' => 'active',
43
                'comment' => 'The status of the map',
44
            ])
45
            ->update()
46
        ;
47
48
        $this->query("UPDATE maps SET status = 'hidden' WHERE is_inactive = 1;");
49
        $this->query("UPDATE maps SET status = 'deleted' WHERE is_deleted = 1;");
50
51
        $mapsTable
52
            ->removeColumn('is_inactive')
53
            ->removeColumn('is_deleted')
54
        ;
55
    }
56
}
57