Skip to content

Commit 0efe399

Browse files
author
Pini
authored
Merge pull request #17 from cloudinary/v1.7.4
v1.7.4
2 parents 41be101 + d9f7fe8 commit 0efe399

28 files changed

+183
-135
lines changed

Block/Adminhtml/Product/Edit/NewVideo.php

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ protected function getCloudinaryConfig()
4949
$this->_cloudinaryConfig['api_url'] = "https://api.cloudinary.com/v1_1/{$this->_cloudinaryConfig['cloud_name']}/";
5050
}
5151
}
52+
5253
return $this->_cloudinaryConfig;
5354
}
5455

@@ -85,11 +86,13 @@ protected function getNoteVideoUrl()
8586
} else {
8687
$result .= __(', YouTube');
8788
}
89+
8890
if (!$this->getCloudinaryConfig()) {
8991
$messages .= __('<br>*To add Cloudinary video, please <a href="%1">enter your Cloudinary Account Credentials</a> first.', $this->getCloudinaryConfigUrl());
9092
} else {
9193
$result .= __(', Cloudinary');
9294
}
95+
9396
return $result . $messages;
9497
}
9598

Command/UploadImages.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(BatchUploader $batchUploader, OutputLogger $outputLo
3333

3434
/**
3535
* Configure the command
36-
*
36+
*
3737
* @return void
3838
*/
3939
protected function configure()

Core/CloudinaryImageProvider.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ public function upload(Image $image)
8484
public function retrieveTransformed(Image $image, Transformation $transformation)
8585
{
8686
$imagePath = \cloudinary_url(
87-
$image->getId(), [
87+
$image->getId(),
88+
[
8889
'transformation' => $transformation->build(),
8990
'secure' => true,
9091
'sign_url' => $this->configuration->getUseSignedUrls()
@@ -141,6 +142,7 @@ public function validateCredentials()
141142
} catch (\Exception $e) {
142143
return false;
143144
}
145+
144146
return true;
145147
}
146148

Core/ConfigurationBuilder.php

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function build()
2525
if ($this->configuration->getCdnSubdomainStatus()) {
2626
$config['cdn_subdomain'] = true;
2727
}
28+
2829
return $config;
2930
}
3031
}

Core/Image/Transformation/Dimensions.php

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public static function squareMissingDimension(Dimensions $dimensions)
3636
} elseif (!$dimensions->getHeight()) {
3737
return Dimensions::square($dimensions->getWidth());
3838
}
39+
3940
return $dimensions;
4041
}
4142

Core/Migration/BatchUploader.php

+3
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ public function uploadImages(array $images)
8888
if ($this->migrationTask->hasBeenStopped()) {
8989
break;
9090
}
91+
9192
$this->uploadImage($image);
9293
}
94+
9395
$this->logger->notice(sprintf(self::MESSAGE_STATUS, $this->countMigrated, $this->countFailed));
9496
}
9597

@@ -160,6 +162,7 @@ private function addRetryMessage($retryMessage, \Exception $e)
160162
} else {
161163
$e = new \Exception($e->getMessage() . $retryMessage);
162164
}
165+
163166
return $e;
164167
}
165168

Core/ValidateRemoteUrlRequest.php

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function validate()
1919
if ($result->responseCode == 200 && is_null($result->error)) {
2020
return true;
2121
}
22+
2223
return false;
2324
}
2425

Model/Api/ResourcesManagement.php

+20-14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Cloudinary\Api;
77
use Cloudinary\Cloudinary\Core\ConfigurationBuilder;
88
use Cloudinary\Cloudinary\Core\ConfigurationInterface;
9+
use Magento\Framework\App\Request\Http;
10+
use Magento\Framework\Json\EncoderInterface;
911

