Completed
Push — develop ( 664cbd...b0b15d )
by Nate
03:42
created

m190413_125316_relations::safeUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 0
cts 34
cp 0
rs 9.328
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
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;
12
use craft\db\Migration;
13
use flipbox\craft\element\lists\records\Association;
14
use yii\db\Query;
15
16
class m190413_125316_relations extends Migration
17
{
18
    /**
19
     * @return bool
20
     * @throws \yii\db\Exception
21
     */
22
    public function safeUp()
23
    {
24
        $query = (new Query())
25
            ->from(['{{%elementlist}}'])
26
            ->select([
27
                'fieldId',
28
                'sourceId',
29
                'targetId',
30
                'sortOrder',
31
                'dateCreated',
32
                'dateUpdated',
33
                'uid',
34
                'siteId as sourceSiteId',
35
            ]);
36
37
        foreach ($query->batch(1000) as $batch) {
38
            Craft::$app->getDb()->createCommand()->batchInsert(
39
                Association::tableName(),
40
                [
41
                    'fieldId',
42
                    'sourceId',
43
                    'targetId',
44
                    'sortOrder',
45
                    'dateCreated',
46
                    'dateUpdated',
47
                    'uid',
48
                    'siteId'
49
                ],
50
                $batch,
51
                false
52
            )->execute();
53
        }
54
55
        $this->dropTableIfExists('elementlist');
56
57
        return true;
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63
    public function safeDown()
64
    {
65
        return true;
66
    }
67
}
68