Passed
Push — develop ( fd68c5...61e97f )
by Andris
26:09 queued 11s
created

m210603_213100_add_gql_schema_components   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A safeDown() 0 4 1
A safeUp() 0 13 4
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace nystudio107\seomatic\migrations;
4
5
use Craft;
6
use craft\db\Migration;
7
8
/**
9
 * m210603_213100_add_gql_schema_components migration.
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
10
 */
0 ignored issues
show
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
11
class m210603_213100_add_gql_schema_components extends Migration
0 ignored issues
show
Coding Style introduced by
Class name is not valid; consider M210603_213100_Add_Gql_Schema_Components instead
Loading history...
Coding Style introduced by
Class name must begin with a capital letter
Loading history...
12
{
13
    /**
14
     * @inheritdoc
15
     */
16
    public function safeUp()
17
    {
18
        // Don't make the same config changes twice
19
        $projectConfig = Craft::$app->getProjectConfig();
20
        $schemaVersion = $projectConfig->get('plugins.seomatic.schemaVersion', true);
21
22
        if (version_compare($schemaVersion, '3.0.10', '<')) {
23
            foreach ($projectConfig->get('graphql.schemas') ?? [] as $schemaUid => $schemaComponents) {
24
                if (isset($schemaComponents['scope'])) {
25
                    $scope = $schemaComponents['scope'];
26
                    $scope[] = 'seomatic.all:read';
27
28
                    $projectConfig->set("graphql.schemas.$schemaUid.scope", $scope);
29
                }
30
            }
31
        }
32
    }
33
34
    /**
35
     * @inheritdoc
36
     */
37
    public function safeDown()
38
    {
39
        echo "m210603_213100_add_gql_schema_components cannot be reverted.\n";
40
        return false;
41
    }
42
}
43