GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — issue-331 ( 5ccbd7...4515e7 )
by
unknown
10:19
created

m160620_112036_config_fix_parent_only::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
use app\modules\shop\models\ConfigConfigurationModel;
4
use yii\db\Migration;
5
use yii\helpers\ArrayHelper;
6
7
class m160620_112036_config_fix_parent_only extends Migration
8
{
9
    public function up()
10
    {
11
12
        $fileName = Yii::getAlias('@app/config/web-configurables.php');
13
        if (true === is_file($fileName)) {
14
            $array = include_once($fileName);
15
            if (true === is_array($array) &&
16
               null  !== $onlyParent = ArrayHelper::getValue($array, 'modules.shop.filterOnlyByParentProduct', null)
17
            ) {
18
                unset($array['modules']['shop']['filterOnlyByParentProduct']);
19
                $array['modules']['shop']['productsFilteringMode'] = $onlyParent === true ?
20
                    ConfigConfigurationModel::FILTER_PARENTS_ONLY :
21
                    ConfigConfigurationModel::FILTER_CHILDREN_ONLY;
22
23
                $writer = new \app\modules\config\helpers\ApplicationConfigWriter([
24
                    'filename' => '@app/config/web-configurables.php',
25
                    'loadExistingConfiguration' => false,
26
                ]);
27
                $writer->addValues($array);
28
                $writer->commit();
29
30
            }
31
        }
32
33
34
        $shopFilename = Yii::getAlias('@app/config/configurables-state/shop.php');
35
        if (true === file_exists($shopFilename)) {
36
            $shopConfigurablesArray = include($shopFilename);
37
            if (true === is_array($shopConfigurablesArray) &&
38
              null !== $onlyParent = ArrayHelper::getValue($shopConfigurablesArray, 'filterOnlyByParentProduct', null)
39
            ) {
40
                unset($shopConfigurablesArray['filterOnlyByParentProduct']);
41
                $shopConfigurablesArray['productsFilteringMode'] = $onlyParent === true ?
42
                    ConfigConfigurationModel::FILTER_PARENTS_ONLY :
43
                    ConfigConfigurationModel::FILTER_CHILDREN_ONLY;
44
                $writer = new \app\modules\config\helpers\ApplicationConfigWriter([
45
                    'filename' => '@app/config/configurables-state/shop.php',
46
                    'loadExistingConfiguration' => false,
47
                ]);
48
                $writer->addValues($shopConfigurablesArray);
49
                $writer->commit();
50
            }
51
        }
52
53
    }
54
55
    public function down()
56
    {
57
        echo "m160620_112036_config_fix_parent_only cannot be reverted.\n";
58
59
        return false;
60
    }
61
62
    /*
63
    // Use safeUp/safeDown to run migration code within a transaction
64
    public function safeUp()
65
    {
66
    }
67
68
    public function safeDown()
69
    {
70
    }
71
    */
72
}
73