Skip to content

Commit

Permalink
Merge pull request #38 from cloudinary/v1.9.8
Browse files Browse the repository at this point in the history
V1.9.8
  • Loading branch information
Pniel (Pini) Cohen authored Sep 12, 2019
2 parents afcde86 + 8c5a490 commit fdc1d48
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Helper/ProductGalleryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down
2 changes: 1 addition & 1 deletion Model/BatchDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<comment>' . sprintf(self::WAIT_FOR_RATE_LIMIT_RESET_MESSAGE, date('Y-m-d H:i:s', ($this->_rateLimitResetAt + 10))) . '</comment>');
@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) {
Expand Down
2 changes: 1 addition & 1 deletion Model/Config/Backend/ProductGalleryCustomFreeParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Model/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Plugin/Catalog/Block/Product/View/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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'];
Expand Down
17 changes: 17 additions & 0 deletions Plugin/ExcludeFilesFromMinification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Cloudinary\Cloudinary\Plugin;

use Magento\Framework\View\Asset\Minification;

class ExcludeFilesFromMinification
{
public function afterGetExcludes(Minification $subject, array $result, $contentType)
{
if ($contentType == 'js') {
$result[] = '//media-library.cloudinary.com/global/all';
$result[] = '//product-gallery.cloudinary.com/all';
}
return $result;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*"
Expand Down
6 changes: 5 additions & 1 deletion etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@
<plugin name="cloudinary_plugin_catalog_block_product_view_gallery" type="Cloudinary\Cloudinary\Plugin\Catalog\Block\Product\View\Gallery"/>
</type>

</config>
<type name="Magento\Framework\View\Asset\Minification">
<plugin name="cloudinary_plugin_framework_view_asset_minification" type="Cloudinary\Cloudinary\Plugin\ExcludeFilesFromMinification" />
</type>

</config>
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Cloudinary_Cloudinary" setup_version="1.9.7">
<module name="Cloudinary_Cloudinary" setup_version="1.9.8">
<sequence>
<module name="Magento_ProductVideo"/>
</sequence>
Expand Down
2 changes: 1 addition & 1 deletion marketplace.composer.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
45 changes: 39 additions & 6 deletions view/adminhtml/web/js/cloudinary-media-library-modal.js
Original file line number Diff line number Diff line change
@@ -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', {
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -76,15 +92,18 @@ 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) {
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}$'), '')
Expand Down Expand Up @@ -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', '<br>'));
}
});
}
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);
}
}
);
}
Expand Down

0 comments on commit fdc1d48

Please sign in to comment.