Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit 2deae18

Browse files
author
Pini
authored
Merge pull request #39 from cloudinary/v2.9.3
V2.9.3
2 parents 8cce8ba + d1a15a6 commit 2deae18

File tree

8 files changed

+68
-15
lines changed

8 files changed

+68
-15
lines changed

app/code/community/Cloudinary/Cloudinary/Model/Configuration.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,11 @@ private function setStoreConfig($configPath, $value)
204204
private function getEnvironmentVariable()
205205
{
206206
if (is_null($this->environmentVariable)) {
207-
$value = Mage::helper('core')->decrypt(Mage::getStoreConfig(self::CONFIG_PATH_ENVIRONMENT_VARIABLE));
207+
if (Mage::registry('cloudinaryEnvironmentVariable')) {
208+
$value = Mage::helper('core')->decrypt(Mage::registry('cloudinaryEnvironmentVariable'));
209+
} else {
210+
$value = Mage::helper('core')->decrypt(Mage::getStoreConfig(self::CONFIG_PATH_ENVIRONMENT_VARIABLE));
211+
}
208212
$this->environmentVariable = CloudinaryEnvironmentVariable::fromString($value);
209213
}
210214
return $this->environmentVariable;

app/code/community/Cloudinary/Cloudinary/Model/Observer/Config.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ public function configSave(Varien_Event_Observer $observer)
2828

2929
$data = Mage::helper('cloudinary_cloudinary/config')->flatten('cloudinary', $config->getGroups());
3030
if ($data[self::ENABLED_FIELD] == '1') {
31+
Mage::register('cloudinaryIsEnabled', true);
3132
$this->validateEnvironmentVariable($data);
3233
$this->logConfigChange($data);
34+
} else {
35+
Mage::register('cloudinaryIsEnabled', false);
3336
}
3437
}
3538

@@ -42,7 +45,7 @@ public function cloudinaryConfigChanged(Varien_Event_Observer $observer)
4245
Mage::app()->getCacheInstance()->cleanType("config");
4346
Mage::dispatchEvent('adminhtml_cache_refresh_type', array('type' => "config"));
4447

45-
if (!Mage::getModel('cloudinary_cloudinary/configuration')->isEnabled()) {
48+
if (!Mage::registry('cloudinaryIsEnabled')) {
4649
return;
4750
}
4851

@@ -62,12 +65,18 @@ public function cloudinaryConfigChanged(Varien_Event_Observer $observer)
6265
*/
6366
private function validateEnvironmentVariable(array $data)
6467
{
68+
$value = (string) $data[self::ENVIRONMENT_FIELD];
69+
if (preg_match('/^\*+$/', $value)) {
70+
$value = Mage::helper('core')->decrypt($value);
71+
}
6572
$credentialValidator = new CredentialValidator();
66-
$environmentVariable = CloudinaryEnvironmentVariable::fromString($data[self::ENVIRONMENT_FIELD]);
73+
$environmentVariable = CloudinaryEnvironmentVariable::fromString($value);
6774

6875
if (!$credentialValidator->validate($environmentVariable->getCredentials())) {
76+
Mage::register('cloudinaryEnvironmentVariableIsValid', false);
6977
throw new Mage_Core_Exception(self::ERROR_WRONG_CREDENTIALS);
7078
}
79+
Mage::register('cloudinaryEnvironmentVariableIsValid', true);
7180
}
7281

7382
/**
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
use CloudinaryExtension\CredentialValidator;
3+
use CloudinaryExtension\Security\CloudinaryEnvironmentVariable;
4+
5+
/**
6+
* Cloudinary_Cloudinary_Model_System_Config_Credentials
7+
*/
8+
class Cloudinary_Cloudinary_Model_System_Config_Credentials extends Mage_Adminhtml_Model_System_Config_Backend_Encrypted
9+
{
10+
/**
11+
* Encrypt value before saving
12+
*
13+
*/
14+
protected function _beforeSave()
15+
{
16+
$value = (string)$this->getValue();
17+
if (preg_match('/^\*+$/', $value)) {
18+
$value = $this->getOldValue();
19+
}
20+
21+
$isValid = false;
22+
try {
23+
$credentialValidator = new CredentialValidator();
24+
$environmentVariable = CloudinaryEnvironmentVariable::fromString($value);
25+
$isValid = (bool) $credentialValidator->validate($environmentVariable->getCredentials());
26+
} catch (\Exception $e) {
27+
//Ignore errors
28+
}
29+
30+
if (!$isValid) {
31+
$this->setValue(null);
32+
Mage::getSingleton('core/session')->addError(Cloudinary_Cloudinary_Model_Observer_Config::ERROR_WRONG_CREDENTIALS);
33+
}
34+
35+
parent::_beforeSave();
36+
37+
Mage::register('cloudinaryEnvironmentVariable', $this->getValue());
38+
39+
return $this;
40+
}
41+
}

app/code/community/Cloudinary/Cloudinary/Model/System/Config/Free.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function httpRequest($url)
9898
*/
9999
public function hasAccountConfigured()
100100
{
101-
return (string)$this->configuration->getCloud() !== '';
101+
return Mage::registry('cloudinaryEnvironmentVariableIsValid');
102102
}
103103

104104
/**

app/code/community/Cloudinary/Cloudinary/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<config>
33
<modules>
44
<Cloudinary_Cloudinary>
5-
<version>2.9.2</version>
5+
<version>2.9.3</version>
66
</Cloudinary_Cloudinary>
77
</modules>
88
<global>

app/code/community/Cloudinary/Cloudinary/etc/system.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<label>Cloudinary Account Credentials</label>
4242
<comment>Set the credentials of your Cloudinary account. Copy the "Environment variable" string from the dashboard of Cloudinary's Management Console.</comment>
4343
<frontend_type>password</frontend_type>
44-
<backend_model>adminhtml/system_config_backend_encrypted</backend_model>
44+
<backend_model>cloudinary_cloudinary/system_config_credentials</backend_model>
4545
<sort_order>1</sort_order>
4646
<show_in_default>1</show_in_default>
4747
<show_in_website>0</show_in_website>
@@ -136,7 +136,7 @@
136136
<source_model>cloudinary_cloudinary/system_config_source_dropdown_dpr</source_model>
137137
</cloudinary_image_dpr>
138138
<cloudinary_free_transform_global>
139-
<label>Global custom transform</label>
139+
<label>Global custom transformation</label>
140140
<frontend_type>text</frontend_type>
141141
<sort_order>5</sort_order>
142142
<show_in_default>1</show_in_default>

var/connect/Cloudinary_Cloudinary.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<_>
2-
<form_key>FlphPtIaaCI8lVwe</form_key>
3-
<_create/>
2+
<form_key>pHIzpC9UKidsX254</form_key>
43
<name>Cloudinary_Cloudinary</name>
54
<channel>community</channel>
65
<version_ids>
@@ -10,7 +9,7 @@
109
<description>Cloudinary supercharges your images! Upload images to the cloud, deliver optimized via a fast CDN, perform smart resizing and apply effects.</description>
1110
<license>MIT License (MITL)</license>
1211
<license_uri/>
13-
<version>2.9.2</version>
12+
<version>2.9.3</version>
1413
<stability>stable</stability>
1514
<notes> - Match MEQP1 coding standards
1615
</notes>
@@ -42,7 +41,7 @@
4241
<max/>
4342
</max>
4443
<files>
45-
<files> </files>
44+
<files> </files>
4645
</files>
4746
</package>
4847
<extension>

var/package/package.xml

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)