Skip to content

Commit ee0e387

Browse files
authored
Merge branch '2.0-develop' into 1688-saved-image-from-adobe-stock-is-selected-highlighted-but-the-add-selected-button-is-not-displayed
2 parents c8b7d55 + 83eef83 commit ee0e387

File tree

497 files changed

+75
-25510
lines changed

Some content is hidden

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

497 files changed

+75
-25510
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

AdobeStockImage/Test/Unit/Model/SaveImageFileTest.php

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace Magento\AdobeStockImage\Test\Unit\Model;
99

1010
use Magento\AdobeStockImage\Model\SaveImageFile;
11-
use Magento\AdobeStockImage\Model\Storage\Delete as StorageDelete;
1211
use Magento\AdobeStockImage\Model\Storage\Save as StorageSave;
1312
use Magento\Framework\Api\AttributeInterface;
1413
use Magento\Framework\Api\Search\Document;
@@ -27,11 +26,6 @@ class SaveImageFileTest extends TestCase
2726
*/
2827
private $storageSave;
2928

30-
/**
31-
* @var MockObject|StorageDelete
32-
*/
33-
private $storageDelete;
34-
3529
/**
3630
* @var SaveImageFile
3731
*/
@@ -43,13 +37,11 @@ class SaveImageFileTest extends TestCase
4337
protected function setUp(): void
4438
{
4539
$this->storageSave = $this->createMock(StorageSave::class);
46-
$this->storageDelete = $this->createMock(StorageDelete::class);
4740

4841
$this->saveImageFile = (new ObjectManager($this))->getObject(
4942
SaveImageFile::class,
5043
[
51-
'storageSave' => $this->storageSave,
52-
'storageDelete' => $this->storageDelete
44+
'storageSave' => $this->storageSave
5345
]
5446
);
5547
}
@@ -60,18 +52,12 @@ protected function setUp(): void
6052
* @param Document $document
6153
* @param string $url
6254
* @param string $destinationPath
63-
* @param bool $delete
6455
* @dataProvider assetProvider
6556
*/
66-
public function testExecute(Document $document, string $url, string $destinationPath, bool $delete): void
57+
public function testExecute(Document $document, string $url, string $destinationPath): void
6758
{
68-
if ($delete) {
69-
$this->storageDelete->expects($this->once())
70-
->method('execute');
71-
} else {
72-
$this->storageSave->expects($this->once())
73-
->method('execute');
74-
}
59+
$this->storageSave->expects($this->once())
60+
->method('execute');
7561

7662
$this->storageSave->expects($this->once())
7763
->method('execute')
@@ -86,24 +72,16 @@ public function testExecute(Document $document, string $url, string $destination
8672
* @param Document $document
8773
* @param string $url
8874
* @param string $destinationPath
89-
* @param bool $delete
9075
* @dataProvider assetProvider
9176
*/
9277
public function testExecuteWithException(
9378
Document $document,
9479
string $url,
95-
string $destinationPath,
96-
bool $delete
80+
string $destinationPath
9781
): void {
98-
if ($delete) {
99-
$this->storageDelete->expects($this->once())
100-
->method('execute')
101-
->willThrowException(new \Exception('Some Exception'));
102-
} else {
103-
$this->storageSave->expects($this->once())
104-
->method('execute')
105-
->willThrowException(new \Exception('Some Exception'));
106-
}
82+
$this->storageSave->expects($this->once())
83+
->method('execute')
84+
->willThrowException(new \Exception('Some Exception'));
10785

10886
$this->expectException(CouldNotSaveException::class);
10987

@@ -121,14 +99,12 @@ public function assetProvider(): array
12199
[
122100
'document' => $this->getDocument(),
123101
'url' => 'https://as2.ftcdn.net/jpg/500_FemVonDcttCeKiOXFk.jpg',
124-
'destinationPath' => 'path',
125-
'delete' => false
102+
'destinationPath' => 'path'
126103
],
127104
[
128105
'document' => $this->getDocument('filepath.jpg'),
129106
'url' => 'https://as2.ftcdn.net/jpg/500_FemVonDcttCeKiOXFk.jpg',
130107
'destinationPath' => 'path',
131-
'delete' => true
132108
],
133109
];
134110
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\AdobeStockImageAdminUi\Plugin;
10+
11+
use Magento\MediaGalleryUi\Ui\Component\Listing\Columns\Source\Options;
12+
13+
/**
14+
* Plugin which adds an Adobe Stock option to surce filter in media gallery
15+
*/
16+
class AddAdobeStockSourceOptionPlugin
17+
{
18+
/**
19+
* Add Adobe Stock source option
20+
*
21+
* @param Options $subject
22+
* @param array $options
23+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
24+
*/
25+
public function aftertoOptionArray(Options $subject, array $options): array
26+
{
27+
$options[] = [
28+
'value' => 'Adobe Stock',
29+
'label' => __('Adobe Stock'),
30+
];
31+
32+
return $options;
33+
}
34+
}

AdobeStockImageAdminUi/Ui/Component/Listing/Columns/Source/Options.php

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

AdobeStockImageAdminUi/etc/adminhtml/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<type name="Magento\MediaGalleryUi\Model\GetDetailsByAssetId">
1313
<plugin name="add_adobe_stock_image_details_plugin" type="Magento\AdobeStockImageAdminUi\Plugin\AddAdobeStockImageDetailsPlugin"/>
1414
</type>
15+
<type name="Magento\MediaGalleryUi\Ui\Component\Listing\Columns\Source\Options">
16+
<plugin name="add_adobe_stock_source_option_plugin" type="Magento\AdobeStockImageAdminUi\Plugin\AddAdobeStockSourceOptionPlugin"/>
17+
</type>
1518
<type name="Magento\MediaGalleryUi\Ui\Component\Listing\Columns\SourceIconProvider">
1619
<arguments>
1720
<argument name="sourceIcons" xsi:type="array">
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<csp_whitelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Csp:etc/csp_whitelist.xsd">
10+
<policies>
11+
<policy id="img-src">
12+
<values>
13+
<value id="adobe_stock_cdn" type="host">*.ftcdn.net</value>
14+
<value id="jquery_image_load_placeholder" type="host">data:</value>
15+
</values>
16+
</policy>
17+
</policies>
18+
</csp_whitelist>

AdobeStockImageAdminUi/view/adminhtml/ui_component/media_gallery_listing.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@
2222
<dataScope>is_licensed</dataScope>
2323
</settings>
2424
</filterSelect>
25-
<filterSelect name="source" provider="${ $.parentName }" sortOrder="30">
26-
<settings>
27-
<caption translate="true">All</caption>
28-
<options class="Magento\AdobeStockImageAdminUi\Ui\Component\Listing\Columns\Source\Options"/>
29-
<label translate="true">Source</label>
30-
<dataScope>source</dataScope>
31-
</settings>
32-
</filterSelect>
3325
</filters>
3426
</listingToolbar>
3527
<columns name="media_gallery_columns">

AdobeStockImageAdminUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@
2222
<dataScope>is_licensed</dataScope>
2323
</settings>
2424
</filterSelect>
25-
<filterSelect name="source" provider="${ $.parentName }" sortOrder="30">
26-
<settings>
27-
<caption translate="true">All</caption>
28-
<options class="Magento\AdobeStockImageAdminUi\Ui\Component\Listing\Columns\Source\Options"/>
29-
<label translate="true">Source</label>
30-
<dataScope>source</dataScope>
31-
</settings>
32-
</filterSelect>
3325
</filters>
3426
</listingToolbar>
3527
<columns name="media_gallery_columns">

MediaContentSynchronization/Console/Command/Synchronize.php

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

0 commit comments

Comments
 (0)