1010use Magento \Framework \App \Helper \AbstractHelper ;
1111use Magento \Framework \Exception \LocalizedException ;
1212use Magento \Framework \App \ProductMetadataInterface ;
13+ use Magento \Framework \App \DeploymentConfig ;
1314
1415class Data extends AbstractHelper
1516{
@@ -25,12 +26,9 @@ class Data extends AbstractHelper
2526 */
2627 protected $ configKeys = [
2728 'domain ' ,
28- 'enabled ' ,
2929 'log_level ' ,
3030 'mage_mode_development ' ,
3131 'environment ' ,
32- 'enable_script_tag ' ,
33- 'script_tag_placement ' ,
3432 ];
3533
3634 /**
@@ -50,17 +48,39 @@ class Data extends AbstractHelper
5048 * @param StoreManagerInterface $storeManager
5149 * @param State $appState
5250 */
53- public function __construct (Context $ context , StoreManagerInterface $ storeManager , State $ appState , ProductMetadataInterface $ productMetadataInterface
51+ public function __construct (
52+ Context $ context ,
53+ StoreManagerInterface $ storeManager ,
54+ State $ appState ,
55+ ProductMetadataInterface $ productMetadataInterface ,
56+ DeploymentConfig $ deploymentConfig
5457 ) {
5558 $ this ->storeManager = $ storeManager ;
5659 $ this ->appState = $ appState ;
5760 $ this ->scopeConfig = $ context ->getScopeConfig ();
5861 $ this ->productMetadataInterface = $ productMetadataInterface ;
62+ $ this ->deploymentConfig = $ deploymentConfig ;
5963 $ this ->collectModuleConfig ();
6064
6165 parent ::__construct ($ context );
6266 }
6367
68+ /**
69+ * @return mixed
70+ */
71+ public function getDSN ()
72+ {
73+ return $ this ->config ['domain ' ];
74+ }
75+
76+ /**
77+ * @return mixed
78+ */
79+ public function getEnvironment ()
80+ {
81+ return $ this ->config ['environment ' ];
82+ }
83+
6484 /**
6585 * @param $field
6686 * @param null $storeId
@@ -90,8 +110,10 @@ public function getGeneralConfig($code, $storeId = null)
90110 */
91111 public function collectModuleConfig ()
92112 {
93- foreach ($ this ->configKeys as $ key => $ value ) {
94- $ this ->config [ $ value ] = $ this ->getGeneralConfig ($ value );
113+ $ this ->config ['enabled ' ] = $ this ->deploymentConfig ->get ('sentry ' ) !== null ;
114+
115+ foreach ($ this ->configKeys as $ value ) {
116+ $ this ->config [$ value ] = $ this ->deploymentConfig ->get ('sentry/ ' . $ value );
95117 }
96118
97119 return $ this ->config ;
@@ -102,7 +124,11 @@ public function collectModuleConfig()
102124 */
103125 public function isActive ()
104126 {
105- return (! empty ($ this ->config ) && array_key_exists ('enabled ' , $ this ->config ) && $ this ->config ['enabled ' ] && ($ this ->isProductionMode () || $ this ->isOverwriteProductionMode ()));
127+ return !empty ($ this ->config )
128+ && array_key_exists ('enabled ' , $ this ->config )
129+ && $ this ->config ['enabled ' ]
130+ && $ this ->getDSN ()
131+ && ($ this ->isProductionMode () || $ this ->isOverwriteProductionMode ());
106132 }
107133
108134 /**
@@ -152,7 +178,7 @@ public function getStore()
152178 */
153179 public function useScriptTag ()
154180 {
155- return isset ( $ this ->config [ ' enable_script_tag ' ]) && $ this -> config [ 'enable_script_tag ' ] ;
181+ return $ this ->scopeConfig -> isSetFlag ( static :: XML_PATH_SRS . 'enable_script_tag ' ) ;
156182 }
157183
158184 /**
@@ -161,11 +187,12 @@ public function useScriptTag()
161187 */
162188 public function showScriptTagInThisBlock ($ blockName )
163189 {
164- if (!isset ($ this ->config ['script_tag_placement ' ])) {
190+ $ config = $ this ->getGeneralConfig ('script_tag_placement ' );
191+ if (!$ config ) {
165192 return false ;
166193 }
167194
168- $ name = 'sentry. ' . $ this -> config [ ' script_tag_placement ' ] ;
195+ $ name = 'sentry. ' . $ config ;
169196
170197 return $ name == $ blockName ;
171198 }
0 commit comments