BanMuteSupportIssue157   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 17 1
A down() 0 14 1
1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
5
/**
6
 * Restructure the `bans` table to better support bans and mutes.
7
 *
8
 * - The `allow_server_join` column was never correctly used and therefore has been dropped; due to incorrect use, the
9
 *   data did not need to be migrated or saved.
10
 * - The `is_soft_ban` column is being added to differentiate between bans that should penalize players on the site
11
 *   itself and bans that will only affect players on league servers. A soft ban will not affect a player on BZiON.
12
 *
13
 * @link https://github.com/allejo/bzion/issues/157
14
 */
15
class BanMuteSupportIssue157 extends AbstractMigration
16
{
17
    public function up()
18
    {
19
        $bansTable = $this->table('bans');
20
        $bansTable
21
            ->removeColumn('allow_server_join')
22
            ->addColumn('is_soft_ban', 'boolean', [
23
                'after' => 'author',
24
                'null' => false,
25
                'default' => false,
26
                'comment' => 'A soft ban will not penalize a user on the site or servers',
27
            ])
28
            ->update()
29
        ;
30
31
        // Unban any currently banned players
32
        $this->query("UPDATE players SET status = 'active' WHERE status = 'banned';");
33
    }
34
35
    public function down()
36
    {
37
        $bansTable = $this->table('bans');
38
        $bansTable
39
            ->removeColumn('is_soft_ban')
40
            ->addColumn('allow_server_join', 'boolean', [
41
                'after' => 'reason',
42
                'null' => false,
43
                'default' => false,
44
                'comment' => 'Whether or not to allow players to join servers while banned'
45
            ])
46
            ->update()
47
        ;
48
    }
49
}
50