m190326_080222_namespace   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
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 36
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A safeUp() 0 30 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\Json;
13
use craft\records\Field;
14
use flipbox\craft\element\lists\fields\UserList;
15
16
class m190326_080222_namespace extends Migration
17
{
18
    /**
19
     * @inheritdoc
20
     */
21
    public function safeUp()
22
    {
23
        $records = Field::find()
24
            ->andWhere([
25
                'type' => "flipbox\\element\\lists\\fields\\UserSourceList"
26
            ])
27
            ->all();
28
29
        $success = true;
30
31
        /** @var Field $record */
32
        foreach ($records as $record) {
33
            $record->type = UserList::class;
34
35
            $settings = $record->settings ?? [];
36
            if (is_string($settings)) {
37
                $settings = Json::decodeIfJson($settings);
38
            }
39
40
            // Update settings
41
            $record->settings = $settings;
42
43
            // Save
44
            if (!$record->save()) {
45
                $success = false;
46
            }
47
        }
48
49
        return $success;
50
    }
51
}
52