Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix overriding configuration #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Magento\Framework\App\Helper\Context;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\App\State;
use Magento\Framework\DB\Adapter\TableNotFoundException;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
Expand Down Expand Up @@ -168,19 +167,18 @@ public function collectModuleConfig(): array
return $this->config;
}

try {
$this->config['enabled'] = $this->scopeConfig->getValue('sentry/environment/enabled')
?? $this->deploymentConfig->get('sentry') !== null;
} catch (TableNotFoundException $e) {
$this->config['enabled'] = null;
$this->config['enabled'] = $this->deploymentConfig->get('sentry') !== null;

foreach ($this->configKeys as $key) {
$this->config[$key] = $this->deploymentConfig->get('sentry/' . $key);
}

foreach ($this->configKeys as $value) {
try {
$this->config[$value] = $this->scopeConfig->getValue('sentry/environment/'.$value)
?? $this->deploymentConfig->get('sentry/'.$value);
} catch (TableNotFoundException $e) {
$this->config[$value] = null;
if ($this->scopeConfig->isSetFlag('sentry/environment/override')) {
$allowedConfigKeys = array_merge(['enabled'], $this->configKeys);
foreach ($this->scopeConfig->getValue('sentry/environment') as $key => $value) {
if ($value !== null && in_array($key, $allowedConfigKeys, true)) {
$this->config[$key] = $value;
}
}
}

Expand Down
28 changes: 21 additions & 7 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,46 +85,60 @@
<group id="environment" translate="label comment" sortOrder="20" showInDefault="1" showInStore="0" showInWebsite="0">
<label>Environment Configuration</label>
<comment><![CDATA[Setting the configuration here will override the Magento Deployment Configuration.]]></comment>
<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<field id="override" translate="label" type="select" sortOrder="5" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Override environment configuration</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<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>
</field>
<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<depends>
<field id="override">1</field>
</depends>
</field>
<field id="dsn" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<field id="dsn" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>DSN</label>
<depends>
<field id="override">1</field>
<field id="enabled">1</field>
</depends>
</field>
<field id="logrocket_key" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<field id="logrocket_key" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Logrocket Key</label>
<depends>
<field id="override">1</field>
<field id="enabled">1</field>
</depends>
</field>
<field id="environment" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<field id="environment" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Environment</label>
<depends>
<field id="override">1</field>
<field id="enabled">1</field>
</depends>
</field>
<field id="log_level" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<field id="log_level" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Log Level</label>
<source_model>JustBetter\Sentry\Model\Config\Source\LogLevel</source_model>
<depends>
<field id="override">1</field>
<field id="enabled">1</field>
</depends>
</field>
<field id="tracing_enabled" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<field id="tracing_enabled" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Tracing Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<depends>
<field id="override">1</field>
<field id="enabled">1</field>
</depends>
</field>
<field id="tracing_sample_rate" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<field id="tracing_sample_rate" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Tracing Sample Rate</label>
<validate>validate-not-negative-number validate-number</validate>
<depends>
<field id="override">1</field>
<field id="enabled">1</field>
</depends>
</field>
Expand Down
Loading