77
88namespace Magento \AdobeStockImage \Model ;
99
10- use Magento \AdobeStockImage \Model \Storage \Delete as StorageDelete ;
1110use Magento \AdobeStockImage \Model \Storage \Save as StorageSave ;
1211use Magento \Framework \Api \Search \Document ;
1312use 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 ) {
0 commit comments