1012
class ResourcesManagement implements \Cloudinary\Cloudinary\Api\ResourcesManagementInterface
1113
{
@@ -28,26 +30,36 @@ class ResourcesManagement implements \Cloudinary\Cloudinary\Api\ResourcesManagem
2830
private $_api;
2931

3032
/**
31-
* @var \Magento\Framework\App\Request\Http
33+
* @var Http
3234
*/
3335
private $_request;
3436

37+
/**
38+
* @var EncoderInterface
39+
*/
40+
private $_jsonEncoder;
41+
3542
/**
3643
* ApiClient constructor.
3744
*
3845
* @param ConfigurationInterface $configuration
3946
* @param ConfigurationBuilder $configurationBuilder
47+
* @param Api $api
48+
* @param Http $request
49+
* @param EncoderInterface $jsonEncoder
4050
*/
4151
public function __construct(
4252
ConfigurationInterface $configuration,
4353
ConfigurationBuilder $configurationBuilder,
4454
Api $api,
45-
\Magento\Framework\App\Request\Http $request
55+
Http $request,
56+
EncoderInterface $jsonEncoder
4657
) {
4758
$this->_configuration = $configuration;
4859
$this->_configurationBuilder = $configurationBuilder;
4960
$this->_api = $api;
5061
$this->_request = $request;
62+
$this->_jsonEncoder = $jsonEncoder;
5163
if ($this->_configuration->isEnabled()) {
5264
$this->_authorise();
5365
}
@@ -59,13 +71,6 @@ private function _authorise()
5971
Cloudinary::$USER_PLATFORM = $this->_configuration->getUserPlatform();
6072
}
6173

62-
public function _sendJsonResponse($response)
63-
{
64-
header('Content-Type: application/json');
65-
echo json_encode($response);
66-
die;
67-
}
68-
6974
/**
7075
* Get details of a single resource
7176
*
@@ -76,18 +81,19 @@ protected function _getResourceData()
7681
{
7782
try {
7883
$this->_resourceData = $this->_api->resource(
79-
$this->_request->getParam("id"), [
84+
$this->_request->getParam("id"),
85+
[
8086
"resource_type" => $this->_resourceType
8187
]
8288
);
83-
$this->_sendJsonResponse(
89+
return $this->_jsonEncoder->encode(
8490
[
8591
"error" => 0,
8692
"data" => $this->_resourceData
8793
]
8894
);
8995
} catch (\Exception $e) {
90-
$this->_sendJsonResponse(
96+
return $this->_jsonEncoder->encode(
9197
[
9298
"error" => 1,
9399
"message" => $e->getMessage()
@@ -102,7 +108,7 @@ protected function _getResourceData()
102108
public function getImage()
103109
{
104110
$this->_resourceType = "image";
105-
$this->_getResourceData();
111+
return $this->_getResourceData();
106112
}
107113

108114
/**
@@ -111,6 +117,6 @@ public function getImage()
111117
public function getVideo()
112118
{
113119
$this->_resourceType = "video";
114-
$this->_getResourceData();
120+
return $this->_getResourceData();
115121
}
116122
}

Model/BatchUploader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ public function uploadUnsynchronisedImages(OutputInterface $output = null)
8585
$this->displayMessage($output, self::MESSAGE_UPLOAD_INTERRUPTED);
8686
return false;
8787
}
88+
8889
$this->uploadAndSynchronise($image, $output);
8990
}
9091

9192
$this->migrationTask->stop();
9293
$this->displayMessage($output, sprintf(self::MESSAGE_UPLOAD_COMPLETE, count($images)));
9394

9495
return true;
95-
9696
} catch (\Exception $e) {
9797
$this->migrationTask->stop();
9898
throw $e;

Model/Config/Backend/Credentials.php

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public function beforeSave()
105105
if (!$rawValue) {
106106
throw new ValidatorException(__(self::CREDENTIALS_CHECK_MISSING));
107107
}
108+
108109
if ($this->isSaveAllowed()) {
109110
$this->validate($this->getCredentialsFromEnvironmentVariable($rawValue));
110111
} else {
@@ -143,6 +144,7 @@ private function getCredentialsFromEnvironmentVariable($environmentVariable)
143144
if (Cloudinary::config_get('private_cdn')) {
144145
$credentials["private_cdn"] = Cloudinary::config_get('private_cdn');
145146
}
147+
146148
return $credentials;
147149
} catch (\Exception $e) {
148150
throw new ValidatorException(__(self::CREDENTIALS_CHECK_FAILED));

Model/Config/Backend/Free.php

-2
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,11 @@ public function __construct(
7373
public function beforeSave()
7474
{
7575
if ($this->hasAccountConfigured() && $this->getValue()) {
76-
7776
$transform = $this->configuration
7877
->getDefaultTransformation()
7978
->withFreeform(Freeform::fromString($this->getValue()));
8079

8180
$this->validate($this->sampleImageUrl($transform));
82-
8381
}
8482

8583
parent::beforeSave();

Model/Config/Source/Dropdown/Dpr.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ class Dpr implements OptionSourceInterface
88
{
99
public function toOptionArray()
1010
{
11-
return array(
12-
array(
11+
return [
12+
[
1313
'value' => '1.0',
1414
'label' => '1.0',
15-
),
16-
array(
15+
],
16+
[
1717
'value' => '2.0',
1818
'label' => '2.0',
19-
),
20-
);
19+
],
20+
];
2121
}
2222
}

Model/Configuration.php

+1
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ public function getEnvironmentVariable()
261261
$this->logger->critical($invalidConfigException);
262262
}
263263
}
264+
264265
return $this->environmentVariable;
265266
}
266267

Model/Observer/Configuration.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public function execute(Observer $observer)
7373
$this->changedPaths = (array) $observer->getEvent()->getChangedPaths();
7474
if (count(
7575
array_intersect(
76-
$this->changedPaths, [
76+
$this->changedPaths,
77+
[
7778
\Cloudinary\Cloudinary\Model\Configuration::CONFIG_PATH_ENABLED,
7879
\Cloudinary\Cloudinary\Model\Configuration::CONFIG_PATH_ENVIRONMENT_VARIABLE,
7980
\Cloudinary\Cloudinary\Model\AutoUploadMapping\AutoUploadConfiguration::REQUEST_PATH

Model/ProductImageFinder.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public function findDeletedImages(Product $product)
5757
private function find(Product $product, ImageFilter $filter)
5858
{
5959
return array_map(
60-
$this->imageCreator, array_filter(
60+
$this->imageCreator,
61+
array_filter(
6162
$product->getMediaGallery('images') ?: [],
6263
$filter
6364
)

Model/ProductImageFinder/DeletedImageFilter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ public function __invoke($imageData)
1212
{
1313
return isset($imageData['removed']) && $imageData['removed'] == 1;
1414
}
15-
}
15+
}

Model/ProductImageFinder/ImageCreator.php

-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,3 @@ public function __invoke(array $imageData)
5353
);
5454
}
5555
}
56-

Model/ProductImageFinder/ImageFilter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ interface ImageFilter
1414
* @return boolean
1515
*/
1616
public function __invoke($imageData);
17-
}
17+
}

