m191122_115434_UpgradeToSupportProjectConfig   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 2
b 0
f 0
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A safeUp() 0 15 2
A safeDown() 0 4 1
1
<?php
2
3
namespace angellco\spoon\migrations;
4
5
use angellco\spoon\helpers\ProjectConfig as ProjectConfigHelper;
6
use angellco\spoon\services\BlockTypes;
7
use angellco\spoon\Spoon;
8
use Craft;
9
use craft\db\Migration;
10
use craft\helpers\App;
11
12
/**
13
 * m191122_115434_UpgradeToSupportProjectConfig migration.
14
 */
15
class m191122_115434_UpgradeToSupportProjectConfig extends Migration
16
{
17
    /**
18
     * @inheritdoc
19
     */
20
    public function safeUp()
21
    {
22
23
        $projectConfig = Craft::$app->getProjectConfig();
24
25
        // Don't make the same config changes twice
26
        $schemaVersion = $projectConfig->get('plugins.spoon.schemaVersion', true);
27
28
        if (version_compare($schemaVersion, '3.4.0', '<')) {
29
            // Run the rebuild and commit it to project.yaml
30
            $projectConfig->muteEvents = true;
31
32
            $projectConfig->set(BlockTypes::CONFIG_BLOCKTYPE_KEY, ProjectConfigHelper::rebuildProjectConfig());
33
34
            $projectConfig->muteEvents = false;
35
        }
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function safeDown()
42
    {
43
        echo "m191122_115434_UpgradeToSupportProjectConfig cannot be reverted.\n";
44
        return false;
45
    }
46
}
47