Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Block/Adminhtml/Product/Edit/NewVideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected function getCloudinaryConfig()
$this->_cloudinaryConfig['api_url'] = "https://api.cloudinary.com/v1_1/{$this->_cloudinaryConfig['cloud_name']}/";
}
}

return $this->_cloudinaryConfig;
}

Expand Down Expand Up @@ -85,11 +86,13 @@ protected function getNoteVideoUrl()
} else {
$result .= __(', YouTube');
}

if (!$this->getCloudinaryConfig()) {
$messages .= __('<br>*To add Cloudinary video, please <a href="%1">enter your Cloudinary Account Credentials</a> first.', $this->getCloudinaryConfigUrl());
} else {
$result .= __(', Cloudinary');
}

return $result . $messages;
}

Expand Down
2 changes: 1 addition & 1 deletion Command/UploadImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(BatchUploader $batchUploader, OutputLogger $outputLo

/**
* Configure the command
*
*
* @return void
*/
protected function configure()
Expand Down
4 changes: 3 additions & 1 deletion Core/CloudinaryImageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public function upload(Image $image)
public function retrieveTransformed(Image $image, Transformation $transformation)
{
$imagePath = \cloudinary_url(
$image->getId(), [
$image->getId(),
[
'transformation' => $transformation->build(),
'secure' => true,
'sign_url' => $this->configuration->getUseSignedUrls()
Expand Down Expand Up @@ -141,6 +142,7 @@ public function validateCredentials()
} catch (\Exception $e) {
return false;
}

return true;
}

Expand Down
1 change: 1 addition & 0 deletions Core/ConfigurationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function build()
if ($this->configuration->getCdnSubdomainStatus()) {
$config['cdn_subdomain'] = true;
}

return $config;
}
}
1 change: 1 addition & 0 deletions Core/Image/Transformation/Dimensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static function squareMissingDimension(Dimensions $dimensions)
} elseif (!$dimensions->getHeight()) {
return Dimensions::square($dimensions->getWidth());
}

return $dimensions;
}

Expand Down
3 changes: 3 additions & 0 deletions Core/Migration/BatchUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ public function uploadImages(array $images)
if ($this->migrationTask->hasBeenStopped()) {
break;
}

$this->uploadImage($image);
}

$this->logger->notice(sprintf(self::MESSAGE_STATUS, $this->countMigrated, $this->countFailed));
}

Expand Down Expand Up @@ -160,6 +162,7 @@ private function addRetryMessage($retryMessage, \Exception $e)
} else {
$e = new \Exception($e->getMessage() . $retryMessage);
}

return $e;
}

Expand Down
1 change: 1 addition & 0 deletions Core/ValidateRemoteUrlRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function validate()
if ($result->responseCode == 200 && is_null($result->error)) {
return true;
}

return false;
}

Expand Down
34 changes: 20 additions & 14 deletions Model/Api/ResourcesManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Cloudinary\Api;
use Cloudinary\Cloudinary\Core\ConfigurationBuilder;
use Cloudinary\Cloudinary\Core\ConfigurationInterface;
use Magento\Framework\App\Request\Http;
use Magento\Framework\Json\EncoderInterface;

