m190815_143313_UpdateFieldLayouts   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 22
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A safeUp() 0 7 2
A safeDown() 0 4 1
1
<?php
2
3
namespace angellco\spoon\migrations;
4
5
use angellco\spoon\models\BlockType;
6
use Craft;
7
use craft\db\Migration;
8
use craft\records\FieldLayout as FieldLayoutRecord;
9
10
/**
11
 * m190815_143313_UpdateFieldLayouts migration.
12
 */
13
class m190815_143313_UpdateFieldLayouts extends Migration
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public function safeUp()
19
    {
20
        $records = FieldLayoutRecord::findWithTrashed()->where(['type' => 'Spoon_BlockType'])->all();
21
22
        foreach ($records as $record) {
23
            $record->type = BlockType::class;
0 ignored issues
show
Bug introduced by
Accessing type on the interface yii\db\ActiveRecordInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
24
            $record->save(false);
25
        }
26
    }
27
28
    /**
29
     * @inheritdoc
30
     */
31
    public function safeDown()
32
    {
33
        echo "m190815_143313_UpdateFieldLayouts cannot be reverted.\n";
34
        return false;
35
    }
36
}
37