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

AlterUserStates::safeDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
class AlterUserStates extends Migration
20
{
21
    /**
22
     * The state column name
23
     */
24
    const COLUMN_NAME = 'state';
25
26
    /**
27
     * @inheritdoc
28
     * @throws \Throwable
29
     */
30
    public function safeUp()
31
    {
32
        $states = array_keys(Organizations::getInstance()->getSettings()->getUserStates());
33
        $defaultState = Organizations::getInstance()->getSettings()->getDefaultUserState();
34
35
        $type = $this->enum(
36
            self::COLUMN_NAME,
37
            $states
38
        )->defaultValue($defaultState)->notNull();
39
40
        $this->alterColumn(
41
            UserAssociation::tableName(),
42
            self::COLUMN_NAME,
43
            $type
44
        );
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50
    public function safeDown()
51
    {
52
        return false;
53
    }
54
}
55