m190815_143313_UpdateFieldLayouts::safeUp()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 0
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