safeDown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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