m190109_121422_namespace   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 51
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A safeUp() 0 18 3
A safeDown() 0 18 3
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/domains/license
6
 * @link       https://www.flipboxfactory.com/software/domains/
7
 */
8
9
namespace flipbox\craft\domains\migrations;
10
11
use craft\db\Migration;
12
use craft\records\Field;
13
use flipbox\craft\domains\fields\Domains;
14
15
class m190109_121422_namespace extends Migration
16
{
17
    /**
18
     * The old class name
19
     */
20
    const OLD_CLASS = "flipbox\\domains\\fields\\Domains";
21
22
    /**
23
     * @inheritdoc
24
     */
25
    public function safeUp()
26
    {
27
        $query = Field::find();
28
        $query->andWhere(['type' => self::OLD_CLASS]);
29
30
        $success = true;
31
32
        /** @var Field $record */
33
        foreach ($query->all() as $record) {
34
            $record->type = Domains::class;
35
36
            if (!$record->save(true, ['type'])) {
37
                $success = false;
38
            }
39
        }
40
41
        return $success;
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function safeDown()
48
    {
49
        $query = Field::find();
50
        $query->andWhere(['type' => Domains::class]);
51
52
        $success = true;
53
54
        /** @var Field $record */
55
        foreach ($query->all() as $record) {
56
            $record->type = static::OLD_CLASS;
57
58
            if (!$record->save(true, ['type'])) {
59
                $success = false;
60
            }
61
        }
62
63
        return $success;
64
    }
65
}
66