Version Notes
Release 2.3.0 notes:
- Provide auto upload mapping feature
Download this release
Release Info
Developer | Cloudinary |
Extension | Cloudinary_Cloudinary |
Version | 2.3.0 |
Comparing to | |
See all releases |
Code changes from version 2.2.0 to 2.3.0
- app/code/community/Cloudinary/Cloudinary/Block/Adminhtml/System/Config/Form/Foldered.php +16 -0
- app/code/community/Cloudinary/Cloudinary/Model/AutoUploadMapping/Configuration.php +71 -0
- app/code/community/Cloudinary/Cloudinary/Model/Configuration.php +9 -1
- app/code/community/Cloudinary/Cloudinary/Model/Observer.php +26 -1
- app/code/community/Cloudinary/Cloudinary/Model/SynchronizationChecker.php +13 -0
- app/code/community/Cloudinary/Cloudinary/etc/config.xml +9 -1
- app/code/community/Cloudinary/Cloudinary/etc/system.xml +12 -1
- lib/CloudinaryExtension/AutoUploadMapping/ApiClient.php +157 -0
- lib/CloudinaryExtension/AutoUploadMapping/Configuration.php +29 -0
- lib/CloudinaryExtension/AutoUploadMapping/RequestProcessor.php +68 -0
- package.xml +6 -9
app/code/community/Cloudinary/Cloudinary/Block/Adminhtml/System/Config/Form/Foldered.php
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Cloudinary_Cloudinary_Block_Adminhtml_System_Config_Form_Foldered extends Mage_Adminhtml_Block_System_Config_Form_Field
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* @param Varien_Data_Form_Element_Select $element
|
7 |
+
* @return mixed
|
8 |
+
*/
|
9 |
+
protected function _getElementHtml($element)
|
10 |
+
{
|
11 |
+
if (Mage::getModel('cloudinary_cloudinary/autoUploadMapping_configuration')->isActive()) {
|
12 |
+
$element->setDisabled('disabled');
|
13 |
+
}
|
14 |
+
return parent::_getElementHtml($element);
|
15 |
+
}
|
16 |
+
}
|
app/code/community/Cloudinary/Cloudinary/Model/AutoUploadMapping/Configuration.php
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
use CloudinaryExtension\AutoUploadMapping\Configuration as ConfigurationInterface;
|
4 |
+
|
5 |
+
class Cloudinary_Cloudinary_Model_AutoUploadMapping_Configuration implements ConfigurationInterface
|
6 |
+
{
|
7 |
+
const STATE_PATH = 'cloudinary/configuration/cloudinary_auto_upload_mapping_state';
|
8 |
+
const REQUEST_PATH = 'cloudinary/configuration/cloudinary_auto_upload_mapping_request';
|
9 |
+
|
10 |
+
/**
|
11 |
+
* @return bool
|
12 |
+
*/
|
13 |
+
public function isActive()
|
14 |
+
{
|
15 |
+
return Mage::getStoreConfigFlag(self::STATE_PATH);
|
16 |
+
}
|
17 |
+
|
18 |
+
/**
|
19 |
+
* @param bool $state
|
20 |
+
*/
|
21 |
+
public function setState($state)
|
22 |
+
{
|
23 |
+
$this->setStoreConfigFlag(self::STATE_PATH, $state);
|
24 |
+
}
|
25 |
+
|
26 |
+
/**
|
27 |
+
* @return bool
|
28 |
+
*/
|
29 |
+
public function getRequestState()
|
30 |
+
{
|
31 |
+
return Mage::getStoreConfigFlag(self::REQUEST_PATH);
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* @param bool $state
|
36 |
+
*/
|
37 |
+
public function setRequestState($state)
|
38 |
+
{
|
39 |
+
$this->setStoreConfigFlag(self::REQUEST_PATH, $state);
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* @param string $configPath
|
44 |
+
* @param bool $state
|
45 |
+
*/
|
46 |
+
private function setStoreConfigFlag($configPath, $state)
|
47 |
+
{
|
48 |
+
$state = $state ? 1 : 0;
|
49 |
+
$this->updatePersistentConfig($configPath, $state);
|
50 |
+
$this->updateCacheConfig($configPath, $state);
|
51 |
+
}
|
52 |
+
|
53 |
+
/**
|
54 |
+
* @param string $path
|
55 |
+
* @param bool $state
|
56 |
+
*/
|
57 |
+
private function updatePersistentConfig($path, $state)
|
58 |
+
{
|
59 |
+
Mage::getModel('core/config')->saveConfig($path, $state)->reinit();
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* @param string $path
|
64 |
+
* @param bool $state
|
65 |
+
*/
|
66 |
+
private function updateCacheConfig($path, $state)
|
67 |
+
{
|
68 |
+
Mage::app()->getStore()->getConfig($path);
|
69 |
+
Mage::app()->getStore()->setConfig($path, $state);
|
70 |
+
}
|
71 |
+
}
|
app/code/community/Cloudinary/Cloudinary/Model/Configuration.php
CHANGED
@@ -152,7 +152,15 @@ class Cloudinary_Cloudinary_Model_Configuration implements ConfigurationInterfac
|
|
152 |
|
153 |
public function isFolderedMigration()
|
154 |
{
|
155 |
-
return Mage::getStoreConfigFlag(self::CONFIG_FOLDERED_MIGRATION);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
}
|
157 |
|
158 |
private function setStoreConfig($configPath, $value)
|
152 |
|
153 |
public function isFolderedMigration()
|
154 |
{
|
155 |
+
return $this->hasAutoUploadMapping() || Mage::getStoreConfigFlag(self::CONFIG_FOLDERED_MIGRATION);
|
156 |
+
}
|
157 |
+
|
158 |
+
/**
|
159 |
+
* @return bool
|
160 |
+
*/
|
161 |
+
private function hasAutoUploadMapping()
|
162 |
+
{
|
163 |
+
return Mage::getModel('cloudinary_cloudinary/autoUploadMapping_configuration')->isActive();
|
164 |
}
|
165 |
|
166 |
private function setStoreConfig($configPath, $value)
|
app/code/community/Cloudinary/Cloudinary/Model/Observer.php
CHANGED
@@ -5,6 +5,9 @@ use CloudinaryExtension\CredentialValidator;
|
|
5 |
use CloudinaryExtension\Exception\InvalidCredentials;
|
6 |
use CloudinaryExtension\Image;
|
7 |
use CloudinaryExtension\Security\CloudinaryEnvironmentVariable;
|
|
|
|
|
|
|
8 |
use Mage_Adminhtml_Model_Config_Data as ConfigData;
|
9 |
use Mage_Catalog_Model_Product as Product;
|
10 |
use Varien_Event_Observer as EventObserver;
|
@@ -13,6 +16,7 @@ class Cloudinary_Cloudinary_Model_Observer extends Mage_Core_Model_Abstract
|
|
13 |
{
|
14 |
const CLOUDINARY_CONFIG_SECTION = 'cloudinary';
|
15 |
const ERROR_WRONG_CREDENTIALS = 'There was a problem validating your Cloudinary credentials.';
|
|
|
16 |
|
17 |
/**
|
18 |
* @param EventObserver $event
|
@@ -70,7 +74,28 @@ class Cloudinary_Cloudinary_Model_Observer extends Mage_Core_Model_Abstract
|
|
70 |
Mage::getSingleton('adminhtml/session')->addError(self::ERROR_WRONG_CREDENTIALS);
|
71 |
}
|
72 |
}
|
73 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
/**
|
76 |
* @param Product $product
|
5 |
use CloudinaryExtension\Exception\InvalidCredentials;
|
6 |
use CloudinaryExtension\Image;
|
7 |
use CloudinaryExtension\Security\CloudinaryEnvironmentVariable;
|
8 |
+
use CloudinaryExtension\AutoUploadMapping\RequestProcessor;
|
9 |
+
use CloudinaryExtension\AutoUploadMapping\ApiClient;
|
10 |
+
use Cloudinary\Api;
|
11 |
use Mage_Adminhtml_Model_Config_Data as ConfigData;
|
12 |
use Mage_Catalog_Model_Product as Product;
|
13 |
use Varien_Event_Observer as EventObserver;
|
16 |
{
|
17 |
const CLOUDINARY_CONFIG_SECTION = 'cloudinary';
|
18 |
const ERROR_WRONG_CREDENTIALS = 'There was a problem validating your Cloudinary credentials.';
|
19 |
+
const AUTO_UPLOAD_SETUP_FAIL_MESSAGE = 'Error. Unable to setup auto upload mapping.';
|
20 |
|
21 |
/**
|
22 |
* @param EventObserver $event
|
74 |
Mage::getSingleton('adminhtml/session')->addError(self::ERROR_WRONG_CREDENTIALS);
|
75 |
}
|
76 |
}
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* @param Varien_Event_Observer $observer
|
81 |
+
*/
|
82 |
+
public function cloudinaryConfigChanged(EventObserver $observer)
|
83 |
+
{
|
84 |
+
if (!$this->autoUploadRequestProcessor()->handle('media', Mage::getBaseUrl('media'))) {
|
85 |
+
Mage::getSingleton('adminhtml/session')->addError(self::AUTO_UPLOAD_SETUP_FAIL_MESSAGE);
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* @return RequestProcessor
|
91 |
+
*/
|
92 |
+
private function autoUploadRequestProcessor()
|
93 |
+
{
|
94 |
+
return new RequestProcessor(
|
95 |
+
Mage::getModel('cloudinary_cloudinary/autoUploadMapping_configuration'),
|
96 |
+
ApiClient::fromConfiguration(Mage::getModel('cloudinary_cloudinary/configuration'))
|
97 |
+
);
|
98 |
+
}
|
99 |
|
100 |
/**
|
101 |
* @param Product $product
|
app/code/community/Cloudinary/Cloudinary/Model/SynchronizationChecker.php
CHANGED
@@ -9,10 +9,23 @@ class Cloudinary_Cloudinary_Model_SynchronizationChecker implements Synchronizat
|
|
9 |
if (!$imageName) {
|
10 |
return false;
|
11 |
}
|
|
|
|
|
|
|
|
|
|
|
12 |
$coll = Mage::getModel('cloudinary_cloudinary/synchronisation')->getCollection();
|
13 |
$table = $coll->getMainTable();
|
14 |
// case sensitive check
|
15 |
$query = "select count(*) from $table where binary image_name = '$imageName' limit 1";
|
16 |
return $coll->getConnection()->query($query)->fetchColumn() > 0;
|
17 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
}
|
9 |
if (!$imageName) {
|
10 |
return false;
|
11 |
}
|
12 |
+
|
13 |
+
if ($this->hasAutoUploadMapping()) {
|
14 |
+
return true;
|
15 |
+
}
|
16 |
+
|
17 |
$coll = Mage::getModel('cloudinary_cloudinary/synchronisation')->getCollection();
|
18 |
$table = $coll->getMainTable();
|
19 |
// case sensitive check
|
20 |
$query = "select count(*) from $table where binary image_name = '$imageName' limit 1";
|
21 |
return $coll->getConnection()->query($query)->fetchColumn() > 0;
|
22 |
}
|
23 |
+
|
24 |
+
/**
|
25 |
+
* @return bool
|
26 |
+
*/
|
27 |
+
private function hasAutoUploadMapping()
|
28 |
+
{
|
29 |
+
return Mage::getModel('cloudinary_cloudinary/autoUploadMapping_configuration')->isActive();
|
30 |
+
}
|
31 |
}
|
app/code/community/Cloudinary/Cloudinary/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Cloudinary_Cloudinary>
|
5 |
-
<version>2.
|
6 |
</Cloudinary_Cloudinary>
|
7 |
</modules>
|
8 |
<global>
|
@@ -126,6 +126,14 @@
|
|
126 |
</validate_cloudinary_credentials>
|
127 |
</observers>
|
128 |
</model_config_data_save_before>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
</events>
|
130 |
</adminhtml>
|
131 |
<admin>
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Cloudinary_Cloudinary>
|
5 |
+
<version>2.3.0</version>
|
6 |
</Cloudinary_Cloudinary>
|
7 |
</modules>
|
8 |
<global>
|
126 |
</validate_cloudinary_credentials>
|
127 |
</observers>
|
128 |
</model_config_data_save_before>
|
129 |
+
<admin_system_config_changed_section_cloudinary>
|
130 |
+
<observers>
|
131 |
+
<validate_cloudinary_credentials>
|
132 |
+
<class>cloudinary_cloudinary/observer</class>
|
133 |
+
<method>cloudinaryConfigChanged</method>
|
134 |
+
</validate_cloudinary_credentials>
|
135 |
+
</observers>
|
136 |
+
</admin_system_config_changed_section_cloudinary>
|
137 |
</events>
|
138 |
</adminhtml>
|
139 |
<admin>
|
app/code/community/Cloudinary/Cloudinary/etc/system.xml
CHANGED
@@ -56,14 +56,25 @@
|
|
56 |
</cloudinary_cdn_subdomain>
|
57 |
<cloudinary_foldered_migration>
|
58 |
<label>Migrate images to folders relative to the magento root folder</label>
|
59 |
-
<comment>When enabled, cloudinary migration will clone the folder structure of the images relative to the magento root folder
|
60 |
<frontend_type>select</frontend_type>
|
61 |
<sort_order>5</sort_order>
|
62 |
<show_in_default>1</show_in_default>
|
63 |
<show_in_website>1</show_in_website>
|
64 |
<show_in_store>1</show_in_store>
|
65 |
<source_model>adminhtml/system_config_source_yesno</source_model>
|
|
|
66 |
</cloudinary_foldered_migration>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
</fields>
|
68 |
</configuration>
|
69 |
<transformations translate="label">
|
56 |
</cloudinary_cdn_subdomain>
|
57 |
<cloudinary_foldered_migration>
|
58 |
<label>Migrate images to folders relative to the magento root folder</label>
|
59 |
+
<comment>When enabled, cloudinary migration will clone the folder structure of the images relative to the magento root folder. This setting is not available when using Auto Upload Mapping.</comment>
|
60 |
<frontend_type>select</frontend_type>
|
61 |
<sort_order>5</sort_order>
|
62 |
<show_in_default>1</show_in_default>
|
63 |
<show_in_website>1</show_in_website>
|
64 |
<show_in_store>1</show_in_store>
|
65 |
<source_model>adminhtml/system_config_source_yesno</source_model>
|
66 |
+
<frontend_model>cloudinary_cloudinary/adminhtml_system_config_form_foldered</frontend_model>
|
67 |
</cloudinary_foldered_migration>
|
68 |
+
<cloudinary_auto_upload_mapping_request>
|
69 |
+
<label>Use auto upload mapping to upload images</label>
|
70 |
+
<comment>When enabled, Cloudinary will fetch images it does not have from your site automatically without requiring the manual migration process. Please clear the block and page cache to start this process.</comment>
|
71 |
+
<frontend_type>select</frontend_type>
|
72 |
+
<sort_order>6</sort_order>
|
73 |
+
<show_in_default>1</show_in_default>
|
74 |
+
<show_in_website>1</show_in_website>
|
75 |
+
<show_in_store>1</show_in_store>
|
76 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
77 |
+
</cloudinary_auto_upload_mapping_request>
|
78 |
</fields>
|
79 |
</configuration>
|
80 |
<transformations translate="label">
|
lib/CloudinaryExtension/AutoUploadMapping/ApiClient.php
ADDED
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace CloudinaryExtension\AutoUploadMapping;
|
4 |
+
|
5 |
+
use Cloudinary;
|
6 |
+
use Cloudinary\Api;
|
7 |
+
use CloudinaryExtension\ConfigurationBuilder;
|
8 |
+
use CloudinaryExtension\ConfigurationInterface;
|
9 |
+
|
10 |
+
class ApiClient
|
11 |
+
{
|
12 |
+
const MAPPINGS_KEY = 'mappings';
|
13 |
+
const FOLDER_KEY = 'folder';
|
14 |
+
const URL_KEY = 'template';
|
15 |
+
|
16 |
+
/**
|
17 |
+
* @var ConfigurationInterface
|
18 |
+
*/
|
19 |
+
private $configuration;
|
20 |
+
|
21 |
+
/**
|
22 |
+
* @var ConfigurationBuilder
|
23 |
+
*/
|
24 |
+
private $configurationBuilder;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* @var [Exception]
|
28 |
+
*/
|
29 |
+
private $errors = [];
|
30 |
+
|
31 |
+
/**
|
32 |
+
* ApiClient constructor.
|
33 |
+
* @param ConfigurationInterface $configuration
|
34 |
+
* @param ConfigurationBuilder $configurationBuilder
|
35 |
+
*/
|
36 |
+
public function __construct(
|
37 |
+
ConfigurationInterface $configuration,
|
38 |
+
ConfigurationBuilder $configurationBuilder,
|
39 |
+
Api $api
|
40 |
+
) {
|
41 |
+
$this->configuration = $configuration;
|
42 |
+
$this->configurationBuilder = $configurationBuilder;
|
43 |
+
$this->api = $api;
|
44 |
+
$this->authorise();
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* @param ConfigurationInterface $configuration
|
49 |
+
* @return ApiClient
|
50 |
+
*/
|
51 |
+
public static function fromConfiguration(ConfigurationInterface $configuration)
|
52 |
+
{
|
53 |
+
return new ApiClient(
|
54 |
+
$configuration,
|
55 |
+
new ConfigurationBuilder($configuration),
|
56 |
+
new Api()
|
57 |
+
);
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* @param string $folder
|
62 |
+
* @param string $url
|
63 |
+
* @return bool
|
64 |
+
*/
|
65 |
+
public function prepareMapping($folder, $url)
|
66 |
+
{
|
67 |
+
try {
|
68 |
+
|
69 |
+
$existingMappings = $this->parseFetchMappingsResponse($this->api->upload_mappings());
|
70 |
+
|
71 |
+
if ($this->hasMapping($existingMappings, $folder)) {
|
72 |
+
if (!$this->mappingMatches($existingMappings, $folder, $url)) {
|
73 |
+
$this->api->update_upload_mapping($folder, [self::URL_KEY => $url]);
|
74 |
+
}
|
75 |
+
} else {
|
76 |
+
$this->api->create_upload_mapping($folder, [self::URL_KEY => $url]);
|
77 |
+
}
|
78 |
+
|
79 |
+
return true;
|
80 |
+
|
81 |
+
} catch (\Exception $e) {
|
82 |
+
$this->errors[] = $e;
|
83 |
+
return false;
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* @param array $response
|
89 |
+
* @return array
|
90 |
+
* @throws \Exception
|
91 |
+
*/
|
92 |
+
private function parseFetchMappingsResponse(array $response)
|
93 |
+
{
|
94 |
+
if (!array_key_exists(self::MAPPINGS_KEY, $response) || !is_array($response[self::MAPPINGS_KEY])) {
|
95 |
+
throw new \Exception('Illegal mapping response');
|
96 |
+
}
|
97 |
+
|
98 |
+
return $response[self::MAPPINGS_KEY];
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* @param array $mappings
|
103 |
+
* @param string $folder
|
104 |
+
* @return array
|
105 |
+
*/
|
106 |
+
private function filterMappings(array $mappings, $folder)
|
107 |
+
{
|
108 |
+
return array_filter(
|
109 |
+
$mappings,
|
110 |
+
function(array $mapping) use ($folder) {
|
111 |
+
return $mapping[self::FOLDER_KEY] == $folder;
|
112 |
+
}
|
113 |
+
);
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* @param array $mappings
|
118 |
+
* @param string $folder
|
119 |
+
* @return bool
|
120 |
+
*/
|
121 |
+
private function hasMapping(array $mappings, $folder)
|
122 |
+
{
|
123 |
+
return count($this->filterMappings($mappings, $folder)) > 0;
|
124 |
+
}
|
125 |
+
|
126 |
+
/**
|
127 |
+
* @param array $existingMappings
|
128 |
+
* @param string $folder
|
129 |
+
* @param string $url
|
130 |
+
* @return bool
|
131 |
+
*/
|
132 |
+
private function mappingMatches(array $existingMappings, $folder, $url)
|
133 |
+
{
|
134 |
+
return count(
|
135 |
+
array_filter(
|
136 |
+
$this->filterMappings($existingMappings, $folder),
|
137 |
+
function(array $mapping) use ($url) {
|
138 |
+
return $mapping[self::URL_KEY] == $url;
|
139 |
+
}
|
140 |
+
)
|
141 |
+
) > 0;
|
142 |
+
}
|
143 |
+
|
144 |
+
private function authorise()
|
145 |
+
{
|
146 |
+
Cloudinary::config($this->configurationBuilder->build());
|
147 |
+
Cloudinary::$USER_PLATFORM = $this->configuration->getUserPlatform();
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* @return [Exception]
|
152 |
+
*/
|
153 |
+
public function getErrors()
|
154 |
+
{
|
155 |
+
return $this->errors;
|
156 |
+
}
|
157 |
+
}
|
lib/CloudinaryExtension/AutoUploadMapping/Configuration.php
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace CloudinaryExtension\AutoUploadMapping;
|
4 |
+
|
5 |
+
interface Configuration
|
6 |
+
{
|
7 |
+
const ACTIVE = true;
|
8 |
+
const INACTIVE = false;
|
9 |
+
|
10 |
+
/**
|
11 |
+
* @return bool
|
12 |
+
*/
|
13 |
+
public function isActive();
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @param bool $state
|
17 |
+
*/
|
18 |
+
public function setState($state);
|
19 |
+
|
20 |
+
/**
|
21 |
+
* @return bool
|
22 |
+
*/
|
23 |
+
public function getRequestState();
|
24 |
+
|
25 |
+
/**
|
26 |
+
* @param bool $state
|
27 |
+
*/
|
28 |
+
public function setRequestState($state);
|
29 |
+
}
|
lib/CloudinaryExtension/AutoUploadMapping/RequestProcessor.php
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace CloudinaryExtension\AutoUploadMapping;
|
4 |
+
|
5 |
+
class RequestProcessor
|
6 |
+
{
|
7 |
+
/**
|
8 |
+
* @var Configuration
|
9 |
+
*/
|
10 |
+
private $configuration;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* @var ApiClient
|
14 |
+
*/
|
15 |
+
private $apiClient;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* RequestProcessor constructor.
|
19 |
+
* @param Configuration $configuration
|
20 |
+
* @param ApiClient $apiClient
|
21 |
+
* @param string $url
|
22 |
+
*/
|
23 |
+
public function __construct(
|
24 |
+
Configuration $configuration,
|
25 |
+
ApiClient $apiClient
|
26 |
+
) {
|
27 |
+
$this->configuration = $configuration;
|
28 |
+
$this->apiClient = $apiClient;
|
29 |
+
}
|
30 |
+
|
31 |
+
/**
|
32 |
+
* @param string $folder
|
33 |
+
* @param string $url
|
34 |
+
* @return bool
|
35 |
+
*/
|
36 |
+
public function handle($folder, $url)
|
37 |
+
{
|
38 |
+
if ($this->configuration->isActive() == $this->configuration->getRequestState()) {
|
39 |
+
return true;
|
40 |
+
}
|
41 |
+
|
42 |
+
if ($this->configuration->getRequestState() == Configuration::ACTIVE) {
|
43 |
+
return $this->handleActiveRequest($folder, $url);
|
44 |
+
}
|
45 |
+
|
46 |
+
$this->configuration->setState(Configuration::INACTIVE);
|
47 |
+
|
48 |
+
return true;
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* @param string $folder
|
53 |
+
* @param string $url
|
54 |
+
* @return bool
|
55 |
+
*/
|
56 |
+
private function handleActiveRequest($folder, $url)
|
57 |
+
{
|
58 |
+
$result = $this->apiClient->prepareMapping($folder, $url);
|
59 |
+
|
60 |
+
if ($result) {
|
61 |
+
$this->configuration->setState(Configuration::ACTIVE);
|
62 |
+
} else {
|
63 |
+
$this->configuration->setRequestState(Configuration::INACTIVE);
|
64 |
+
}
|
65 |
+
|
66 |
+
return $result;
|
67 |
+
}
|
68 |
+
}
|
package.xml
CHANGED
@@ -1,23 +1,20 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Cloudinary_Cloudinary</name>
|
4 |
-
<version>2.
|
5 |
<stability>stable</stability>
|
6 |
<license>MIT License (MITL)</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>Cloudinary - Image Management In The Cloud</summary>
|
10 |
<description>Cloudinary supercharges your images! Upload images to the cloud, deliver optimized via a fast CDN, perform smart resizing and apply effects.</description>
|
11 |
-
<notes> Release 2.
|
12 |
-
-
|
13 |
-
- Fix bug where migration status shows value above 100%
|
14 |
-
- Preserve original file extensions in Cloudinary image urls
|
15 |
-
- Retry migration when network failures occur
|
16 |
</notes>
|
17 |
<authors><author><name>Cloudinary</name><user>cloudinary</user><email>accounts+magento@cloudinary.com</email></author></authors>
|
18 |
-
<date>2017-05-
|
19 |
-
<time>
|
20 |
-
<contents><target name="magecommunity"><dir name="Cloudinary"><dir name="Cloudinary"><dir name="Block"><dir name="Adminhtml"><dir name="Manage"><file name="Grid.php" hash="b6a05f6ba08c5ba0d08846a7b0a06776"/></dir><file name="Manage.php" hash="9cd8997737c1191cff57dc8530daa26c"/><dir name="Page"><file name="Menu.php" hash="891d6a4c075ba03c9a20658076c86ad0"/></dir><dir name="System"><dir name="Config"><file name="Signup.php" hash="ed6accbe7a4ce16bb0679eaf0c2dbb22"/></dir></dir></dir></dir><dir name="Helper"><file name="Autoloader.php" hash="393b3e2fc25e63ca28157152d2542b18"/><file name="Console.php" hash="7c909e3226c51c05d6da1f6ff9cbbfc9"/><file name="Cron.php" hash="805557370a2006b15444b7a62bbbc65a"/><file name="Data.php" hash="42c9d44f1bbe530e30cf5379846dea65"/><file name="Image.php" hash="af1c1d734793d6b08feaa7e1abd591d0"/></dir><dir name="Model"><dir name="Catalog"><dir name="Product"><file name="Image.php" hash="b5d14bcb836158890152c9fed191f8bc"/><dir name="Media"><file name="Config.php" hash="c2dbac447d4a22c920c19b0d4eb2672e"/></dir><file name="Media.php" hash="05726616a07d7d08933e9654e6107283"/></dir></dir><dir name="Cms"><dir name="Adminhtml"><dir name="Template"><file name="Filter.php" hash="792893f6b4e884a8e42847d457a6068c"/></dir></dir><file name="Synchronisation.php" hash="8d830a18f169a0ff5f7d865e3afcb710"/><dir name="Template"><file name="Filter.php" hash="c3fe64f98128043de13e92156a26ab02"/></dir><file name="Uploader.php" hash="021195c01a7e6fd9e72c5a30ebd11554"/><dir name="Wysiwyg"><dir name="Images"><file name="Storage.php" hash="0d23e557d6db06308886d9307fe92665"/></dir></dir></dir><file name="CollectionCounter.php" hash="e69953aee5d966a3ec13d33533f017e0"/><file name="Configuration.php" hash="
|
21 |
<compatible/>
|
22 |
<dependencies><required><php><min>5.4.0</min><max>7.1.0</max></php></required></dependencies>
|
23 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Cloudinary_Cloudinary</name>
|
4 |
+
<version>2.3.0</version>
|
5 |
<stability>stable</stability>
|
6 |
<license>MIT License (MITL)</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>Cloudinary - Image Management In The Cloud</summary>
|
10 |
<description>Cloudinary supercharges your images! Upload images to the cloud, deliver optimized via a fast CDN, perform smart resizing and apply effects.</description>
|
11 |
+
<notes> Release 2.3.0 notes:
|
12 |
+
- Provide auto upload mapping feature
|
|
|
|
|
|
|
13 |
</notes>
|
14 |
<authors><author><name>Cloudinary</name><user>cloudinary</user><email>accounts+magento@cloudinary.com</email></author></authors>
|
15 |
+
<date>2017-05-10</date>
|
16 |
+
<time>15:02:55</time>
|
17 |
+
<contents><target name="magecommunity"><dir name="Cloudinary"><dir name="Cloudinary"><dir name="Block"><dir name="Adminhtml"><dir name="Manage"><file name="Grid.php" hash="b6a05f6ba08c5ba0d08846a7b0a06776"/></dir><file name="Manage.php" hash="9cd8997737c1191cff57dc8530daa26c"/><dir name="Page"><file name="Menu.php" hash="891d6a4c075ba03c9a20658076c86ad0"/></dir><dir name="System"><dir name="Config"><dir name="Form"><file name="Foldered.php" hash="925c3c8b3938495afe4d2f917bd58f95"/></dir><file name="Signup.php" hash="ed6accbe7a4ce16bb0679eaf0c2dbb22"/></dir></dir></dir></dir><dir name="Helper"><file name="Autoloader.php" hash="393b3e2fc25e63ca28157152d2542b18"/><file name="Console.php" hash="7c909e3226c51c05d6da1f6ff9cbbfc9"/><file name="Cron.php" hash="805557370a2006b15444b7a62bbbc65a"/><file name="Data.php" hash="42c9d44f1bbe530e30cf5379846dea65"/><file name="Image.php" hash="af1c1d734793d6b08feaa7e1abd591d0"/></dir><dir name="Model"><dir name="AutoUploadMapping"><file name="Configuration.php" hash="a9c2e1176ec36cea6f5183b24793dc2d"/></dir><dir name="Catalog"><dir name="Product"><file name="Image.php" hash="b5d14bcb836158890152c9fed191f8bc"/><dir name="Media"><file name="Config.php" hash="c2dbac447d4a22c920c19b0d4eb2672e"/></dir><file name="Media.php" hash="05726616a07d7d08933e9654e6107283"/></dir></dir><dir name="Cms"><dir name="Adminhtml"><dir name="Template"><file name="Filter.php" hash="792893f6b4e884a8e42847d457a6068c"/></dir></dir><file name="Synchronisation.php" hash="8d830a18f169a0ff5f7d865e3afcb710"/><dir name="Template"><file name="Filter.php" hash="c3fe64f98128043de13e92156a26ab02"/></dir><file name="Uploader.php" hash="021195c01a7e6fd9e72c5a30ebd11554"/><dir name="Wysiwyg"><dir name="Images"><file name="Storage.php" hash="0d23e557d6db06308886d9307fe92665"/></dir></dir></dir><file name="CollectionCounter.php" hash="e69953aee5d966a3ec13d33533f017e0"/><file name="Configuration.php" hash="2054e73d40d952cc0a4f5755107f2502"/><file name="Cron.php" hash="a7296d26862df0d382023d33496bb80a"/><dir name="Exception"><file name="BadFilePathException.php" hash="68135da8dfe2f0589a531b4bd36e3330"/></dir><file name="Image.php" hash="84d42417651e2feefdb1b0c048f61ca4"/><file name="Logger.php" hash="ab5e45b0769c9dbee33025a202a87fee"/><file name="MagentoFolderTranslator.php" hash="37219fc1804d6ad8d1686af8509e1963"/><file name="Migration.php" hash="30f671877307d93904fd823d01d35c1d"/><file name="MigrationError.php" hash="67eca6725679a5dae6eab65efae39c64"/><file name="Observer.php" hash="e8437f1dd16c3251f0b0d69a80aa8f8b"/><dir name="Resource"><dir name="Cms"><dir name="Synchronisation"><file name="Collection.php" hash="226db91ad96a348f0d937781358f9dec"/></dir></dir><dir name="Media"><file name="Collection.php" hash="f54d914a6f79c7b3ab51f822bf64de39"/></dir><file name="Migration.php" hash="69a545d0627016afc03ea097641aa749"/><dir name="MigrationError"><file name="Collection.php" hash="3c5ef530b18b4cd7763a610b84cd3d41"/></dir><file name="MigrationError.php" hash="e6de24a80cb0daed6ead44c699dce535"/><dir name="Synchronisation"><file name="Collection.php" hash="d16275121feb30e57b9b54122e26f05c"/></dir><file name="Synchronisation.php" hash="5b721d854d8f89bc3310e46081be7153"/></dir><file name="Synchronisation.php" hash="05414c5959efc7656b8e101617005d9a"/><file name="SynchronisedMediaUnifier.php" hash="899abd4ef47be0ce3604cfc8790c582a"/><file name="SynchronizationChecker.php" hash="f01a4eab976e491d201206ce838dc686"/><dir name="System"><dir name="Config"><dir name="Source"><dir name="Dropdown"><file name="Dpr.php" hash="2b9bfd5f836dbdb5d7224d298264f540"/><file name="Gravity.php" hash="c241498e2093640892170673cd7550cd"/><file name="Quality.php" hash="e0c5902f5c36c96fb8a8ba7cc741ce1f"/></dir></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="CloudinaryController.php" hash="d44f610256d0d7a5633a94977442787b"/></dir></dir><dir name="data"><dir name="cloudinary_setup"><file name="data-upgrade-0.1.0-0.1.1.php" hash="4c6ce6cd9ab0d94654afb4a398fb3d6c"/><file name="data-upgrade-1.1.2-1.1.3.php" hash="fe2026874346017303a8f41a9d0d6c0d"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="46e365e2f4b1d543aad248dfcfb99c50"/><file name="config.xml" hash="769c420587a7088db6199738e4474e17"/><file name="system.xml" hash="2116e6b1db2dbaa826938abdafc3e418"/></dir><dir name="sql"><dir name="cloudinary_setup"><file name="install-0.1.0.php" hash="55d93b3dab573c2a932edbb5a2fa4865"/><file name="upgrade-0.1.0-0.1.1.php" hash="6c8d430fbf7b9714586b67db3d455008"/><file name="upgrade-1.1.3-1.1.4.php" hash="d6314fc1843b2061d0d04ae60c4d8091"/><file name="upgrade-1.1.4-1.1.5.php" hash="5b035e4b600cbbc743e9ff6a7b505230"/><file name="upgrade-1.1.5-1.1.6.php" hash="323c5e50635018be420cf524072f6a92"/><file name="upgrade-2.0.0-2.1.0.php" hash="9d053bed5099e064eed808a090755b03"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Cloudinary_Cloudinary.xml" hash="9337962a4ccf8a43164d5d71dfd2d756"/></dir></target><target name="magelib"><dir name="CloudinaryExtension"><dir name="AutoUploadMapping"><file name="ApiClient.php" hash="c37bfa114f18192ad34422a277c86afa"/><file name="Configuration.php" hash="0c28915836a4d7ba4390f2831c86aa6f"/><file name="RequestProcessor.php" hash="ef82cf531a21b4879b9facadd8085070"/></dir><file name="Cloud.php" hash="59b0debf9ae297e4e824e39ba819b1d1"/><file name="CloudinaryImageManager.php" hash="94af20e7b144adc4a27ee011aabbefe3"/><file name="CloudinaryImageProvider.php" hash="c4199a5384e6c42316ab4c5c74ed35e3"/><file name="ConfigurationBuilder.php" hash="c8832b207d9228ef14b3c74100ee74c4"/><file name="ConfigurationInterface.php" hash="4129b1e282fb0000b78946f07baa740c"/><file name="CredentialValidator.php" hash="965b0bd024f668aabcc9f30ef2e3c240"/><file name="Credentials.php" hash="71054eb4af7b6496608ffd14912bdbe4"/><dir name="Exception"><file name="ApiError.php" hash="d6fb1e32ca96183e9800c3706de37206"/><file name="FileExists.php" hash="6969387c67deef15a378cb94b9d269ac"/><file name="InvalidCredentials.php" hash="abecc635a25f6c9896c605ad16e1f7d7"/><file name="MigrationError.php" hash="92ea7aa65f4e14e606fa107d33f3ad30"/></dir><file name="FolderTranslator.php" hash="19a335acf751d67bd7efe46829602490"/><dir name="Image"><file name="ImageFactory.php" hash="0a2e066331584d33a9c4ec03787fd6e5"/><file name="LocalImage.php" hash="ab9b814b1a006baf05b9904af3ebce74"/><file name="Synchronizable.php" hash="b842f71ed25718838233207b7748f1bf"/><file name="SynchronizationChecker.php" hash="f2c45545766a81fede68138cf84dd1af"/><dir name="Transformation"><file name="Crop.php" hash="84e57281780a57326c938ac776641e8b"/><file name="Dimensions.php" hash="86a36c564aa41a08da2cf383d611c060"/><file name="Dpr.php" hash="f78cd1bfabaf3088ca8d4af972bfd453"/><file name="FetchFormat.php" hash="c745a6d80b509755cb6ae9fe37b95d76"/><file name="Gravity.php" hash="c1c2adf4dbbeaa6b06d67d2014300559"/><file name="Quality.php" hash="23a857f3910aecf6e45645194ff7f54e"/></dir><file name="Transformation.php" hash="7037bb18dcf82ee729deb6a06344faab"/></dir><file name="Image.php" hash="3090cfbaa3b2a90b5ef4a2a94b165581"/><file name="ImageInterface.php" hash="4a7c7e39d7fda0b0fa99affcac78ec8c"/><file name="ImageProvider.php" hash="a615c472cdc8a6ad7d887133db35c262"/><dir name="Migration"><file name="BatchUploader.php" hash="87d9dcf1c07fb9975283d7e4f577f1b9"/><file name="Logger.php" hash="648b47bb065de0c81b386ac300b4f9a3"/><file name="Queue.php" hash="add92864192b0950c29c91ffe5e5a3ee"/><file name="SynchronizedMediaRepository.php" hash="6b4e07f253aad9b845c68d51a1ab4166"/><file name="Task.php" hash="ac11d06c531d48b38cf88f6e8f2bdc19"/></dir><dir name="Security"><file name="ApiSignature.php" hash="049c7db2684ec2a6cf5bb4efcd064951"/><file name="CloudinaryEnvironmentVariable.php" hash="418af61bdbcfef955df29ac47c54415b"/><file name="ConsoleUrl.php" hash="4e748cfe0f5a0aeab2307c623179c6f9"/><file name="EnvironmentVariable.php" hash="297fa60b819ffc028b9a32dae6eef63d"/><file name="Key.php" hash="ac3a50b59f2a7db1edcf30386759c7ec"/><file name="Secret.php" hash="b1010679976575d57752dbb07f1b94ed"/><file name="SignedConsoleUrl.php" hash="791e1f1080be23423c2ad87f431f6221"/></dir><file name="SynchroniseAssetsRepositoryInterface.php" hash="e0d8e270ae2c74214e82e53e04e3dc0f"/><file name="UploadConfig.php" hash="a68f1ea7b84574ec36a8d2fac9bd6054"/><file name="UploadResponseValidator.php" hash="2d20dba12898b277b20b010d24f18859"/><file name="UrlGenerator.php" hash="06d223e5628c68570a2af4f8fb2306ce"/><file name="ValidateRemoteUrlRequest.php" hash="c2e2eb712e5293ad508a23610dfbbd6d"/></dir><dir name="Cloudinary"><file name="Api.php" hash="d71322346c3625db7c3563cdad191e8c"/><file name="AuthToken.php" hash="bec8b856baf85d89a249c932c3eba39f"/><file name="Cloudinary.php" hash="f2ec7b7bc8fc7c978f7773c3d4ccc5dd"/><file name="CloudinaryField.php" hash="411714580d21b58115ab07737367173a"/><file name="Helpers.php" hash="4db8371fc84d34be49c8ea04eee7d6eb"/><file name="PreloadedFile.php" hash="73cc9e276f96553814f05eae592d11ee"/><file name="Uploader.php" hash="eae92a330d19654028a8d16410616421"/><file name="cacert.pem" hash="c4290b9deb70d0bef2f88b67fc68c8ec"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="cloudinary"><file name="cloudinary.xml" hash="e5a2def3fccdb6a365364dcf23964d08"/></dir></dir><dir name="template"><dir name="cloudinary"><file name="manage.phtml" hash="7630d346f45d7118748b647be3501fa3"/><dir name="system"><dir name="config"><file name="signup.phtml" hash="2a0e06990eb542f22531ac2ebb5996f5"/></dir></dir></dir></dir></dir></dir></dir></target></contents>
|
18 |
<compatible/>
|
19 |
<dependencies><required><php><min>5.4.0</min><max>7.1.0</max></php></required></dependencies>
|
20 |
</package>
|