Skip to content

Commit 3e4f056

Browse files
🔃 Update 2.1-master branch
Accepted Community Pull Requests:
2 parents 0b0b4aa + 4f5b531 commit 3e4f056

File tree

50 files changed

+218
-778
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+218
-778
lines changed

AdobeStockAdminUi/Controller/Adminhtml/System/Config/TestConnection.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
use Magento\AdobeStockClientApi\Api\ClientInterface;
1313
use Magento\Backend\App\Action;
1414
use Magento\Backend\App\Action\Context;
15-
use Magento\Framework\App\Action\HttpGetActionInterface;
16-
use Magento\Framework\Controller\Result\Json;
15+
use Magento\Framework\App\Action\HttpPostActionInterface;
1716
use Magento\Framework\Controller\Result\JsonFactory;
1817
use Magento\Framework\Controller\ResultInterface;
1918

2019
/**
2120
* Controller used for testing connection to Adobe Stock API from stores configuration
2221
*/
23-
class TestConnection extends Action implements HttpGetActionInterface
22+
class TestConnection extends Action implements HttpPostActionInterface
2423
{
2524
/**
2625
* Authorization level of a basic admin session.
@@ -74,7 +73,7 @@ public function __construct(
7473
*
7574
* @return ResultInterface
7675
*/
77-
public function execute() : ResultInterface
76+
public function execute(): ResultInterface
7877
{
7978
try {
8079
$params = $this->getRequest()->getParams();
@@ -89,8 +88,7 @@ public function execute() : ResultInterface
8988
$isConnectionEstablished = false;
9089
}
9190

92-
$resultJson = $this->resultJsonFactory->create();
93-
return $resultJson->setData(
91+
return $this->resultJsonFactory->create()->setData(
9492
[
9593
'success' => $isConnectionEstablished,
9694
'message' => $message->render(),

AdobeStockAdminUi/view/adminhtml/web/js/connection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ define([
7575
this.visible(false);
7676

7777
$.ajax({
78-
type: 'GET',
78+
type: 'POST',
7979
url: this.url,
8080
dataType: 'json',
8181
data: {

AdobeStockAsset/Model/GetAssetById.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ public function execute(int $adobeId): Document
6363

6464
$items = $this->getAssetList->execute($searchCriteria)->getItems();
6565
if (empty($items) || 1 < count($items)) {
66-
$message = __('Requested image doesn\'t exists');
67-
throw new NoSuchEntityException($message);
66+
throw new NoSuchEntityException(__('Requested asset does not exist.'));
6867
}
6968

7069
return reset($items);

AdobeStockAsset/Model/GetAssetList.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Magento\Framework\Api\Search\SearchResultInterface;
1515
use Magento\Framework\Exception\AuthenticationException;
1616
use Magento\Framework\Exception\LocalizedException;
17-
use Magento\Framework\UrlInterface;
1817
use Psr\Log\LoggerInterface;
1918

2019
/**
@@ -32,11 +31,6 @@ class GetAssetList implements GetAssetListInterface
3231
*/
3332
private $client;
3433

35-
/**
36-
* @var UrlInterface
37-
*/
38-
private $url;
39-
4034
/**
4135
* @var LoggerInterface
4236
*/
@@ -45,18 +39,15 @@ class GetAssetList implements GetAssetListInterface
4539
/**
4640
* GetAssetList constructor.
4741
* @param ClientInterface $client
48-
* @param UrlInterface $url
4942
* @param LoggerInterface $log
5043
* @param AppendAttributes $appendAttributes
5144
*/
5245
public function __construct(
5346
ClientInterface $client,
54-
UrlInterface $url,
5547
LoggerInterface $log,
5648
AppendAttributes $appendAttributes
5749
) {
5850
$this->client = $client;
59-
$this->url = $url;
6051
$this->log = $log;
6152
$this->appendAttributes = $appendAttributes;
6253
}
@@ -72,20 +63,7 @@ public function execute(SearchCriteriaInterface $searchCriteria): SearchResultIn
7263

7364
return $searchResult;
7465
} catch (AuthenticationException $exception) {
75-
throw new LocalizedException(
76-
__(
77-
'Failed to authenticate to Adobe Stock API. <br> Please correct the API credentials in '
78-
. '<a href="%1">Configuration → System → Adobe Stock Integration.</a>',
79-
$this->url->getUrl(
80-
'adminhtml/system_config/edit',
81-
[
82-
'section' => 'system',
83-
'_fragment' => 'system_adobe_stock_integration-link'
84-
]
85-
)
86-
),
87-
$exception
88-
);
66+
throw $exception;
8967
} catch (\Exception $exception) {
9068
$this->log->critical($exception);
9169
throw new LocalizedException(

AdobeStockClient/Model/ConnectionWrapper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ private function handleException(\Exception $exception, string $message): \Excep
132132
$this->flushUserTokens->execute();
133133
return new AuthorizationException(__('Adobe API login has expired!'));
134134
}
135+
if (strpos($exception->getMessage(), 'Could not validate the oauth token') !== false) {
136+
$this->flushUserTokens->execute();
137+
return new AuthorizationException(__('Adobe API login has expired!'));
138+
}
135139
$phrase = __(
136140
$message . ': %error_message',
137141
['error_message' => $exception->getMessage()]

AdobeStockImage/Model/GetRelatedImages.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\Api\FilterBuilder;
1414
use Magento\Framework\Api\Search\Document;
1515
use Magento\Framework\Api\Search\SearchCriteriaBuilder;
16+
use Magento\Framework\Exception\AuthenticationException;
1617
use Magento\Framework\Exception\LocalizedException;
1718
use Psr\Log\LoggerInterface;
1819

@@ -92,6 +93,8 @@ public function execute(int $imageId, int $limit): array
9293
);
9394
}
9495
return $relatedImageGroups;
96+
} catch (AuthenticationException $exception) {
97+
throw $exception;
9598
} catch (\Exception $exception) {
9699
$this->logger->critical($exception);
97100
throw new LocalizedException(

AdobeStockImage/Model/Storage/Delete.php

Lines changed: 0 additions & 60 deletions
This file was deleted.

AdobeStockImage/Test/Unit/Model/Storage/DeleteTest.php

Lines changed: 0 additions & 132 deletions
This file was deleted.

AdobeStockImage/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"magento/module-adobe-stock-asset-api": "*",
99
"magento/module-adobe-stock-image-api": "*",
1010
"magento/module-media-gallery-api": "*",
11-
"magento/module-media-gallery-synchronization-api": "*",
12-
"magento/module-cms": "*"
11+
"magento/module-media-gallery-synchronization-api": "*"
1312
},
1413
"suggest": {
1514
"magento/module-catalog": "*"

AdobeStockImageAdminUi/Controller/Adminhtml/Asset/GetMediaGalleryAsset.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\Controller\ResultFactory;
1414
use Psr\Log\LoggerInterface;
1515
use Magento\AdobeStockImageAdminUi\Model\Asset\GetMediaGalleryAssetByAdobeId;
16+
use Magento\Framework\Exception\NoSuchEntityException;
1617

1718
/**
1819
* Backend controller for retrieving asset information by adobeId
@@ -61,7 +62,6 @@ public function execute()
6162
{
6263
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
6364
try {
64-
6565
$params = $this->getRequest()->getParams();
6666
$adobeId = isset($params['adobe_id']) ? $params['adobe_id'] : null;
6767

@@ -78,6 +78,9 @@ public function execute()
7878

7979
$responseCode = self::HTTP_OK;
8080
$responseContent = $this->getAssetByAdobeId->execute((int) $adobeId);
81+
} catch (NoSuchEntityException $execption) {
82+
$responseCode = self::HTTP_OK;
83+
$responseContent = [];
8184
} catch (\Exception $exception) {
8285
$responseCode = self::HTTP_INTERNAL_ERROR;
8386
$this->logger->critical($exception);

0 commit comments

Comments
 (0)