Passed
Push — master ( 52718a...4c1d96 )
by Benjamin
11:03 queued 03:42
created

safeUp()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 10
c 2
b 0
f 0
nc 4
nop 0
dl 0
loc 23
rs 9.9332
1
<?php
2
3
namespace dukt\videos\migrations;
4
5
use Craft;
6
use craft\db\Migration;
7
use craft\helpers\ProjectConfig;
8
9
/**
10
 * m200925_135118_refactor_oauth_provider_options migration.
11
 */
12
class m200925_135118_refactor_oauth_provider_options extends Migration
13
{
14
    /**
15
     * @inheritdoc
16
     */
17
    public function safeUp()
18
    {
19
        $projectConfig = Craft::$app->projectConfig;
20
21
        // Don't make the same config changes twice
22
        $schemaVersion = $projectConfig->get('plugins.videos.schemaVersion', true);
23
24
        if (version_compare($schemaVersion, '1.0.3', '<')) {
25
            // Get OAuth provider options
26
            $oauthProviderOptions = $projectConfig->get('plugins.videos.settings.oauthProviderOptions', true);
27
28
            if(!is_array($oauthProviderOptions)) {
29
                return true;
30
            }
31
32
            $oauthProviderOptions = ProjectConfig::unpackAssociativeArray($oauthProviderOptions);
33
34
            // Reset OAuth provider options
35
            $projectConfig->set('plugins.videos.settings.oauthProviderOptions', [], "Reset the oauth provider options");
36
37
            // Rebuild OAuth provider options
38
            foreach($oauthProviderOptions as $providerHandle => $provider) {
39
                $projectConfig->set('plugins.videos.settings.oauthProviderOptions.'.$providerHandle, $provider, "Save the “{$providerHandle}” provider");
40
            }
41
        }
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function safeDown()
48
    {
49
        echo "m200925_135118_refactor_oauth_provider_options cannot be reverted.\n";
50
        return false;
51
    }
52
}
53