Passed
Pull Request — master (#16)
by
unknown
15:25
created

UpgradeData   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 13
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A upgrade() 0 24 3
1
<?php
2
3
namespace DigitalOrigin\Pmt\Setup;
4
5
use Magento\Framework\Setup\UpgradeDataInterface;
6
use Magento\Framework\Setup\ModuleContextInterface;
7
use Magento\Framework\Setup\ModuleDataSetupInterface;
8
use DigitalOrigin\Pmt\Helper\Config;
9
10
class UpgradeData implements UpgradeDataInterface
11
{
12
    /** Config tablename */
13
    const CONFIG_TABLE = 'pmt_config';
14
15
    /** @var Config */
16
    public $config;
17
18
    public function __construct(Config $config)
19
    {
20
        $this->config = $config;
21
    }
22
23
    /**
24
     * @param ModuleDataSetupInterface $setup
25
     * @param ModuleContextInterface   $context
26
     */
27
    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
28
    {
29
        $setup->startSetup();
30
31
        //Any version lower than 7.2.0: public_key => pmt_public_key, secret_key => pmt_private_key //TODO
32
        /*if (version_compare($context->getVersion(), '7.2.0') > 0) {
33
            print_r($this->config, true);
34
        }*/
35
36
        if (version_compare($context->getVersion(), '7.2.0') < 0) {
37
            $newConfigs = array(
38
                /* INSERT NEW CONFIGS PARAMS HERE:config=>'<config>','value'=>'<value>'*/);
39
            foreach ($newConfigs as $config => $value) {
40
                $setup->getConnection()->insert(self::CONFIG_TABLE, array('config'=>$config, 'value'=>$value));
41
            }
42
        }
43
44
        //Allow symlinks for product simulator. Admin menu: Stores->Configuration->Advanced->Developer->Template
45
        $setup->getConnection()->insert(
46
            'core_config_data',
47
            array('value'=>1, 'path'=>'dev/template/allow_symlink','scope'=>'default')
48
        );
49
50
        $setup->endSetup();
51
    }
52
}