9
9
use Cloudinary \Cloudinary \Core \Exception \InvalidCredentials ;
10
10
use Magento \Config \Model \Config \Backend \Encrypted ;
11
11
use Magento \Framework \App \Cache \TypeListInterface ;
12
+ use Magento \Framework \App \Config \ReinitableConfigInterface ;
12
13
use Magento \Framework \App \Config \ScopeConfigInterface ;
13
14
use Magento \Framework \Data \Collection \AbstractDb ;
14
15
use Magento \Framework \Encryption \EncryptorInterface ;
@@ -39,6 +40,13 @@ class Credentials extends Encrypted
39
40
*/
40
41
private $ api ;
41
42
43
+ /**
44
+ * Application config
45
+ *
46
+ * @var ScopeConfigInterface
47
+ */
48
+ protected $ appConfig ;
49
+
42
50
/**
43
51
* @param Context $context
44
52
* @param Registry $registry
@@ -50,6 +58,7 @@ class Credentials extends Encrypted
50
58
* @param AbstractDb $resourceCollection
51
59
* @param ConfigurationBuilder $configurationBuilder
52
60
* @param Api $api
61
+ * @param ReinitableConfigInterface $appConfig
53
62
* @param array $data
54
63
*/
55
64
public function __construct (
@@ -63,11 +72,13 @@ public function __construct(
63
72
AbstractDb $ resourceCollection = null ,
64
73
ConfigurationBuilder $ configurationBuilder ,
65
74
Api $ api ,
75
+ ReinitableConfigInterface $ appConfig ,
66
76
array $ data = []
67
77
) {
68
78
$ this ->configuration = $ configuration ;
69
79
$ this ->configurationBuilder = $ configurationBuilder ;
70
80
$ this ->api = $ api ;
81
+ $ this ->appConfig = $ appConfig ;
71
82
72
83
parent ::__construct (
73
84
$ context ,
@@ -87,7 +98,13 @@ public function beforeSave()
87
98
88
99
parent ::beforeSave ();
89
100
90
- if ($ rawValue ) {
101
+ $ this ->cacheTypeList ->cleanType (\Magento \Framework \App \Cache \Type \Config::TYPE_IDENTIFIER );
102
+ $ this ->appConfig ->reinit ();
103
+
104
+ if ($ rawValue || $ this ->configuration ->isEnabled (false )) {
105
+ if (!$ rawValue ) {
106
+ throw new ValidatorException (__ (self ::CREDENTIALS_CHECK_MISSING ));
107
+ }
91
108
if ($ this ->isSaveAllowed ()) {
92
109
$ this ->validate ($ this ->getCredentialsFromEnvironmentVariable ($ rawValue ));
93
110
} else {
0 commit comments