Skip to content

Commit 94ccf77

Browse files
author
Pini
authored
Merge pull request #15 from cloudinary/v1.7.3
Fixes & improvements in environment variable validationFixes
2 parents b44bbe7 + 79af181 commit 94ccf77

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Diff for: Model/Config/Backend/Credentials.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Cloudinary\Cloudinary\Core\Exception\InvalidCredentials;
1010
use Magento\Config\Model\Config\Backend\Encrypted;
1111
use Magento\Framework\App\Cache\TypeListInterface;
12+
use Magento\Framework\App\Config\ReinitableConfigInterface;
1213
use Magento\Framework\App\Config\ScopeConfigInterface;
1314
use Magento\Framework\Data\Collection\AbstractDb;
1415
use Magento\Framework\Encryption\EncryptorInterface;
@@ -39,6 +40,13 @@ class Credentials extends Encrypted
3940
*/
4041
private $api;
4142

43+
/**
44+
* Application config
45+
*
46+
* @var ScopeConfigInterface
47+
*/
48+
protected $appConfig;
49+
4250
/**
4351
* @param Context $context
4452
* @param Registry $registry
@@ -50,6 +58,7 @@ class Credentials extends Encrypted
5058
* @param AbstractDb $resourceCollection
5159
* @param ConfigurationBuilder $configurationBuilder
5260
* @param Api $api
61+
* @param ReinitableConfigInterface $appConfig
5362
* @param array $data
5463
*/
5564
public function __construct(
@@ -63,11 +72,13 @@ public function __construct(
6372
AbstractDb $resourceCollection = null,
6473
ConfigurationBuilder $configurationBuilder,
6574
Api $api,
75+
ReinitableConfigInterface $appConfig,
6676
array $data = []
6777
) {
6878
$this->configuration = $configuration;
6979
$this->configurationBuilder = $configurationBuilder;
7080
$this->api = $api;
81+
$this->appConfig = $appConfig;
7182

7283
parent::__construct(
7384
$context,
@@ -87,7 +98,13 @@ public function beforeSave()
8798

8899
parent::beforeSave();
89100

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+
}
91108
if ($this->isSaveAllowed()) {
92109
$this->validate($this->getCredentialsFromEnvironmentVariable($rawValue));
93110
} else {

Diff for: Model/Configuration.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ public function getUploadConfig()
173173
/**
174174
* @return boolean
175175
*/
176-
public function isEnabled()
176+
public function isEnabled($checkEnvVar = true)
177177
{
178-
return $this->hasEnvironmentVariable() && $this->configReader->isSetFlag(self::CONFIG_PATH_ENABLED);
178+
return ($this->hasEnvironmentVariable() || !$checkEnvVar) && $this->configReader->isSetFlag(self::CONFIG_PATH_ENABLED);
179179
}
180180

181181
public function enable()

0 commit comments

Comments
 (0)