m210308_211023_accounts::safeDown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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