class ResourcesManagement implements \Cloudinary\Cloudinary\Api\ResourcesManagementInterface
{
Expand All @@ -28,26 +30,36 @@ class ResourcesManagement implements \Cloudinary\Cloudinary\Api\ResourcesManagem
private $_api;

/**
* @var \Magento\Framework\App\Request\Http
* @var Http
*/
private $_request;

/**
* @var EncoderInterface
*/
private $_jsonEncoder;

/**
* ApiClient constructor.
*
* @param ConfigurationInterface $configuration
* @param ConfigurationBuilder $configurationBuilder
* @param Api $api
* @param Http $request
* @param EncoderInterface $jsonEncoder
*/
public function __construct(
ConfigurationInterface $configuration,
ConfigurationBuilder $configurationBuilder,
Api $api,
\Magento\Framework\App\Request\Http $request
Http $request,
EncoderInterface $jsonEncoder
) {
$this->_configuration = $configuration;
$this->_configurationBuilder = $configurationBuilder;
$this->_api = $api;
$this->_request = $request;
$this->_jsonEncoder = $jsonEncoder;
if ($this->_configuration->isEnabled()) {
$this->_authorise();
}
Expand All @@ -59,13 +71,6 @@ private function _authorise()
Cloudinary::$USER_PLATFORM = $this->_configuration->getUserPlatform();
}

public function _sendJsonResponse($response)
{
header('Content-Type: application/json');
echo json_encode($response);
die;
}

/**
* Get details of a single resource
*
Expand All @@ -76,18 +81,19 @@ protected function _getResourceData()
{
try {
$this->_resourceData = $this->_api->resource(
$this->_request->getParam("id"), [
$this->_request->getParam("id"),
[
"resource_type" => $this->_resourceType
]
);
$this->_sendJsonResponse(
return $this->_jsonEncoder->encode(
[
"error" => 0,
"data" => $this->_resourceData
]
);
} catch (\Exception $e) {
$this->_sendJsonResponse(
return $this->_jsonEncoder->encode(
[
"error" => 1,
"message" => $e->getMessage()
Expand All @@ -102,7 +108,7 @@ protected function _getResourceData()
public function getImage()
{
$this->_resourceType = "image";
$this->_getResourceData();
return $this->_getResourceData();
}

/**
Expand All @@ -111,6 +117,6 @@ public function getImage()
public function getVideo()
{
$this->_resourceType = "video";
$this->_getResourceData();
return $this->_getResourceData();
}
}
2 changes: 1 addition & 1 deletion Model/BatchUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ public function uploadUnsynchronisedImages(OutputInterface $output = null)
$this->displayMessage($output, self::MESSAGE_UPLOAD_INTERRUPTED);
return false;
}

$this->uploadAndSynchronise($image, $output);
}

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

return true;

} catch (\Exception $e) {
$this->migrationTask->stop();
throw $e;
Expand Down
2 changes: 2 additions & 0 deletions Model/Config/Backend/Credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public function beforeSave()
if (!$rawValue) {
throw new ValidatorException(__(self::CREDENTIALS_CHECK_MISSING));
}

if ($this->isSaveAllowed()) {
$this->validate($this->getCredentialsFromEnvironmentVariable($rawValue));
} else {
Expand Down Expand Up @@ -143,6 +144,7 @@ private function getCredentialsFromEnvironmentVariable($environmentVariable)
if (Cloudinary::config_get('private_cdn')) {
$credentials["private_cdn"] = Cloudinary::config_get('private_cdn');
}

return $credentials;
} catch (\Exception $e) {
throw new ValidatorException(__(self::CREDENTIALS_CHECK_FAILED));
Expand Down
2 changes: 0 additions & 2 deletions Model/Config/Backend/Free.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ public function __construct(
public function beforeSave()
{
if ($this->hasAccountConfigured() && $this->getValue()) {

$transform = $this->configuration
->getDefaultTransformation()
->withFreeform(Freeform::fromString($this->getValue()));

$this->validate($this->sampleImageUrl($transform));

}

parent::beforeSave();
Expand Down
12 changes: 6 additions & 6 deletions Model/Config/Source/Dropdown/Dpr.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class Dpr implements OptionSourceInterface
{
public function toOptionArray()
{
return array(
array(
return [
[
'value' => '1.0',
'label' => '1.0',
),
array(
],
[
'value' => '2.0',
'label' => '2.0',
),
);
],
];
}
}
1 change: 1 addition & 0 deletions Model/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ public function getEnvironmentVariable()
$this->logger->critical($invalidConfigException);
}
}

return $this->environmentVariable;
}

Expand Down
3 changes: 2 additions & 1 deletion Model/Observer/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public function execute(Observer $observer)
$this->changedPaths = (array) $observer->getEvent()->getChangedPaths();
if (count(
array_intersect(
$this->changedPaths, [
$this->changedPaths,
[
\Cloudinary\Cloudinary\Model\Configuration::CONFIG_PATH_ENABLED,
\Cloudinary\Cloudinary\Model\Configuration::CONFIG_PATH_ENVIRONMENT_VARIABLE,
\Cloudinary\Cloudinary\Model\AutoUploadMapping\AutoUploadConfiguration::REQUEST_PATH
Expand Down
3 changes: 2 additions & 1 deletion Model/ProductImageFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public function findDeletedImages(Product $product)
private function find(Product $product, ImageFilter $filter)
{
return array_map(
$this->imageCreator, array_filter(
$this->imageCreator,
array_filter(
$product->getMediaGallery('images') ?: [],
$filter
)
Expand Down
2 changes: 1 addition & 1 deletion Model/ProductImageFinder/DeletedImageFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ public function __invoke($imageData)
{
return isset($imageData['removed']) && $imageData['removed'] == 1;
}
}
}
1 change: 0 additions & 1 deletion Model/ProductImageFinder/ImageCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,3 @@ public function __invoke(array $imageData)
);
}
}

2 changes: 1 addition & 1 deletion Model/ProductImageFinder/ImageFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ interface ImageFilter
* @return boolean
*/
public function __invoke($imageData);
}
}
2 changes: 1 addition & 1 deletion Model/ProductImageFinder/NewImageFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public function __invoke($imageData)
{
return !empty($imageData['new_file']);
}
}
}
3 changes: 1 addition & 2 deletions Model/SynchronisationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
use Magento\Framework\Api\SearchResultsInterface;
use Magento\Framework\Api\SearchResultsInterfaceFactory;

