Conditions | 4 |
Paths | 3 |
Total Lines | 39 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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 | // If OAuth token is set on the settings, keep it |
||
36 | $settings = Plugin::$plugin->getSettings(); |
||
37 | |||
38 | if ( |
||
39 | !isset($settings->token) || |
||
40 | !$settings->token |
||
41 | ) { |
||
42 | return null; |
||
43 | } |
||
44 | |||
45 | $this->insert( |
||
46 | '{{%facebook_accounts}}', |
||
47 | [ |
||
48 | 'token' => Json::encode($settings->token), |
||
49 | ] |
||
50 | ); |
||
51 | |||
52 | // Reset token and token secret on the settings |
||
53 | $settings->token = null; |
||
54 | |||
55 | $plugin = Craft::$app->getPlugins()->getPlugin('facebook'); |
||
56 | Craft::$app->getPlugins()->savePluginSettings($plugin, $settings->toArray()); |
||
57 | } |
||
68 |