Skip to content

Commit fa92f2a

Browse files
authored
Merge pull request #6105 from magento-engcom/asi-bugfix-3
[Magento Community Engineering] 2.4.1 Adobe Stock Integration bugfixes
2 parents 1d47699 + fff396a commit fa92f2a

File tree

20 files changed

+287
-202
lines changed

20 files changed

+287
-202
lines changed

app/code/Magento/Cms/Block/Adminhtml/Wysiwyg/Images/Content.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ protected function _construct()
102102
'type' => 'button'
103103
],
104104
0,
105-
0,
105+
100,
106106
'header'
107107
);
108108
}

app/code/Magento/MediaContentSynchronization/Console/Command/Synchronize.php

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

88
namespace Magento\MediaContentSynchronization\Console\Command;
99

10-
use Magento\Framework\App\Area;
11-
use Magento\Framework\App\State;
1210
use Magento\Framework\Console\Cli;
1311
use Magento\MediaContentSynchronizationApi\Api\SynchronizeInterface;
1412
use Symfony\Component\Console\Command\Command;
@@ -25,21 +23,13 @@ class Synchronize extends Command
2523
*/
2624
private $synchronizeContent;
2725

28-
/**
29-
* @var State $state
30-
*/
31-
private $state;
32-
3326
/**
3427
* @param SynchronizeInterface $synchronizeContent
35-
* @param State $state
3628
*/
3729
public function __construct(
38-
SynchronizeInterface $synchronizeContent,
39-
State $state
30+
SynchronizeInterface $synchronizeContent
4031
) {
4132
$this->synchronizeContent = $synchronizeContent;
42-
$this->state = $state;
4333
parent::__construct();
4434
}
4535

@@ -58,12 +48,7 @@ protected function configure()
5848
protected function execute(InputInterface $input, OutputInterface $output)
5949
{
6050
$output->writeln('Synchronizing content with assets...');
61-
$this->state->emulateAreaCode(
62-
Area::AREA_ADMINHTML,
63-
function () {
64-
$this->synchronizeContent->execute();
65-
}
66-
);
51+
$this->synchronizeContent->execute();
6752
$output->writeln('Completed content synchronization.');
6853
return Cli::RETURN_SUCCESS;
6954
}

