Skip to content

Commit 71c6ed9

Browse files
committed
fix Used in entity is removed after and Image Preview has been Licensed
1 parent ca076e6 commit 71c6ed9

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

AdobeStockImage/Model/SaveImageFile.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\AdobeStockImage\Model;
99

10-
use Magento\AdobeStockImage\Model\Storage\Delete as StorageDelete;
1110
use Magento\AdobeStockImage\Model\Storage\Save as StorageSave;
1211
use Magento\Framework\Api\Search\Document;
1312
use Magento\Framework\Exception\CouldNotSaveException;
@@ -23,23 +22,15 @@ class SaveImageFile
2322
*/
2423
private $storageSave;
2524

26-
/**
27-
* @var StorageDelete
28-
*/
29-
private $storageDelete;
30-
3125
/**
3226
* SaveImageFile constructor.
3327
*
3428
* @param StorageSave $storageSave
35-
* @param StorageDelete $storageDelete
3629
*/
3730
public function __construct(
38-
StorageSave $storageSave,
39-
StorageDelete $storageDelete
31+
StorageSave $storageSave
4032
) {
4133
$this->storageSave = $storageSave;
42-
$this->storageDelete = $storageDelete;
4334
}
4435

4536
/**
@@ -55,12 +46,15 @@ public function __construct(
5546
public function execute(Document $document, string $url, string $destinationPath): void
5647
{
5748
try {
49+
$allowOverwrite = false;
5850
$pathAttribute = $document->getCustomAttribute('path');
5951
$pathValue = $pathAttribute->getValue();
60-
if (null !== $pathAttribute && $pathValue) {
61-
$this->storageDelete->execute($pathValue);
52+
53+
if (null !== $pathAttribute && $pathValue && $pathValue === $destinationPath) {
54+
$allowOverwrite = true;
6255
}
63-
$this->storageSave->execute($url, $destinationPath);
56+
57+
$this->storageSave->execute($url, $destinationPath, $allowOverwrite);
6458
} catch (LocalizedException $localizedException) {
6559
throw $localizedException;
6660
} catch (\Exception $exception) {

AdobeStockImage/Model/Storage/Save.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ public function __construct(
5959
*
6060
* @param string $imageUrl
6161
* @param string $destinationPath
62+
* @param bool $allowOverwrite
6263
* @throws AlreadyExistsException
6364
* @throws FileSystemException
6465
* @throws LocalizedException
6566
*/
66-
public function execute(string $imageUrl, string $destinationPath): void
67+
public function execute(string $imageUrl, string $destinationPath, bool $allowOverwrite =false): void
6768
{
6869
$mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
6970

@@ -75,7 +76,7 @@ public function execute(string $imageUrl, string $destinationPath): void
7576
throw new LocalizedException(__('Could not save image: unsupported file type.'));
7677
}
7778

78-
if ($mediaDirectory->isExist($destinationPath)) {
79+
if (!$allowOverwrite && $mediaDirectory->isExist($destinationPath)) {
7980
throw new AlreadyExistsException(__('Image with the same file name already exits.'));
8081
}
8182

0 commit comments

Comments
 (0)