| Conditions | 6 |
| Paths | 3 |
| Total Lines | 44 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | public function safeUp() |
||
| 18 | { |
||
| 19 | if (Craft::$app->db->schema->getTableSchema('{{%twitter_accounts}}') !== null) { |
||
| 20 | return null; |
||
| 21 | } |
||
| 22 | |||
| 23 | $this->createTable( |
||
| 24 | '{{%twitter_accounts}}', |
||
| 25 | [ |
||
| 26 | 'id' => $this->primaryKey(), |
||
| 27 | 'token' => $this->string(50), |
||
| 28 | 'tokenSecret' => $this->string(50), |
||
| 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 | !isset($settings->tokenSecret) || |
||
| 41 | !$settings->token || |
||
| 42 | !$settings->tokenSecret |
||
| 43 | ) { |
||
| 44 | return null; |
||
| 45 | } |
||
| 46 | |||
| 47 | $this->insert( |
||
| 48 | '{{%twitter_accounts}}', |
||
| 49 | [ |
||
| 50 | 'token' => $settings->token, |
||
| 51 | 'tokenSecret' => $settings->tokenSecret, |
||
| 52 | ] |
||
| 53 | ); |
||
| 54 | |||
| 55 | // Reset token and token secret on the settings |
||
| 56 | $settings->token = null; |
||
| 57 | $settings->tokenSecret = null; |
||
| 58 | |||
| 59 | $plugin = Craft::$app->getPlugins()->getPlugin('twitter'); |
||
| 60 | Craft::$app->getPlugins()->savePluginSettings($plugin, $settings->toArray()); |
||
| 61 | } |
||
| 72 |