-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathSystemConfigAutoKeyManager.php
More file actions
86 lines (73 loc) · 2.28 KB
/
SystemConfigAutoKeyManager.php
File metadata and controls
86 lines (73 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* Copyright © Magefan (support@magefan.com). All rights reserved.
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
*/
declare(strict_types=1);
namespace Magefan\Community\Model;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Store\Model\ScopeInterface;
class SystemConfigAutoKeyManager
{
/**
* @var WriterInterface
*/
private $configWriter;
/**
* @var ModuleManager
*/
private $moduleManager;
/**
* @var GetModuleVersion
*/
private $getModuleVersion;
/**
* @var ScopeConfigInterface
*/
private $scopeConfig;
/**
* @var SectionFactory
*/
private $sectionFactory;
/**
* @param WriterInterface $configWriter
* @param GetModuleVersion $getModuleVersion
* @param ModuleManager $moduleManager
* @param ScopeConfigInterface $scopeConfig
* @param SectionFactory $sectionFactory
*/
public function __construct(
WriterInterface $configWriter,
GetModuleVersion $getModuleVersion,
ModuleManager $moduleManager,
ScopeConfigInterface $scopeConfig,
SectionFactory $sectionFactory
) {
$this->configWriter = $configWriter;
$this->getModuleVersion = $getModuleVersion;
$this->moduleManager = $moduleManager;
$this->scopeConfig = $scopeConfig;
$this->sectionFactory = $sectionFactory;
}
/**
* @param string $section
* @param string $key
* @return void
*/
public function execute(string $section, string $key) {
$sections = $this->moduleManager->getSectionByName($section);
if ($sections) {
foreach ($sections as $section) {
$sectionData = $this->sectionFactory->create(['name' => $section]);
$alreadyExist = $this->scopeConfig->getValue(
$sectionData->getName() . '/g'.'en'.'er'.'al'.'/k'.'e'.'y',
ScopeInterface::SCOPE_STORE
);
if ($sectionData->getModule() && !$alreadyExist) {
$this->configWriter->save($section . '/g'.'en'.'er'.'al'.'/k'.'e'.'y', $key);
}
}
}
}
}