Skip to content

Commit

Permalink
Merge pull request #25 from cloudinary/release/core-1.7.2-m1-2.8.2-m2…
Browse files Browse the repository at this point in the history
…-1.5.3

Core 1.7.2 M2 1.5.3
  • Loading branch information
nadavofi authored Feb 26, 2018
2 parents 649d69c + 9cdf72c commit dd9afc0
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 20 deletions.
48 changes: 43 additions & 5 deletions core/lib/Cloudinary/Cloudinary/Core/CloudinaryImageProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Cloudinary\Cloudinary\Core;

use Cloudinary;
Expand All @@ -13,20 +12,32 @@

class CloudinaryImageProvider implements ImageProvider
{
/**
* @var ConfigurationInterface
*/
private $configuration;

/**
* @var UploadResponseValidator
*/
private $uploadResponseValidator;

/**
* @var ConfigurationBuilder
*/
private $configurationBuilder;

/**
* @var CredentialValidator
*/
private $credentialValidator;

/**
* @param ConfigurationInterface $configuration
* @param ConfigurationBuilder $configurationBuilder
* @param UploadResponseValidator $uploadResponseValidator
* @param CredentialValidator $credentialValidator
*/
public function __construct(
ConfigurationInterface $configuration,
ConfigurationBuilder $configurationBuilder,
Expand All @@ -42,6 +53,10 @@ public function __construct(
}
}

/**
* @param ConfigurationInterface $configuration
* @return CloudinaryImageProvider
*/
public static function fromConfiguration(ConfigurationInterface $configuration){
return new CloudinaryImageProvider(
$configuration,
Expand All @@ -51,22 +66,32 @@ public static function fromConfiguration(ConfigurationInterface $configuration){
);
}

/**
* @param Image $image
* @return mixed
*/
public function upload(Image $image)
{
$uploadResult = null;
if (!$this->configuration->isEnabled()) {
return false;
}

try {
$uploadResult = Uploader::upload(
(string)$image,
$this->configuration->getUploadConfig()->toArray() + [ "folder" => $image->getRelativeFolder()]
);
return $this->uploadResponseValidator->validateResponse($image, $uploadResult);
} catch (\Exception $e) {
ApiError::throwWith($image, $e->getMessage());
}

return $this->uploadResponseValidator->validateResponse($image, $uploadResult);
}

/**
* @param Image $image
* @param Transformation $transformation
* @return Image
*/
public function retrieveTransformed(Image $image, Transformation $transformation)
{
return Image::fromPath(
Expand All @@ -75,16 +100,29 @@ public function retrieveTransformed(Image $image, Transformation $transformation
);
}

/**
* @param Image $image
* @return Image
*/
public function retrieve(Image $image)
{
return $this->retrieveTransformed($image, $this->configuration->getDefaultTransformation());
}

/**
* @param Image $image
* @return bool
*/
public function delete(Image $image)
{
Uploader::destroy($image->getIdWithoutExtension());
if ($this->configuration->isEnabled()) {
Uploader::destroy($image->getIdWithoutExtension());
}
}

/**
* @return bool
*/
public function validateCredentials()
{
return $this->credentialValidator->validate($this->configuration->getCredentials());
Expand Down
5 changes: 0 additions & 5 deletions magento2/Model/Config/Backend/Credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ public function beforeSave()

parent::beforeSave();

if (!$this->isModuleActiveInFormData()) {
$this->_dataSaveAllowed = true;
return;
}

if (!$rawValue) {
throw new ValidatorException(__(self::CREDENTIALS_CHECK_MISSING));
}
Expand Down
2 changes: 1 addition & 1 deletion magento2/Model/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function getCdnSubdomainStatus()
*/
public function getUserPlatform()
{
return sprintf(self::USER_PLATFORM_TEMPLATE, '1.5.1', '2.0.0');
return sprintf(self::USER_PLATFORM_TEMPLATE, '1.5.3', '2.0.0');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion magento2/Model/ProductImageFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function findDeletedImages(Product $product)
private function find(Product $product, ImageFilter $filter)
{
return array_map($this->imageCreator, array_filter(
$product->getMediaGallery('images'),
$product->getMediaGallery('images') ?: [],
$filter
));
}
Expand Down
17 changes: 13 additions & 4 deletions magento2/Plugin/FileUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public function __construct(
*/
public function afterSave(Uploader $uploader, $result)
{
$filepath = $this->absolutePath($result);
$filepath = $this->absoluteFilePath($result);

if (!$this->isTemporaryPath($filepath)) {
if ($this->isMediaFilePath($filepath) && !$this->isMediaTmpFilePath($filepath)) {

$this->cloudinaryImageManager->uploadAndSynchronise(
Image::fromPath($filepath, $this->mediaRelativePath($filepath))
Expand All @@ -55,7 +55,16 @@ public function afterSave(Uploader $uploader, $result)
* @param string $filepath
* @return bool
*/
protected function isTemporaryPath($filepath)
protected function isMediaFilePath($filepath)
{
return strpos($filepath, $this->directoryList->getPath('media')) === 0;
}

/**
* @param string $filepath
* @return string
*/
protected function isMediaTmpFilePath($filepath)
{
return strpos($filepath, sprintf('%s/tmp', $this->directoryList->getPath('media'))) === 0;
}
Expand All @@ -64,7 +73,7 @@ protected function isTemporaryPath($filepath)
* @param array $result
* @return string
*/
protected function absolutePath(array $result)
protected function absoluteFilePath(array $result)
{
return sprintf('%s%s%s', $result['path'], DIRECTORY_SEPARATOR, $result['file']);
}
Expand Down
2 changes: 1 addition & 1 deletion magento2/Ui/DataProvider/Product/Form/Modifier/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function modifyData(array $data)
$this->injectImageUrls(
$this->injectFreeTransformations(
$this->filterNonImageTypes(
$product->getMediaGalleryEntries()
$product->getMediaGalleryEntries() ?: []
)
)
)
Expand Down
4 changes: 2 additions & 2 deletions magento2/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "cloudinary/cloudinary",
"description": "Cloudinary Magento 2 Integration.",
"type": "magento2-module",
"version": "1.5.1",
"version": "1.5.3",
"minimum-stability": "dev",
"repositories": {
"0": {
Expand All @@ -13,7 +13,7 @@
"require": {
"php": ">=5.5",
"cloudinary/cloudinary_php": "1.8.0",
"inviqa/cloudinary-core": "1.7.0"
"inviqa/cloudinary-core": "1.7.1"
},
"require-dev": {
"phpspec/phpspec": "^3.0",
Expand Down
2 changes: 1 addition & 1 deletion magento2/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?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.5.1">
<module name="Cloudinary_Cloudinary" setup_version="1.5.3">
</module>
</config>

0 comments on commit dd9afc0

Please sign in to comment.