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
17 changes: 12 additions & 5 deletions Core/AutoUploadMapping/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class ApiClient
const FOLDER_KEY = 'folder';
const URL_KEY = 'template';

/**
* @var bool
*/
private $_authorised;

/**
* @var ConfigurationInterface
*/
Expand Down Expand Up @@ -43,9 +48,6 @@ public function __construct(
$this->configuration = $configuration;
$this->configurationBuilder = $configurationBuilder;
$this->api = $api;
if ($this->configuration->isEnabled()) {
$this->authorise();
}
}

/**
Expand All @@ -54,6 +56,7 @@ public function __construct(
*/
public static function fromConfiguration(ConfigurationInterface $configuration)
{
$this->authorise();
return new ApiClient(
$configuration,
new ConfigurationBuilder($configuration),
Expand All @@ -69,6 +72,7 @@ public static function fromConfiguration(ConfigurationInterface $configuration)
public function prepareMapping($folder, $url)
{
try {
$this->authorise();
$existingMappings = $this->parseFetchMappingsResponse($this->api->upload_mappings());

if ($this->hasMapping($existingMappings, $folder)) {
Expand Down Expand Up @@ -145,8 +149,11 @@ function (array $mapping) use ($url) {

private function authorise()
{
Cloudinary::config($this->configurationBuilder->build());
Cloudinary::$USER_PLATFORM = $this->configuration->getUserPlatform();
if (!$this->_authorised && $configuration->isEnabled()) {
Cloudinary::config($this->configurationBuilder->build());
Cloudinary::$USER_PLATFORM = $this->configuration->getUserPlatform();
$this->_authorised = true;
}
}

/**
Expand Down
21 changes: 16 additions & 5 deletions Core/CloudinaryImageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

class CloudinaryImageProvider implements ImageProvider
{
/**
* @var bool
*/
private $_authorised;

/**
* @var ConfigurationInterface
*/
Expand Down Expand Up @@ -37,9 +42,6 @@ public function __construct(
$this->configuration = $configuration;
$this->uploadResponseValidator = $uploadResponseValidator;
$this->configurationBuilder = $configurationBuilder;
if ($configuration->isEnabled()) {
$this->authorise();
}
}

/**
Expand All @@ -48,6 +50,7 @@ public function __construct(
*/
public static function fromConfiguration(ConfigurationInterface $configuration)
{
$this->authorise();
return new CloudinaryImageProvider(
$configuration,
new ConfigurationBuilder($configuration),
Expand All @@ -61,6 +64,7 @@ public static function fromConfiguration(ConfigurationInterface $configuration)
*/
public function upload(Image $image)
{
$this->authorise();
if (!$this->configuration->isEnabled()) {
return false;
}
Expand All @@ -83,6 +87,7 @@ public function upload(Image $image)
*/
public function retrieveTransformed(Image $image, Transformation $transformation)
{
$this->authorise();
$imagePath = \cloudinary_url(
$image->getId(),
[
Expand Down Expand Up @@ -114,6 +119,7 @@ public function retrieveTransformed(Image $image, Transformation $transformation
*/
public function retrieve(Image $image)
{
$this->authorise();
return $this->retrieveTransformed($image, $this->configuration->getDefaultTransformation());
}

Expand All @@ -123,6 +129,7 @@ public function retrieve(Image $image)
*/
public function delete(Image $image)
{
$this->authorise();
if ($this->configuration->isEnabled()) {
Uploader::destroy($image->getIdWithoutExtension());
}
Expand All @@ -134,6 +141,7 @@ public function delete(Image $image)
public function validateCredentials()
{
try {
$this->authorise();
$pingValidation = $this->api->ping();
if (!(isset($pingValidation["status"]) && $pingValidation["status"] === "ok")) {
return false;
Expand All @@ -148,7 +156,10 @@ public function validateCredentials()

private function authorise()
{
Cloudinary::config($this->configurationBuilder->build());
Cloudinary::$USER_PLATFORM = $this->configuration->getUserPlatform();
if (!$this->_authorised && $configuration->isEnabled()) {
Cloudinary::config($this->configurationBuilder->build());
Cloudinary::$USER_PLATFORM = $this->configuration->getUserPlatform();
$this->_authorised = true;
}
}
}
2 changes: 1 addition & 1 deletion 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.2', '2.0.0');
return sprintf(self::USER_PLATFORM_TEMPLATE, '1.9.3', '2.0.0');
}

/**
Expand Down
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.2",
"version": "1.9.3",
"license": "MIT",
"require": {
"cloudinary/cloudinary_php": "*"
Expand Down
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.2">
<module name="Cloudinary_Cloudinary" setup_version="1.9.3">
<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.2",
"version": "1.9.3",
"description": "Cloudinary Magento 2 Integration.",
"license": "MIT",
"require": {
Expand Down