Completed
Push — develop ( 65300b...355392 )
by Nate
04:47
created

m190326_080222_namespace   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 40
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A safeUp() 0 34 4
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/craft-element-lists/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-element-lists/
7
 */
8
9
namespace flipbox\craft\element\lists\migrations;
10
11
use craft\db\Migration;
12
use craft\helpers\ArrayHelper;
13
use craft\helpers\Json;
14
use craft\helpers\StringHelper;
15
use craft\records\Field;
16
use flipbox\craft\element\lists\fields\UserList;
17
18
class m190326_080222_namespace extends Migration
19
{
20
    /**
21
     * @inheritdoc
22
     */
23
    public function safeUp()
24
    {
25
        $records = Field::find()
26
            ->andWhere(
27
                [
28
                'type' => "flipbox\\element\\lists\\fields\\UserSourceList"
29
                ]
30
            )
31
            ->all();
32
33
        $success = true;
34
35
        /**
36
 * @var Field $record
37
*/
38
        foreach ($records as $record) {
39
            $record->type = UserList::class;
40
41
            $settings = $record->settings ?? [];
42
            if (is_string($settings)) {
43
                $settings = Json::decodeIfJson($settings);
44
            }
45
46
            // Update settings
47
            $record->settings = $settings;
48
49
            // Save
50
            if (!$record->save()) {
51
                $success = false;
52
            }
53
        }
54
55
        return $success;
56
    }
57
}
58