safeUp()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 25
rs 9.8333
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 m161117_000001_remove_account_explorer_data_setting 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
23
        $row = (new Query())
24
            ->select('*')
25
            ->from(['{{%plugins}}'])
26
            ->where(['handle' => 'analytics'])
27
            ->one();
28
29
        if ($row) {
30
            $settingsJson = $row['settings'];
31
32
            $settings = Json::decode($settingsJson);
33
34
            if (isset($settings['accountExplorerData'])) {
35
                unset($settings['accountExplorerData']);
36
            }
37
38
            $settingsJson = Json::encode($settings);
39
40
            $this->update('{{%plugins}}', ['settings' => $settingsJson], ['id' => $row['id']]);
41
        }
42
43
        return true;
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public function safeDown()
50
    {
51
        echo "m161117_000001_remove_account_explorer_data_setting cannot be reverted.\n";
52
53
        return false;
54
    }
55
}
56