Completed
Push — develop ( 0d3736...607e7f )
by Nate
09:29
created

m190128_091129_user_state_column::safeUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 0
cts 19
cp 0
rs 9.568
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/organization/license
6
 * @link       https://www.flipboxfactory.com/software/organization/
7
 */
8
9
namespace flipbox\organizations\migrations;
10
11
use craft\db\Migration;
12
use flipbox\organizations\Organizations;
13
use flipbox\organizations\records\UserAssociation;
14
15
/**
16
 * This migration adds a 'state' column to the organization user association record.
17
 */
18
class m190128_091129_user_state_column extends Migration
19
{
20
    /**
21
     * @inheritdoc
22
     * @throws \yii\base\NotSupportedException
23
     */
24
    public function safeUp()
25
    {
26
        $table = $this->getDb()->getSchema()->getTableSchema(
27
            UserAssociation::tableName()
28
        );
29
        
30
        if (!isset($table->columns[AlterUserStates::COLUMN_NAME])) {
31
            $states = array_keys(Organizations::getInstance()->getSettings()->getUserStates());
32
            $defaultState = Organizations::getInstance()->getSettings()->getDefaultUserState();
33
34
            $type = $this->enum(
35
                AlterUserStates::COLUMN_NAME,
36
                $states
37
            )->defaultValue($defaultState)->notNull()->after('organizationOrder');
38
39
            $this->addColumn(
40
                UserAssociation::tableName(),
41
                AlterUserStates::COLUMN_NAME,
42
                $type
43
            );
44
        }
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50
    public function safeDown()
51
    {
52
        echo "m190128_091129_user_state_column cannot be reverted.\n";
53
        return true;
54
    }
55
}
56