app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function execute(array $paths): void
7878
if (!empty($failedPaths)) {
7979
throw new CouldNotSaveException(
8080
__(
81-
'Could not save directories: %paths',
81+
'Could not create directories: %paths',
8282
[
8383
'paths' => implode(' ,', $failedPaths)
8484
]

app/code/Magento/MediaGallery/Model/ResourceModel/Keyword/SaveAssetLinks.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private function deleteAssetKeywords(int $assetId, array $obsoleteKeywordIds): v
133133
/** @var Mysql $connection */
134134
$connection = $this->resourceConnection->getConnection();
135135
$connection->delete(
136-
$connection->getTableName(
136+
$this->resourceConnection->getTableName(
137137
self::TABLE_ASSET_KEYWORD
138138
),
139139
[
@@ -196,7 +196,7 @@ private function setAssetUpdatedAt(int $assetId): void
196196
try {
197197
$connection = $this->resourceConnection->getConnection();
198198
$connection->update(
199-
$connection->getTableName(self::TABLE_MEDIA_ASSET),
199+
$this->resourceConnection->getTableName(self::TABLE_MEDIA_ASSET),
200200
['updated_at' => null],
201201
['id =?' => $assetId]
202202
);

app/code/Magento/MediaGallery/Test/Unit/Model/ResourceModel/Keyword/SaveAssetLinksTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,14 @@ public function testAssetKeywordsSave(int $assetId, array $keywordIds, array $va
7878
$this->resourceConnectionMock->expects($this->exactly(2))
7979
->method('getConnection')
8080
->willReturn($this->connectionMock);
81-
$this->resourceConnectionMock->expects($this->once())
81+
$this->resourceConnectionMock->expects($this->any())
8282
->method('getTableName')
83-
->with('media_gallery_asset_keyword')
84-
->willReturn('prefix_media_gallery_asset_keyword');
83+
->willReturnMap(
84+
[
85+
['media_gallery_asset_keyword', 'default', 'prefix_media_gallery_asset_keyword'],
86+
['media_gallery_asset', 'default', 'prefix_media_gallery_asset']
87+
]
88+
);
8589
$this->connectionMock->expects($this->once())
8690
->method('insertArray')
8791
->with(

app/code/Magento/MediaGalleryUi/Controller/Adminhtml/Directories/GetTree.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Framework\App\Action\HttpGetActionInterface;
1212
use Magento\Framework\Controller\Result\Json;
1313
use Magento\Framework\Controller\ResultFactory;
14-
use Magento\MediaGalleryUi\Model\Directories\GetFolderTree;
14+
use Magento\MediaGalleryUi\Model\Directories\GetDirectoryTree;
1515
use Psr\Log\LoggerInterface;
1616

1717
/**
@@ -33,33 +33,35 @@ class GetTree extends Action implements HttpGetActionInterface
3333
private $logger;
3434

3535
/**
36-
* @var GetFolderTree
36+
* @var GetDirectoryTree
3737
*/
38-
private $getFolderTree;
38+
private $getDirectoryTree;
3939

4040
/**
4141
* Constructor
4242
*
4343
* @param Action\Context $context
4444
* @param LoggerInterface $logger
45-
* @param GetFolderTree $getFolderTree
45+
* @param GetDirectoryTree $getDirectoryTree
4646
*/
4747
public function __construct(
4848
Action\Context $context,
4949
LoggerInterface $logger,
50-
GetFolderTree $getFolderTree
50+
GetDirectoryTree $getDirectoryTree
5151
) {
5252
parent::__construct($context);
5353
$this->logger = $logger;
54-
$this->getFolderTree = $getFolderTree;
54+
$this->getDirectoryTree = $getDirectoryTree;
5555
}
5656
/**
5757
* @inheritdoc
5858
*/
5959
public function execute()
6060
{
6161
try {
62-
$responseContent[] = $this->getFolderTree->execute();
62+
$responseContent = [
63+
$this->getDirectoryTree->execute()
64+
];
6365
$responseCode = self::HTTP_OK;
6466
} catch (\Exception $exception) {
6567
$this->logger->critical($exception);

app/code/Magento/MediaGalleryUi/Model/Directories/GetFolderTree.php renamed to app/code/Magento/MediaGalleryUi/Model/Directories/GetDirectoryTree.php

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,58 +7,61 @@
77

88
namespace Magento\MediaGalleryUi\Model\Directories;
99

10+
use Magento\Framework\App\Filesystem\DirectoryList;
1011
use Magento\Framework\Exception\ValidatorException;
1112
use Magento\Framework\Filesystem;
1213
use Magento\Framework\Filesystem\Directory\Read;
1314
use Magento\MediaGalleryApi\Api\IsPathExcludedInterface;
1415

1516
/**
16-
* Build folder tree structure by path
17+
* Build media gallery folder tree structure by path
1718
*/
18-
class GetFolderTree
19+
class GetDirectoryTree
1920
{
2021
/**
2122
* @var Filesystem
2223
*/
2324
private $filesystem;
2425

25-
/**
26-
* @var string
27-
*/
28-
private $path;
29-
3026
/**
3127
* @var IsPathExcludedInterface
3228
*/
3329
private $isPathExcluded;
3430

3531
/**
36-
* Constructor
37-
*
3832
* @param Filesystem $filesystem
39-
* @param string $path
4033
* @param IsPathExcludedInterface $isPathExcluded
4134
*/
4235
public function __construct(
4336
Filesystem $filesystem,
44-
string $path,
4537
IsPathExcludedInterface $isPathExcluded
4638
) {
4739
$this->filesystem = $filesystem;
48-
$this->path = $path;
4940
$this->isPathExcluded = $isPathExcluded;
5041
}
5142

5243
/**
5344
* Return directory folder structure in array
5445
*
55-
* @param bool $skipRoot
5646
* @return array
5747
* @throws ValidatorException
5848
*/
59-
public function execute(bool $skipRoot = true): array
49+
public function execute(): array
6050
{
61-
return $this->buildFolderTree($this->getDirectories(), $skipRoot);
51+
$tree = [
52+
'name' => 'root',
53+
'path' => '/',
54+
'children' => []
55+
];
56+
$directories = $this->getDirectories();
57+
foreach ($directories as $idx => &$node) {
58+
$node['children'] = [];
59+
$result = $this->findParent($node, $tree);
60+
$parent = &$result['treeNode'];
61+
62+
$parent['children'][] = &$directories[$idx];
63+
}
64+
return $tree['children'];
6265
}
6366

6467
/**
@@ -72,7 +75,7 @@ private function getDirectories(): array
7275
$directories = [];
7376

7477
/** @var Read $directory */
75-
$directory = $this->filesystem->getDirectoryRead($this->path);
78+
$directory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
7679

7780
if (!$directory->isDirectory()) {
7881
return $directories;
@@ -96,30 +99,6 @@ private function getDirectories(): array
9699
return $directories;
97100
}
98101

99-
/**
100-
* Build folder tree structure by provided directories path
101-
*
102-
* @param array $directories
103-
* @param bool $skipRoot
104-
* @return array
105-
*/
106-
private function buildFolderTree(array $directories, bool $skipRoot): array
107-
{
108-
$tree = [
109-
'name' => 'root',
110-
'path' => '/',
111-
'children' => []
112-
];
113-
foreach ($directories as $idx => &$node) {
114-
$node['children'] = [];
115-
$result = $this->findParent($node, $tree);
116-
$parent = & $result['treeNode'];
117-
118-
$parent['children'][] =& $directories[$idx];
119-
}
120-
return $skipRoot ? $tree['children'] : $tree;
121-
}
122-
123102
/**
124103
* Find parent directory
125104
*
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AssertFolderIsChangedActionGroup">
12+
<annotations>
13+
<description>Assert that folder is changed</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="newSelectedFolder" type="string"/>
17+
<argument name="oldSelectedFolder" type="string" defaultValue="{{AdminMediaGalleryFolderData.name}}"/>
18+
</arguments>
19+
20+
<assertNotEquals stepKey="assertNotEqual">
21+
<actualResult type="string">{{newSelectedFolder}}</actualResult>
22+
<expectedResult type="string">{{oldSelectedFolder}}</expectedResult>
23+
</assertNotEquals>
24+
</actionGroup>
25+
</actionGroups>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminMediaGallerySwitchingBetweenViewsTest">
11+
<annotations>
12+
<features value="MediaGallery"/>
13+
<useCaseId value="https://github.com/magento/adobe-stock-integration/issues/1523"/>
14+
<title value="User switches between Views and checks if the folder is changed"/>
15+
<stories value="User switches between Views and checks if the folder is changed"/>
16+
<testCaseId value="https://studio.cucumber.io/projects/131313/test-plan/folders/1337102/scenarios/5060037"/>
17+
<description value="User switches between Views and checks if the folder is changed"/>
18+
<severity value="CRITICAL"/>
19+
<group value="media_gallery_ui"/>
20+
</annotations>
21+
<before>
22+
<createData entity="SimpleSubCategory" stepKey="category"/>
23+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
24+
</before>
25+
<after>
26+
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetAdminDataGridToDefaultView"/>
27+
<actionGroup ref="AdminEnhancedMediaGalleryDeleteGridViewActionGroup" stepKey="deleteView">
28+
<argument name="viewToDelete" value="New View"/>
29+
</actionGroup>
30+
<actionGroup ref="AdminMediaGalleryFolderSelectActionGroup" stepKey="selectFolderForDelete"/>
31+
<actionGroup ref="AdminMediaGalleryFolderDeleteActionGroup" stepKey="deleteFolder"/>
32+
<actionGroup ref="AdminMediaGalleryAssertFolderDoesNotExistActionGroup" stepKey="assertFolderWasDeleted"/>
33+
<deleteData createDataKey="category" stepKey="deleteCategory"/>
34+
</after>
35+
<actionGroup ref="AdminOpenCreateNewCMSPageActionGroup" stepKey="openNewPage"/>
36+
<actionGroup ref="AdminOpenMediaGalleryFromPageNoEditorActionGroup" stepKey="openMediaGalleryForPage"/>
37+
<actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearFilters"/>
38+
<actionGroup ref="AdminMediaGalleryOpenNewFolderFormActionGroup" stepKey="openNewFolderForm"/>
39+
<actionGroup ref="AdminMediaGalleryCreateNewFolderActionGroup" stepKey="createNewFolder"/>
40+
<actionGroup ref="AdminMediaGalleryAssertFolderNameActionGroup" stepKey="assertNewFolderCreated"/>
41+
<waitForLoadingMaskToDisappear stepKey="waitForFolderContents"/>
42+
<actionGroup ref="AdminEnhancedMediaGallerySaveCustomViewActionGroup" stepKey="saveCustomView">
43+
<argument name="viewName" value="New View"/>
44+
</actionGroup>
45+
<actionGroup ref="AdminOpenCategoryPageActionGroup" stepKey="openCategoryPage"/>
46+
<actionGroup ref="AdminCategoriesOpenCategoryActionGroup" stepKey="openCategory">
47+
<argument name="category" value="$$category$$"/>
48+
</actionGroup>
49+
<actionGroup ref="AdminOpenMediaGalleryFromCategoryImageUploaderActionGroup" stepKey="openMediaGalleryFromImageUploader"/>
50+
<actionGroup ref="AdminEnhancedMediaGallerySelectCustomBookmarksViewActionGroup" stepKey="selectDefaultView">
51+
<argument name="selectView" value="Default View"/>
52+
</actionGroup>
53+
<actionGroup ref="AssertFolderIsChangedActionGroup" stepKey="assertFolderIsChanged">
54+
<argument name="newSelectedFolder" value="category" />
55+
</actionGroup>
56+
<actionGroup ref="AdminEnhancedMediaGallerySelectCustomBookmarksViewActionGroup" stepKey="switchBackToNewView">
57+
<argument name="selectView" value="New View"/>
58+
</actionGroup>
59+
<actionGroup ref="AdminEnhancedMediaGalleryAssertActiveFiltersActionGroup" stepKey="assertFilterApplied">
60+
<argument name="resultValue" value="{{AdminMediaGalleryFolderData.name}}"/>
61+
</actionGroup>
62+
</test>
63+
</tests>

app/code/Magento/MediaGalleryUi/Test/Mftf/Test/AdminMediaGalleryUploadCategoryImageTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<actionGroup ref="AddCategoryImageActionGroup" stepKey="addCategoryImage"/>
3737
<actionGroup ref="AdminSaveCategoryFormActionGroup" stepKey="saveCategoryForm"/>
3838
<actionGroup ref="AdminOpenMediaGalleryFromCategoryImageUploaderActionGroup" stepKey="openMediaGalleryFromImageUploader"/>
39+
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetAdminDataGridToDefaultView"/>
3940
<actionGroup ref="AdminMediaGalleryAssertImageInGridActionGroup" stepKey="assertImageInGrid">
4041
<argument name="title" value="ProductImage.filename"/>
4142
</actionGroup>

0 commit comments

Comments
 (0)