m180507_121214_user_association_sort   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A safeUp() 0 22 3
A safeDown() 0 5 1
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\records\UserAssociation;
13
14
/**
15
 * This migration adds a new column to support multiple user association sort types.
16
 */
17
class m180507_121214_user_association_sort extends Migration
18
{
19
    /**
20
     * @inheritdoc
21
     * @throws \yii\base\NotSupportedException
22
     */
23
    public function safeUp()
24
    {
25
        $table = $this->getDb()->getSchema()->getTableSchema(
26
            UserAssociation::tableName()
27
        );
28
29
        if (isset($table->columns['sortOrder'])) {
30
            $this->renameColumn(
31
                UserAssociation::tableName(),
32
                'sortOrder',
33
                'organizationOrder'
34
            );
35
        }
36
37
        if (!isset($table->columns['userOrder'])) {
38
            $this->addColumn(
39
                UserAssociation::tableName(),
40
                'userOrder',
41
                $this->smallInteger()->unsigned()->after('organizationid')
42
            );
43
        }
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public function safeDown()
50
    {
51
        echo "m180507_1212141_user_association_sort cannot be reverted.\n";
52
        return true;
53
    }
54
}
55