m161117_000001_remove_account_explorer_data_setting   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A safeDown() 0 5 1
A safeUp() 0 25 3
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