Model/ProductImageFinder/NewImageFilter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ public function __invoke($imageData)
1616
{
1717
return !empty($imageData['new_file']);
1818
}
19-
}
19+
}

Model/SynchronisationRepository.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
use Magento\Framework\Api\SearchResultsInterface;
1717
use Magento\Framework\Api\SearchResultsInterfaceFactory;
1818

19-
class SynchronisationRepository
20-
implements SynchronisationRepositoryInterface, SynchroniseAssetsRepositoryInterface
19+
class SynchronisationRepository implements SynchronisationRepositoryInterface, SynchroniseAssetsRepositoryInterface
2120
{
2221
/**
2322
* @var CollectionFactory

Model/Transformation.php

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public function addFreeformTransformationForImage(ImageTransformation $transform
9898
if (($this->getImageName() === $imageFile) && $this->hasFreeTransformation()) {
9999
$transformation->withFreeform(Freeform::fromString($this->getFreeTransformation()));
100100
}
101+
101102
return $transformation;
102103
}
103104

Plugin/Catalog/Block/Product/ImageFactory.php

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ private function createTransformation(array $imageMiscParams)
177177
if (isset($imageMiscParams['keep_frame'])) {
178178
$this->keepFrame = ($imageMiscParams['keep_frame'] === 'frame') ? true : false;
179179
}
180+
180181
if ($this->keepFrame) {
181182
$transform->withCrop(Crop::fromString('lpad'))
182183
->withDimensions(Dimensions::squareMissingDimension($dimensions));

Plugin/Catalog/Model/Product/Image/UrlBuilder.php

+1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ private function createTransformation(array $imageMiscParams)
174174
if (isset($imageMiscParams['keep_frame'])) {
175175
$this->keepFrame = ($imageMiscParams['keep_frame'] === 'frame') ? true : false;
176176
}
177+
177178
if ($this->keepFrame) {
178179
$transform->withCrop(Crop::fromString('lpad'))
179180
->withDimensions(Dimensions::squareMissingDimension($dimensions));

Plugin/ImageHelper.php

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public function aroundGetUrl(CatalogImageHelper $helper, \Closure $originalMetho
137137
if (!$this->configuration->isEnabled()) {
138138
return $originalMethod();
139139
}
140+
140141
$imagePath = $this->imageFile ?: $this->product->getData($helper->getType());
141142

142143
$image = $this->imageFactory->build(sprintf('catalog/product%s', $imagePath), $originalMethod);

Plugin/Widget/Model/Template/Filter.php

+2
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ public function aroundMediaDirective(\Magento\Widget\Model\Template\Filter $widg
6464
if (!$this->_configuration->isEnabled()) {
6565
return $proceed($construction);
6666
}
67+
6768
$params = $this->_cloudinaryWidgetFilter->getParams($construction[2]);
6869
if (!isset($params['url'])) {
6970
return $proceed($construction);
7071
}
72+
7173
$url = (preg_match('/^&quot;.+&quot;$/', $params['url'])) ? preg_replace('/(^&quot;)|(&quot;$)/', '', $params['url']) : $params['url'];
7274

7375
$image = $this->_imageFactory->build(

Setup/UpgradeData.php

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
5151
if ($context->getVersion()) {
5252
$this->output->writeln("<comment>Reseting configurations for 'website' & 'store' scopes (only supports 'default' at the moment)</comment>");
5353
}
54+
5455
$this->resourceConnection->getConnection()->delete(
5556
$this->resourceConnection->getTableName('core_config_data'),
5657
"path LIKE 'cloudinary/%' AND scope != 'default'"

0 commit comments

Comments
 (0)