m161021_000001_force_connect   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A safeUp() 0 21 2
A safeDown() 0 5 1
1
<?php
2
3
namespace dukt\analytics\migrations;
4
5
use craft\db\Migration;
6
use craft\db\Query;
7
use craft\helpers\Json;
8
9
/**
10
 * The class name is the UTC timestamp in the format of mYYMMDD_HHMMSS_pluginHandle_migrationName
11
 */
12
class m161021_000001_force_connect extends Migration
13
{
14
    /**
15
     * Any migration code in here is wrapped inside of a transaction.
16
     *
17
     * @return bool
18
     */
19
    public function safeUp()
20
    {
21
        // set forceConnect setting to true
22
        $row = (new Query())
23
            ->select('*')
24
            ->from(['{{%plugins}}'])
25
            ->where(['handle' => 'analytics'])
26
            ->one();
27
28
        if ($row) {
29
            $settingsJson = $row['settings'];
30
31
            $settings = Json::decode($settingsJson);
32
            $settings['forceConnect'] = true;
33
34
            $settingsJson = Json::encode($settings);
35
36
            $this->update('{{%plugins}}', ['settings' => $settingsJson], ['id' => $row['id']]);
37
        }
38
39
        return true;
40
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45
    public function safeDown()
46
    {
47
        echo "m161021_000001_force_connect cannot be reverted.\n";
48
49
        return false;
50
    }
51
}
52