class SynchronisationRepository
implements SynchronisationRepositoryInterface, SynchroniseAssetsRepositoryInterface
class SynchronisationRepository implements SynchronisationRepositoryInterface, SynchroniseAssetsRepositoryInterface
{
/**
* @var CollectionFactory
Expand Down
1 change: 1 addition & 0 deletions Model/Transformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function addFreeformTransformationForImage(ImageTransformation $transform
if (($this->getImageName() === $imageFile) && $this->hasFreeTransformation()) {
$transformation->withFreeform(Freeform::fromString($this->getFreeTransformation()));
}

return $transformation;
}

Expand Down
1 change: 1 addition & 0 deletions Plugin/Catalog/Block/Product/ImageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ private function createTransformation(array $imageMiscParams)
if (isset($imageMiscParams['keep_frame'])) {
$this->keepFrame = ($imageMiscParams['keep_frame'] === 'frame') ? true : false;
}

if ($this->keepFrame) {
$transform->withCrop(Crop::fromString('lpad'))
->withDimensions(Dimensions::squareMissingDimension($dimensions));
Expand Down
1 change: 1 addition & 0 deletions Plugin/Catalog/Model/Product/Image/UrlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ private function createTransformation(array $imageMiscParams)
if (isset($imageMiscParams['keep_frame'])) {
$this->keepFrame = ($imageMiscParams['keep_frame'] === 'frame') ? true : false;
}

if ($this->keepFrame) {
$transform->withCrop(Crop::fromString('lpad'))
->withDimensions(Dimensions::squareMissingDimension($dimensions));
Expand Down
1 change: 1 addition & 0 deletions Plugin/ImageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public function aroundGetUrl(CatalogImageHelper $helper, \Closure $originalMetho
if (!$this->configuration->isEnabled()) {
return $originalMethod();
}

$imagePath = $this->imageFile ?: $this->product->getData($helper->getType());

$image = $this->imageFactory->build(sprintf('catalog/product%s', $imagePath), $originalMethod);
Expand Down
2 changes: 2 additions & 0 deletions Plugin/Widget/Model/Template/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ public function aroundMediaDirective(\Magento\Widget\Model\Template\Filter $widg
if (!$this->_configuration->isEnabled()) {
return $proceed($construction);
}

$params = $this->_cloudinaryWidgetFilter->getParams($construction[2]);
if (!isset($params['url'])) {
return $proceed($construction);
}

$url = (preg_match('/^&quot;.+&quot;$/', $params['url'])) ? preg_replace('/(^&quot;)|(&quot;$)/', '', $params['url']) : $params['url'];

$image = $this->_imageFactory->build(
Expand Down
1 change: 1 addition & 0 deletions Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
if ($context->getVersion()) {
$this->output->writeln("<comment>Reseting configurations for 'website' & 'store' scopes (only supports 'default' at the moment)</comment>");
}

$this->resourceConnection->getConnection()->delete(
$this->resourceConnection->getTableName('core_config_data'),
"path LIKE 'cloudinary/%' AND scope != 'default'"
Expand Down
Loading