Code Duplication    Length = 52-53 lines in 3 locations

migrations/20180210222728_maps_status_column_conversion.php 1 location

@@ 5-56 (lines=52) @@
2
3
use Phinx\Migration\AbstractMigration;
4
5
class MapsStatusColumnConversion extends AbstractMigration
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

migrations/20180212044818_team_status_column_conversion.php 1 location

@@ 5-57 (lines=53) @@
2
3
use Phinx\Migration\AbstractMigration;
4
5
class TeamStatusColumnConversion extends AbstractMigration
6
{
7
    public function up()
8
    {
9
        $teamsTable = $this->table('teams');
10
        $teamsTable
11
            ->addColumn('is_closed', 'boolean', [
12
                'after' => 'members',
13
                'null' => false,
14
                'default' => false,
15
                'comment' => 'Whether or not this team is closed',
16
            ])
17
            ->addColumn('is_deleted', 'boolean', [
18
                'after' => 'is_closed',
19
                'null' => false,
20
                'default' => false,
21
                'comment' => 'Whether or not this team has been soft deleted',
22
            ])
23
            ->update()
24
        ;
25
26
        $this->query("UPDATE teams SET is_closed = 1 WHERE status = 'closed';");
27
        $this->query("UPDATE teams SET is_deleted = 1 WHERE status = 'deleted';");
28
29
        $teamsTable
30
            ->removeColumn('status')
31
            ->update()
32
        ;
33
    }
34
35
    public function down()
36
    {
37
        $teamsTable = $this->table('teams');
38
        $teamsTable
39
            ->addColumn('status', 'set', [
40
                'values' => ['open', 'closed', 'disabled', 'deleted'],
41
                'null' => false,
42
                'default' => 'open',
43
                'comment' => 'The status of the team',
44
            ])
45
            ->update()
46
        ;
47
48
        $this->query("UPDATE teams SET status = 'deleted' WHERE is_deleted = 1;");
49
        $this->query("UPDATE teams SET status = 'closed' WHERE is_closed = 1;");
50
51
        $teamsTable
52
            ->removeColumn('is_closed')
53
            ->removeColumn('is_deleted')
54
            ->update()
55
        ;
56
    }
57
}
58

migrations/20180214080518_player_status_column_conversion.php 1 location

@@ 5-57 (lines=53) @@
2
3
use Phinx\Migration\AbstractMigration;
4
5
class PlayerStatusColumnConversion extends AbstractMigration
6
{
7
    public function up()
8
    {
9
        $playersTable = $this->table('players');
10
        $playersTable
11
            ->addColumn('is_disabled', 'boolean', [
12
                'after' => 'last_login',
13
                'null' => false,
14
                'default' => false,
15
                'comment' => 'Whether or not this account has been disabled by an admin and cannot log in',
16
            ])
17
            ->addColumn('is_deleted', 'boolean', [
18
                'after' => 'is_disabled',
19
                'null' => false,
20
                'default' => false,
21
                'comment' => 'Whether or not this player has been soft-deleted',
22
            ])
23
            ->update()
24
        ;
25
26
        $this->query("UPDATE players SET is_deleted = 1 WHERE status = 'deleted';");
27
        $this->query("UPDATE players SET is_disabled = 1 WHERE status = 'disabled';");
28
29
        $playersTable
30
            ->removeColumn('status')
31
            ->update()
32
        ;
33
    }
34
35
    public function down()
36
    {
37
        $playersTable = $this->table('players');
38
        $playersTable
39
            ->addColumn('status', 'set', [
40
                'values' => ['active','disabled','deleted','reported','banned','test'],
41
                'null' => false,
42
                'default' => 'active',
43
                'comment' => 'The status of this player',
44
            ])
45
            ->update()
46
        ;
47
48
        $this->query("UPDATE players SET status = 'deleted' WHERE is_deleted = 1;");
49
        $this->query("UPDATE players SET status = 'disabled' WHERE is_disabled = 1;");
50
51
        $playersTable
52
            ->removeColumn('is_disabled')
53
            ->removeColumn('is_deleted')
54
            ->update()
55
        ;
56
    }
57
}
58