1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Phinx\Migration\AbstractMigration; |
4
|
|
|
|
5
|
|
|
class ServerStatusColumnConversation extends AbstractMigration |
6
|
|
|
{ |
7
|
|
View Code Duplication |
public function up() |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
$serversTable = $this->table('servers'); |
10
|
|
|
$serversTable |
11
|
|
|
->addColumn('is_official_server', 'boolean', [ |
12
|
|
|
'after' => 'updated', |
13
|
|
|
'null' => false, |
14
|
|
|
'default' => false, |
15
|
|
|
'comment' => 'Whether or not this server is capable of hosting official matches', |
16
|
|
|
]) |
17
|
|
|
->addColumn('is_replay_server', 'boolean', [ |
18
|
|
|
'after' => 'is_official_server', |
19
|
|
|
'null' => false, |
20
|
|
|
'default' => false, |
21
|
|
|
'comment' => 'Whether or not this server is dedicated to serving replays of matches', |
22
|
|
|
]) |
23
|
|
|
->addColumn('is_inactive', 'boolean', [ |
24
|
|
|
'after' => 'is_replay_server', |
25
|
|
|
'null' => false, |
26
|
|
|
'default' => false, |
27
|
|
|
'comment' => 'Whether or not this server is no longer active but still required for historical purposes', |
28
|
|
|
|
29
|
|
|
]) |
30
|
|
|
->addColumn('is_deleted', 'boolean', [ |
31
|
|
|
'after' => 'is_inactive', |
32
|
|
|
'null' => false, |
33
|
|
|
'default' => false, |
34
|
|
|
'comment' => 'Whether or not this server has been soft deleted', |
35
|
|
|
]) |
36
|
|
|
->update() |
37
|
|
|
; |
38
|
|
|
|
39
|
|
|
// BZiON 0.10.x and below required that you soft deleted servers so they'd no longer appear on the server list. |
40
|
|
|
// For this reason and because Leagues United is the only known installation, we'll be assuming that deleted |
41
|
|
|
// servers were just meant to be marked as "inactive." |
42
|
|
|
$this->query("UPDATE servers SET is_inactive = 1 WHERE status = 'deleted';"); |
43
|
|
|
|
44
|
|
|
$serversTable |
45
|
|
|
->removeColumn('status') |
46
|
|
|
->update() |
47
|
|
|
; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
View Code Duplication |
public function down() |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$serversTable = $this->table('servers'); |
53
|
|
|
$serversTable |
54
|
|
|
->addColumn('status', 'set', [ |
55
|
|
|
'values' => ['active', 'disabled', 'deleted'], |
56
|
|
|
'null' => false, |
57
|
|
|
'default' => 'active', |
58
|
|
|
'comment' => 'The status of the server relative to BZiON', |
59
|
|
|
]) |
60
|
|
|
->update() |
61
|
|
|
; |
62
|
|
|
|
63
|
|
|
$this->query("UPDATE servers SET status = 'deleted' WHERE is_inactive = 1;"); |
64
|
|
|
|
65
|
|
|
$serversTable |
66
|
|
|
->removeColumn('is_official_server') |
67
|
|
|
->removeColumn('is_replay_server') |
68
|
|
|
->removeColumn('is_inactive') |
69
|
|
|
->removeColumn('is_deleted') |
70
|
|
|
->update() |
71
|
|
|
; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
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.