Conditions | 3 |
Paths | 3 |
Total Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 12 |
Changes | 0 |
1 | <?php |
||
32 | public function safeUp() |
||
33 | { |
||
34 | $table = $this->getDb()->getSchema()->getTableSchema( |
||
35 | $this->getDb()->getSchema()->getRawTableName(static::tableName()) |
||
36 | ); |
||
37 | |||
38 | if (isset($table->columns['name'])) { |
||
39 | return true; |
||
40 | } |
||
41 | |||
42 | $this->addColumn( |
||
43 | static::tableName(), |
||
44 | 'name', |
||
45 | $this->string()->after('id')->notNull() |
||
46 | ); |
||
47 | |||
48 | $records = (new Query()) |
||
49 | ->from(static::tableName()) |
||
50 | ->select(['id', 'handle']) |
||
51 | ->all(); |
||
52 | |||
53 | foreach ($records as $record) { |
||
54 | Craft::$app->getDb()->createCommand() |
||
55 | ->update( |
||
56 | static::tableName(), |
||
57 | ['name' => StringHelper::titleize($record['handle'])], |
||
58 | ['id' => $record['id']] |
||
59 | ) |
||
60 | ->execute(); |
||
61 | } |
||
62 | } |
||
63 | } |
||
64 |