From d55622f13a71f043546a1fe2193f36190707cb53 Mon Sep 17 00:00:00 2001 From: pini-girit Date: Sun, 18 Aug 2019 17:08:47 +0300 Subject: [PATCH 1/6] CLOUDINARY-185: Fixed transformations parsing (regex) on media-library widget --- view/adminhtml/web/js/cloudinary-media-library-modal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/adminhtml/web/js/cloudinary-media-library-modal.js b/view/adminhtml/web/js/cloudinary-media-library-modal.js index 5315975..dee9569 100644 --- a/view/adminhtml/web/js/cloudinary-media-library-modal.js +++ b/view/adminhtml/web/js/cloudinary-media-library-modal.js @@ -84,7 +84,7 @@ define([ if (asset.derived && asset.derived[0] && asset.derived[0].secure_url) { asset.asset_derived_url = asset.asset_derived_image_url = asset.derived[0].secure_url; asset.free_transformation = asset.asset_derived_image_url - .replace(new RegExp('^.*cloudinary.com/' + this.options.cloudinaryMLoptions.cloud_name + '/' + asset.resource_type + '/' + asset.type + '/'), '') + .replace(new RegExp('^.*cloudinary.com/(' + this.options.cloudinaryMLoptions.cloud_name + '/)?' + asset.resource_type + '/' + asset.type + '/'), '') .replace(/\.[^/.]+$/, '') .replace(new RegExp('\/' + asset.public_id + '$'), '') .replace(new RegExp('\/v[0-9]{1,10}$'), '') From 16f9afdb952b246d49113e1f2bbb3598a4ea60b3 Mon Sep 17 00:00:00 2001 From: pini-girit Date: Tue, 20 Aug 2019 11:42:33 +0300 Subject: [PATCH 2/6] CLOUDINARY-183: Changed getMigratedPath() to always add the media dir prefix --- Model/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/Configuration.php b/Model/Configuration.php index 3981ae3..a5d0fac 100644 --- a/Model/Configuration.php +++ b/Model/Configuration.php @@ -242,7 +242,7 @@ public function getFormatsToPreserve() */ public function getMigratedPath($file) { - return $this->autoUploadConfiguration->isActive() ? sprintf('%s/%s', DirectoryList::MEDIA, $file) : $file; + return sprintf('%s/%s', DirectoryList::MEDIA, $file); } /** From 9b760f5ee8b64ed64c1be64ad5eb00ed5358ea8e Mon Sep 17 00:00:00 2001 From: pini-girit Date: Mon, 2 Sep 2019 12:07:09 +0300 Subject: [PATCH 3/6] v1.9.9: Excluded cloudinary external JS scripts from Magento minification --- Plugin/ExcludeFilesFromMinification.php | 17 +++++++++++++++++ etc/di.xml | 6 +++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 Plugin/ExcludeFilesFromMinification.php diff --git a/Plugin/ExcludeFilesFromMinification.php b/Plugin/ExcludeFilesFromMinification.php new file mode 100644 index 0000000..1fdf8ed --- /dev/null +++ b/Plugin/ExcludeFilesFromMinification.php @@ -0,0 +1,17 @@ + - \ No newline at end of file + + + + + From 9c2f9d0fa4b9695cb1813d9725fbb4e508bbc376 Mon Sep 17 00:00:00 2001 From: pini-girit Date: Mon, 2 Sep 2019 12:10:54 +0300 Subject: [PATCH 4/6] v1.9.8: Change version to 1.9.8 --- Model/Configuration.php | 2 +- composer.json | 2 +- etc/module.xml | 2 +- marketplace.composer.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Model/Configuration.php b/Model/Configuration.php index a5d0fac..d61fcd4 100644 --- a/Model/Configuration.php +++ b/Model/Configuration.php @@ -199,7 +199,7 @@ public function getCdnSubdomainStatus() */ public function getUserPlatform() { - return sprintf(self::USER_PLATFORM_TEMPLATE, '1.9.7', '2.0.0'); + return sprintf(self::USER_PLATFORM_TEMPLATE, '1.9.8', '2.0.0'); } /** diff --git a/composer.json b/composer.json index f6fa35c..423cccd 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "cloudinary/cloudinary-magento2", "description": "Cloudinary Magento 2 Integration.", "type": "magento2-module", - "version": "1.9.7", + "version": "1.9.8", "license": "MIT", "require": { "cloudinary/cloudinary_php": "*" diff --git a/etc/module.xml b/etc/module.xml index c79bb8a..96699ac 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - + diff --git a/marketplace.composer.json b/marketplace.composer.json index 0867af0..d335f3e 100644 --- a/marketplace.composer.json +++ b/marketplace.composer.json @@ -1,7 +1,7 @@ { "name": "cloudinary/cloudinary", "type": "magento2-module", - "version": "1.9.7", + "version": "1.9.8", "description": "Cloudinary Magento 2 Integration.", "license": "MIT", "require": { From bf2b10cdab6c5a075f1fb202f8a666f37ca30752 Mon Sep 17 00:00:00 2001 From: pini-girit Date: Mon, 2 Sep 2019 12:17:04 +0300 Subject: [PATCH 5/6] Applied magento-coding-standards --- Helper/ProductGalleryHelper.php | 2 +- Model/BatchDownloader.php | 2 +- Model/Config/Backend/ProductGalleryCustomFreeParams.php | 2 +- Plugin/Catalog/Block/Product/View/Gallery.php | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Helper/ProductGalleryHelper.php b/Helper/ProductGalleryHelper.php index 5741ffc..09381ce 100644 --- a/Helper/ProductGalleryHelper.php +++ b/Helper/ProductGalleryHelper.php @@ -90,7 +90,7 @@ public function getCloudinaryPGOptions($refresh = false, $ignoreDisabled = false unset($this->cloudinaryPGoptions['enabled']); } if (isset($this->cloudinaryPGoptions['custom_free_params'])) { - $customFreeParams = (array) @json_decode($this->cloudinaryPGoptions['custom_free_params'], true); + $customFreeParams = (array) json_decode($this->cloudinaryPGoptions['custom_free_params'], true); $this->cloudinaryPGoptions = array_replace_recursive($this->cloudinaryPGoptions, $customFreeParams); unset($this->cloudinaryPGoptions['custom_free_params']); } diff --git a/Model/BatchDownloader.php b/Model/BatchDownloader.php index 01409b8..6114c8b 100644 --- a/Model/BatchDownloader.php +++ b/Model/BatchDownloader.php @@ -264,7 +264,7 @@ public function downloadUnsynchronisedImages(OutputInterface $output = null, $ov } if (($this->_nextCursor = $response->getNextCursor()) && (int)$this->_rateLimitRemaining <= self::API_REQUEST_STOP_ON_REMAINING_RATE_LIMIT) { $this->displayMessage('' . sprintf(self::WAIT_FOR_RATE_LIMIT_RESET_MESSAGE, date('Y-m-d H:i:s', ($this->_rateLimitResetAt + 10))) . ''); - @time_sleep_until($this->_rateLimitResetAt + 10); + time_sleep_until($this->_rateLimitResetAt + 10); } sleep(self::API_REQUESTS_SLEEP_BEFORE_NEXT_CALL); //Wait between each API call. } catch (\Exception $e) { diff --git a/Model/Config/Backend/ProductGalleryCustomFreeParams.php b/Model/Config/Backend/ProductGalleryCustomFreeParams.php index 04ea774..959a5c9 100644 --- a/Model/Config/Backend/ProductGalleryCustomFreeParams.php +++ b/Model/Config/Backend/ProductGalleryCustomFreeParams.php @@ -63,7 +63,7 @@ public function beforeSave() $this->appConfig->reinit(); if ($rawValue) { - $data = @json_decode($rawValue); + $data = json_decode($rawValue); if ($data === null || $data === false) { $this->setValue('{}'); try { diff --git a/Plugin/Catalog/Block/Product/View/Gallery.php b/Plugin/Catalog/Block/Product/View/Gallery.php index 52d83ef..030b82a 100644 --- a/Plugin/Catalog/Block/Product/View/Gallery.php +++ b/Plugin/Catalog/Block/Product/View/Gallery.php @@ -64,7 +64,7 @@ public function beforeToHtml(\Magento\Catalog\Block\Product\View\Gallery $produc public function getHtmlId() { if (!$this->htmlId) { - $this->htmlId = md5(uniqid('', true)); + $this->htmlId = hash('sha256', uniqid('', true)); } return $this->htmlId; } @@ -85,7 +85,7 @@ protected function getCloudinaryPGOptions($refresh = false, $ignoreDisabled = fa if (is_null($this->cloudinaryPGoptions) || $refresh) { $this->cloudinaryPGoptions = $this->productGalleryHelper->getCloudinaryPGOptions($refresh, $ignoreDisabled); $this->cloudinaryPGoptions['container'] = '#' . $this->getCldPGid(); - $galleryAssets = (array) @json_decode($this->productGalleryBlock->getGalleryImagesJson(), true); + $galleryAssets = (array) json_decode($this->productGalleryBlock->getGalleryImagesJson(), true); if (count($galleryAssets)>1) { usort($galleryAssets, function ($a, $b) { return $a['position'] - $b['position']; From 8c5a490e9634b9e2d20498bf08f3a07aa1addc27 Mon Sep 17 00:00:00 2001 From: pini-girit Date: Wed, 4 Sep 2019 18:00:10 +0300 Subject: [PATCH 6/6] v1.9.8: CLOUDINARY-184: Added alert on media-library errors. --- .../web/js/cloudinary-media-library-modal.js | 43 ++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/view/adminhtml/web/js/cloudinary-media-library-modal.js b/view/adminhtml/web/js/cloudinary-media-library-modal.js index dee9569..8a02b66 100644 --- a/view/adminhtml/web/js/cloudinary-media-library-modal.js +++ b/view/adminhtml/web/js/cloudinary-media-library-modal.js @@ -1,14 +1,16 @@ define([ 'jquery', 'productGallery', + 'Magento_Ui/js/modal/alert', + 'mage/backend/notification', + 'mage/translate', 'jquery/ui', 'Magento_Ui/js/modal/modal', - 'mage/translate', 'mage/backend/tree-suggest', 'mage/backend/validation', 'cloudinaryMediaLibraryAll', 'es6Promise' -], function($, productGallery) { +], function($, productGallery, uiAlert, notification, $t) { 'use strict'; $.widget('mage.cloudinaryMediaLibraryModal', { @@ -39,6 +41,20 @@ define([ } }, + /** + * @param {Array} messages + */ + notifyError: function(messages) { + var data = { + content: messages.join('') + }; + if (messages.length > 1) { + data.modalClass = '_image-box'; + } + uiAlert(data); + return this; + }, + /** * @private */ @@ -76,9 +92,12 @@ define([ */ cloudinaryInsertHandler: function(data) { var widget = this; + var aggregatedErrorMessages = []; + var $i = data.assets.length; data.assets.forEach(asset => { //console.log(asset); + $i--; if (widget.options.imageUploaderUrl) { asset.asset_url = asset.asset_image_url = asset.secure_url; if (asset.derived && asset.derived[0] && asset.derived[0].secure_url) { @@ -140,15 +159,29 @@ define([ widget.options.callbackHandler[widget.options.callbackHandlerMethod](file); } } else { - alert($.mage.__('An error occured during ' + asset.resource_type + ' insert!')); console.error(file); + notification().add({ + error: true, + message: $t('An error occured during ' + asset.resource_type + ' insert (' + asset.public_id + ')!') + '%s%sError: ' + file.error.replace(/File:.*$/, ''), + insertMethod: function(constructedMessage) { + aggregatedErrorMessages.push(constructedMessage.replace('%s%s', '
')); + } + }); + } + if (!$i && aggregatedErrorMessages.length) { + widget.notifyError(aggregatedErrorMessages); } - } ).fail( function(response) { - alert($.mage.__('An error occured during ' + asset.resource_type + ' insert!')); console.error(response); + notification().add({ + error: true, + message: $t('An error occured during ' + asset.resource_type + ' insert (' + asset.public_id + ')!') + }); + if (!$i && aggregatedErrorMessages.length) { + widget.notifyError(aggregatedErrorMessages); + } } ); }