Skip to content

Commit 1ab7fca

Browse files
committed
#27536: Moved xsd to api module, removed unit tests, updated comments
1 parent 93ce4b5 commit 1ab7fca

File tree

15 files changed

+36
-710
lines changed

15 files changed

+36
-710
lines changed

app/code/Magento/MediaContent/Model/AssignAssets.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public function execute(ContentIdentityInterface $contentIdentity, array $assetI
6565
} catch (\Exception $exception) {
6666
$this->logger->critical($exception);
6767
throw new CouldNotSaveException(
68-
__('An error occurred while saving relation between media asset and media content.')
68+
__('An error occurred while saving relation between media asset and media content.'),
69+
$exception
6970
);
7071
}
7172
}

app/code/Magento/MediaContent/Model/Content/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Framework\Config\DataInterface;
1111

1212
/**
13-
* Media content config
13+
* Media content configuration
1414
*/
1515
class Config
1616
{

app/code/Magento/MediaContent/Model/Content/Config/Converter.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,12 @@
1010
use Magento\Framework\Config\ConverterInterface;
1111

1212
/**
13-
* Class Converter
13+
* Media Content configuration Converter
1414
*/
1515
class Converter implements ConverterInterface
1616
{
17-
/**
18-
* Search tag name
19-
*/
2017
private const SEARCH_TAG_NAME = 'search';
21-
22-
/**
23-
* Patterns tag name
24-
*/
2518
private const PATTERNS_TAG_NAME = 'patterns';
26-
27-
/**
28-
* Pattern tag name
29-
*/
3019
private const PATTERN_TAG_NAME = 'pattern';
3120

3221
/**
@@ -43,9 +32,9 @@ public function convert($source) : array
4332
return $result;
4433
}
4534

46-
foreach ($source->getElementsByTagName(self::SEARCH_TAG_NAME) as $blacklist) {
35+
foreach ($source->getElementsByTagName(self::SEARCH_TAG_NAME) as $search) {
4736
$result[self::SEARCH_TAG_NAME] = [];
48-
foreach ($blacklist->getElementsByTagName(self::PATTERNS_TAG_NAME) as $patterns) {
37+
foreach ($search->getElementsByTagName(self::PATTERNS_TAG_NAME) as $patterns) {
4938
$result[self::SEARCH_TAG_NAME][self::PATTERNS_TAG_NAME] = [];
5039
foreach ($patterns->getElementsByTagName(self::PATTERN_TAG_NAME) as $pattern) {
5140
$result[self::SEARCH_TAG_NAME][self::PATTERNS_TAG_NAME]
@@ -56,4 +45,4 @@ public function convert($source) : array
5645

5746
return $result;
5847
}
59-
}
48+
}

app/code/Magento/MediaContent/Model/Content/Config/SchemaLocator.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use Magento\Framework\Module\Dir;
1212
use Magento\Framework\Module\Dir\Reader;
1313

14+
/**
15+
* Media Content configuration schema locator
16+
*/
1417
class SchemaLocator implements SchemaLocatorInterface
1518
{
1619
/**
@@ -25,7 +28,8 @@ class SchemaLocator implements SchemaLocatorInterface
2528
*/
2629
public function __construct(Reader $moduleReader)
2730
{
28-
$this->schema = $moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_MediaContent') . '/media_content.xsd';
31+
$this->schema = $moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_MediaContentApi')
32+
. '/media_content.xsd';
2933
}
3034

3135
/**
@@ -47,4 +51,4 @@ public function getPerFileSchema()
4751
{
4852
return $this->schema;
4953
}
50-
}
54+
}

app/code/Magento/MediaContent/Model/ExtractAssetsFromContent.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
class ExtractAssetsFromContent implements ExtractAssetsFromContentInterface
2020
{
21+
private const XML_PATH_SEARCH_PATTERNS = 'search/patterns';
22+
2123
/**
2224
* @var Config
2325
*/
@@ -49,16 +51,13 @@ public function __construct(
4951
}
5052

5153
/**
52-
* Search for the media asset in content and extract it providing a list of media assets.
53-
*
54-
* @param string $content
55-
* @return AssetInterface[]
54+
* @inheritdoc
5655
*/
5756
public function execute(string $content): array
5857
{
5958
$paths = [];
6059

61-
foreach ($this->config->get('search/patterns') as $pattern) {
60+
foreach ($this->config->get(self::XML_PATH_SEARCH_PATTERNS) as $pattern) {
6261
if (empty($pattern)) {
6362
continue;
6463
}
@@ -86,7 +85,7 @@ private function getAssetsByPaths(array $paths): array
8685
foreach ($paths as $path) {
8786
try {
8887
/** @var AssetInterface $asset */
89-
$asset = $this->getMediaAssetByPath->execute('/' . $path);
88+
$asset = $this->getMediaAssetByPath->execute($this->getPathStartingWithSlash($path));
9089
$assets[$asset->getId()] = $asset;
9190
} catch (\Exception $exception) {
9291
$this->logger->critical($exception);
@@ -95,4 +94,15 @@ private function getAssetsByPaths(array $paths): array
9594

9695
return $assets;
9796
}
97+
98+
/**
99+
* Ensure the extracted paths matches the standard format
100+
*
101+
* @param string $path
102+
* @return string
103+
*/
104+
private function getPathStartingWithSlash(string $path): string
105+
{
106+
return '/' . ltrim($path, '/');
107+
}
98108
}

app/code/Magento/MediaContent/Model/GetContentWithAssets.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct(
5555
}
5656

5757
/**
58-
* @inheritDoc
58+
* @inheritdoc
5959
*/
6060
public function execute(array $assetIds): array
6161
{

app/code/Magento/MediaContent/Model/UnassignAssets.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ class UnassignAssets implements UnassignAssetsInterface
3535
private $logger;
3636

3737
/**
38-
* GetAssetsUsedInContent constructor.
39-
*
4038
* @param ResourceConnection $resourceConnection
4139
* @param LoggerInterface $logger
4240
*/
@@ -66,7 +64,8 @@ public function execute(ContentIdentityInterface $contentIdentity, array $assetI
6664
} catch (\Exception $exception) {
6765
$this->logger->critical($exception);
6866
throw new CouldNotDeleteException(
69-
__('An error occurred at unassign relation between the media asset and media content.')
67+
__('An error occurred at unassign relation between the media asset and media content.'),
68+
$exception
7069
);
7170
}
7271
}

app/code/Magento/MediaContent/Model/UpdateRelations.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ public function __construct(
7171
}
7272

7373
/**
74-
* Create new relation between media asset and content or updated existing
75-
*
76-
* @param ContentIdentityInterface $contentIdentity
77-
* @param string $data
74+
* @inheritdoc
7875
*/
7976
public function execute(ContentIdentityInterface $contentIdentity, string $data): void
8077
{
@@ -86,7 +83,7 @@ public function execute(ContentIdentityInterface $contentIdentity, string $data)
8683
}
8784

8885
/**
89-
* Records a relation for the newly added asset
86+
* Find out which relations are obsolete and which are new and update them
9087
*
9188
* @param ContentIdentityInterface $contentIdentity
9289
* @param string $data

app/code/Magento/MediaContent/Test/Unit/Model/AssignAssetsTest.php

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

0 commit comments

Comments
 (0)