m210308_211023_accounts   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 38
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A safeUp() 0 24 2
A safeDown() 0 4 1
1
<?php
2
3
namespace dukt\facebook\migrations;
4
5
use Craft;
6
use craft\db\Migration;
7
use craft\helpers\Json;
8
use dukt\facebook\Plugin;
9
10
/**
11
 * m210308_211023_accounts migration.
12
 */
13
class m210308_211023_accounts extends Migration
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public function safeUp()
19
    {
20
        if (Craft::$app->db->schema->getTableSchema('{{%facebook_accounts}}') !== null) {
21
            return null;
22
        }
23
24
        $this->createTable(
25
            '{{%facebook_accounts}}',
26
            [
27
                'id'                => $this->primaryKey(),
28
                'token'             => $this->text(),
29
                'dateCreated'       => $this->dateTime()->notNull(),
30
                'dateUpdated'       => $this->dateTime()->notNull(),
31
                'uid'               => $this->uid()
32
            ]
33
        );
34
35
        // Don't try to port the token to the new accounts table since the OAuth scope has changed in Facebook 2.0.4
36
37
        // Reset the token on the settings since it will now be stored in the accounts table
38
        $settings = Plugin::$plugin->getSettings();
39
        $settings->token = null;
40
        $plugin = Craft::$app->getPlugins()->getPlugin('facebook');
41
        Craft::$app->getPlugins()->savePluginSettings($plugin, $settings->toArray());
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function safeDown()
48
    {
49
        echo "m210308_211023_accounts cannot be reverted.\n";
50
        return false;
51
    }
52
}
53