|
7 | 7 |
|
8 | 8 | namespace Magento\MediaGallery\Model\Asset\Command;
|
9 | 9 |
|
10 |
| -use Magento\MediaGalleryApi\Api\Data\AssetInterface; |
11 |
| -use Magento\MediaGalleryApi\Api\Data\AssetInterfaceFactory; |
12 |
| -use Magento\MediaGalleryApi\Model\Asset\Command\GetByIdInterface; |
13 | 10 | use Magento\Framework\App\ResourceConnection;
|
14 | 11 | use Magento\Framework\Exception\IntegrationException;
|
15 | 12 | use Magento\Framework\Exception\NoSuchEntityException;
|
| 13 | +use Magento\MediaGalleryApi\Api\Data\AssetInterface; |
| 14 | +use Magento\MediaGalleryApi\Api\Data\AssetInterfaceFactory; |
| 15 | +use Magento\MediaGalleryApi\Model\Asset\Command\GetByIdInterface; |
16 | 16 | use Psr\Log\LoggerInterface;
|
17 | 17 |
|
18 | 18 | /**
|
@@ -71,20 +71,29 @@ public function execute(int $mediaAssetId): AssetInterface
|
71 | 71 | $select = $connection->select()
|
72 | 72 | ->from(['amg' => $mediaAssetTable])
|
73 | 73 | ->where('amg.id = ?', $mediaAssetId);
|
74 |
| - $data = $connection->query($select)->fetch(); |
| 74 | + $mediaAssetData = $connection->query($select)->fetch(); |
| 75 | + } catch (\Exception $exception) { |
| 76 | + $message = __( |
| 77 | + 'En error occurred during get media asset data by id %id: %error', |
| 78 | + ['id' => $mediaAssetId, 'error' => $exception->getMessage()] |
| 79 | + ); |
| 80 | + $this->logger->critical($message); |
| 81 | + throw new IntegrationException($message, $exception); |
| 82 | + } |
75 | 83 |
|
76 |
| - if (empty($data)) { |
77 |
| - $message = __('There is no such media asset with id "%1"', $mediaAssetId); |
78 |
| - throw new NoSuchEntityException($message); |
79 |
| - } |
| 84 | + if (empty($mediaAssetData)) { |
| 85 | + $message = __('There is no such media asset with id "%1"', $mediaAssetId); |
| 86 | + throw new NoSuchEntityException($message); |
| 87 | + } |
80 | 88 |
|
81 |
| - return $this->assetFactory->create(['data' => $data]); |
| 89 | + try { |
| 90 | + return $this->assetFactory->create(['data' => $mediaAssetData]); |
82 | 91 | } catch (\Exception $exception) {
|
| 92 | + $this->logger->critical($exception->getMessage()); |
83 | 93 | $message = __(
|
84 |
| - 'En error occurred during get media asset with id %id: %error', |
| 94 | + 'En error occurred during initialize media asset with id %id: %error', |
85 | 95 | ['id' => $mediaAssetId, 'error' => $exception->getMessage()]
|
86 | 96 | );
|
87 |
| - $this->logger->critical($message); |
88 | 97 | throw new IntegrationException($message, $exception);
|
89 | 98 | }
|
90 | 99 | }
|
|
0 commit comments