Skip to content

Commit 0226de7

Browse files
committed
fix overriding configuration
1 parent a398817 commit 0226de7

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

Helper/Data.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
use Magento\Framework\App\Helper\Context;
1313
use Magento\Framework\App\ProductMetadataInterface;
1414
use Magento\Framework\App\State;
15-
use Magento\Framework\DB\Adapter\TableNotFoundException;
16-
use Magento\Framework\Exception\FileSystemException;
1715
use Magento\Framework\Exception\RuntimeException;
1816
use Magento\Framework\Serialize\Serializer\Json;
1917
use Magento\Store\Model\ScopeInterface;
@@ -210,20 +208,19 @@ public function collectModuleConfig(): array
210208
if (isset($this->config[$storeId]['enabled'])) {
211209
return $this->config[$storeId];
212210
}
211+
$this->config[$storeId]['enabled'] = $this->deploymentConfig->get('sentry') !== null;
213212

214-
try {
215-
$this->config[$storeId]['enabled'] = $this->scopeConfig->getValue('sentry/environment/enabled', ScopeInterface::SCOPE_STORE)
216-
?? $this->deploymentConfig->get('sentry') !== null;
217-
} catch (TableNotFoundException|FileSystemException|RuntimeException $e) {
218-
$this->config[$storeId]['enabled'] = null;
213+
foreach ($this->configKeys as $key) {
214+
$this->config[$storeId][$key] = $this->deploymentConfig->get('sentry/' . $key);
219215
}
220216

221-
foreach ($this->configKeys as $value) {
222-
try {
223-
$this->config[$storeId][$value] = $this->scopeConfig->getValue('sentry/environment/'.$value, ScopeInterface::SCOPE_STORE)
224-
?? $this->deploymentConfig->get('sentry/'.$value);
225-
} catch (TableNotFoundException|FileSystemException|RuntimeException $e) {
226-
$this->config[$storeId][$value] = null;
217+
if ($this->scopeConfig->isSetFlag('sentry/environment/override', ScopeInterface::SCOPE_STORE, $storeId)) {
218+
$allowedConfigKeys = array_merge(['enabled'], $this->configKeys);
219+
$scopeConfig = $this->scopeConfig->getValue('sentry/environment', ScopeInterface::SCOPE_STORE, $storeId);
220+
foreach ($scopeConfig as $key => $value) {
221+
if ($value !== null && in_array($key, $allowedConfigKeys, true)) {
222+
$this->config[$storeId][$key] = $value;
223+
}
227224
}
228225
}
229226

etc/adminhtml/system.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,46 +85,60 @@
8585
<group id="environment" translate="label comment" sortOrder="20" showInDefault="1" showInStore="1" showInWebsite="1" canRestore="1">
8686
<label>Environment Configuration</label>
8787
<comment><![CDATA[Setting the configuration here will override the Magento Deployment Configuration.]]></comment>
88+
<field id="override" translate="label" type="select" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
89+
<label>Override environment configuration</label>
90+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
91+
<comment>If enabled, the deployment configuration from env.php got overridden by the following fields. Reset fields to system value, if you want to use the deployment configuration from env.php</comment>
92+
</field>
8893
<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInStore="0" showInWebsite="0" canRestore="1">
8994
<label>Enabled</label>
9095
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
96+
<depends>
97+
<field id="override">1</field>
98+
</depends>
9199
</field>
92100
<field id="dsn" translate="label" type="text" sortOrder="10" showInDefault="1" showInStore="0" showInWebsite="0" canRestore="1">
93101
<label>DSN</label>
94102
<depends>
103+
<field id="override">1</field>
95104
<field id="enabled">1</field>
96105
</depends>
97106
</field>
98107
<field id="logrocket_key" translate="label" type="text" sortOrder="10" showInDefault="1" showInStore="1" showInWebsite="1" canRestore="1">
99108
<label>Logrocket Key</label>
100109
<depends>
110+
<field id="override">1</field>
101111
<field id="enabled">1</field>
102112
</depends>
103113
</field>
104114
<field id="environment" translate="label" type="text" sortOrder="10" showInDefault="1" showInStore="0" showInWebsite="0" canRestore="1">
105115
<label>Environment</label>
106116
<depends>
117+
<field id="override">1</field>
107118
<field id="enabled">1</field>
108119
</depends>
109120
</field>
110121
<field id="log_level" translate="label" type="select" sortOrder="10" showInDefault="1" showInStore="0" showInWebsite="0" canRestore="1">
111122
<label>Log Level</label>
112123
<source_model>JustBetter\Sentry\Model\Config\Source\LogLevel</source_model>
113124
<depends>
125+
<field id="override">1</field>
114126
<field id="enabled">1</field>
115127
</depends>
116128
</field>
117-
<field id="tracing_enabled" translate="label" type="text" sortOrder="10" showInDefault="1" showInStore="1" showInWebsite="1" canRestore="1">
129+
<field id="tracing_enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInStore="1" showInWebsite="1" canRestore="1">
118130
<label>Tracing Enabled</label>
119131
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
120132
<depends>
133+
<field id="override">1</field>
121134
<field id="enabled">1</field>
122135
</depends>
123136
</field>
124137
<field id="tracing_sample_rate" translate="label" type="text" sortOrder="10" showInDefault="1" showInStore="1" showInWebsite="1" canRestore="1">
125138
<label>Tracing Sample Rate</label>
126139
<validate>validate-not-negative-number validate-number</validate>
127140
<depends>
141+
<field id="override">1</field>
128142
<field id="enabled">1</field>
129143
</depends>
130144
</field>

0 commit comments

Comments
 (0)