Skip to content

Commit 28717cf

Browse files
committed
Services convered with integration tests
1 parent 5d9d688 commit 28717cf

File tree

11 files changed

+122
-21
lines changed

11 files changed

+122
-21
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class AssignAssets implements AssignAssetsInterface
2020
{
2121
private const MEDIA_CONTENT_ASSET_TABLE_NAME = 'media_content_asset';
2222
private const ASSET_ID = 'asset_id';
23-
private const TYPE = 'type';
23+
private const ENTITY_TYPE = 'entity_type';
2424
private const ENTITY_ID = 'entity_id';
2525
private const FIELD = 'field';
2626

@@ -56,16 +56,17 @@ public function execute(ContentIdentityInterface $contentIdentity, array $assetI
5656
foreach ($assetIds as $assetId) {
5757
$data[] = [
5858
self::ASSET_ID => $assetId,
59-
self::TYPE => $contentIdentity->getEntityType(),
59+
self::ENTITY_TYPE => $contentIdentity->getEntityType(),
6060
self::ENTITY_ID => $contentIdentity->getEntityId(),
6161
self::FIELD => $contentIdentity->getField()
6262
];
6363
}
6464
$connection->insertMultiple($tableName, $data);
6565
} catch (\Exception $exception) {
6666
$this->logger->critical($exception);
67-
$message = __('An error occurred while saving relation between media asset and media content.');
68-
throw new CouldNotSaveException($message);
67+
throw new CouldNotSaveException(
68+
__('An error occurred while saving relation between media asset and media content.')
69+
);
6970
}
7071
}
7172
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
class ContentIdentity extends AbstractExtensibleModel implements ContentIdentityInterface
1717
{
18-
private const TYPE = 'entity_type';
18+
private const ENTITY_TYPE = 'entity_type';
1919
private const ENTITY_ID = 'entity_id';
2020
private const FIELD = 'field';
2121

@@ -24,7 +24,7 @@ class ContentIdentity extends AbstractExtensibleModel implements ContentIdentity
2424
*/
2525
public function getEntityType(): string
2626
{
27-
return (string) $this->getData(self::TYPE);
27+
return (string) $this->getData(self::ENTITY_TYPE);
2828
}
2929

3030
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class GetAssetIdsUsedInContent implements GetAssetIdsUsedInContentInterface
2020
{
2121
private const MEDIA_CONTENT_ASSET_TABLE_NAME = 'media_content_asset';
2222
private const ASSET_ID = 'asset_id';
23-
private const TYPE = 'type';
23+
private const ENTITY_TYPE = 'entity_type';
2424
private const ENTITY_ID = 'entity_id';
2525
private const FIELD = 'field';
2626

@@ -58,7 +58,7 @@ public function execute(ContentIdentityInterface $contentIdentity): array
5858
$this->resourceConnection->getTableName(self::MEDIA_CONTENT_ASSET_TABLE_NAME),
5959
self::ASSET_ID
6060
)->where(
61-
self::TYPE . ' = ?',
61+
self::ENTITY_TYPE . ' = ?',
6262
$contentIdentity->getEntityType()
6363
)->where(
6464
self::ENTITY_ID . '= ?',
@@ -68,7 +68,7 @@ public function execute(ContentIdentityInterface $contentIdentity): array
6868
$contentIdentity->getField()
6969
);
7070

71-
return $connection->fetchAssoc($select);
71+
return array_keys($connection->fetchAssoc($select));
7272
} catch (\Exception $exception) {
7373
$this->logger->critical($exception);
7474
$message = __('An error occurred at getting asset used in content information.');

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class GetContentWithAssets implements GetContentWithAssetsInterface
2020
{
2121
private const MEDIA_CONTENT_ASSET_TABLE_NAME = 'media_content_asset';
2222
private const ASSET_ID = 'asset_id';
23+
private const ENTITY_TYPE = 'entity_type';
24+
private const ENTITY_ID = 'entity_id';
25+
private const FIELD = 'field';
2326

2427
/**
2528
* @var ResourceConnection
@@ -59,8 +62,12 @@ public function execute(array $assetIds): array
5962
try {
6063
$connection = $this->resourceConnection->getConnection();
6164
$select = $connection->select()
62-
->from($this->resourceConnection->getTableName(self::MEDIA_CONTENT_ASSET_TABLE_NAME))
63-
->where(self::ASSET_ID . 'IN (?)', $assetIds);
65+
->distinct()
66+
->from(
67+
$this->resourceConnection->getTableName(self::MEDIA_CONTENT_ASSET_TABLE_NAME),
68+
[self::ENTITY_TYPE, self::ENTITY_ID, self::FIELD]
69+
)
70+
->where(self::ASSET_ID . ' IN (?)', $assetIds);
6471

6572
$contentIdentities = [];
6673
foreach ($connection->fetchAssoc($select) as $contentIdentityData) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class UnassignAssets implements UnassignAssetsInterface
2020
{
2121
private const MEDIA_CONTENT_ASSET_TABLE_NAME = 'media_content_asset';
2222
private const ASSET_ID = 'asset_id';
23-
private const TYPE = 'type';
23+
private const ENTITY_TYPE = 'entity_type';
2424
private const ENTITY_ID = 'entity_id';
2525
private const FIELD = 'field';
2626

@@ -58,7 +58,7 @@ public function execute(ContentIdentityInterface $contentIdentity, array $assetI
5858
$tableName,
5959
[
6060
self::ASSET_ID . ' IN (?)' => $assetIds,
61-
self::TYPE . ' = ?' => $contentIdentity->getEntityType(),
61+
self::ENTITY_TYPE . ' = ?' => $contentIdentity->getEntityType(),
6262
self::ENTITY_ID . ' = ?' => $contentIdentity->getEntityId(),
6363
self::FIELD . ' = ?' => $contentIdentity->getField()
6464
]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AssignAssetsTest extends TestCase
4141
/**
4242
* Media content type
4343
*/
44-
private const TYPE = 'type';
44+
private const ENTITY_TYPE = 'entity_type';
4545

4646
/**
4747
* Media entity id
@@ -120,7 +120,7 @@ public function testSuccessfulExecute(
120120
): void {
121121
$saveData = [
122122
self::ASSET_ID => $assetId,
123-
self::TYPE => $contentType,
123+
self::ENTITY_TYPE => $contentType,
124124
self::ENTITY_ID => $contentEntityId,
125125
self::FIELD => $contentField
126126
];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function getAssetsListRelatedToContent(): array
143143
return [
144144
[
145145
[
146-
'type' => 'cms_page',
146+
'entity_type' => 'cms_page',
147147
'entity_id' => '1',
148148
'field' => 'content'
149149
],

app/code/Magento/MediaContent/etc/db_schema.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
99
<table name="media_content_asset" resource="default" engine="innodb" comment="Relation between media content and media asset">
1010
<column xsi:type="int" padding="10" name="asset_id" unsigned="true" nullable="false" identity="true" comment="Entity ID"/>
11-
<column xsi:type="varchar" length="255" name="type" nullable="false" comment="Content type"/>
11+
<column xsi:type="varchar" length="255" name="entity_type" nullable="false" comment="Content type"/>
1212
<column xsi:type="varchar" length="255" name="entity_id" nullable="false" comment="Content entity id"/>
1313
<column xsi:type="varchar" length="255" name="field" nullable="false" comment="Content field"/>
1414
<constraint xsi:type="primary" referenceId="PRIMARY">
1515
<column name="asset_id"/>
16-
<column name="type"/>
16+
<column name="entity_type"/>
1717
<column name="field"/>
18+
<column name="entity_id"/>
1819
</constraint>
1920
</table>
2021
</schema>

app/code/Magento/MediaContent/etc/db_schema_whitelist.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"media_content_asset": {
33
"column": {
44
"asset_id": true,
5-
"type": true,
5+
"entity_type": true,
66
"entity_id": true,
77
"field": true
88
},

app/code/Magento/MediaContent/etc/di.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<preference for="Magento\MediaContentApi\Api\GetContentWithAssetsInterface" type="Magento\MediaContent\Model\GetContentWithAssets"/>
1313
<preference for="Magento\MediaContentApi\Api\ExtractAssetsFromContentInterface" type="Magento\MediaContent\Model\ExtractAssetsFromContent"/>
1414
<preference for="Magento\MediaContentApi\Api\UpdateRelationsInterface" type="Magento\MediaContent\Model\UpdateRelations"/>
15-
<preference for="Magento\MediaContentApi\Api\Data\ContentIdentityInterface" type="Magento\MediaContent\Model\Content"/>
15+
<preference for="Magento\MediaContentApi\Api\Data\ContentIdentityInterface" type="Magento\MediaContent\Model\ContentIdentity"/>
1616
<type name="Magento\MediaGalleryApi\Model\Asset\Command\DeleteByPathInterface">
1717
<plugin name="remove_media_content_after_asset_is_removed_by_path" type="Magento\MediaContent\Model\Plugin\MediaGalleryAssetDeleteByPath" />
1818
</type>
@@ -26,7 +26,7 @@
2626
<argument name="schemaLocator" xsi:type="object">Magento\MediaContent\Model\Content\Config\SchemaLocator</argument>
2727
</arguments>
2828
</type>
29-
<virtualType name="Magento\MediaContent\Model\Directory\Config\Data" type="Magento\Framework\Config\Data">
29+
<virtualType name="Magento\MediaContent\Model\Content\Config\Data" type="Magento\Framework\Config\Data">
3030
<arguments>
3131
<argument name="reader" xsi:type="object">Magento\MediaContent\Model\Content\Config\Reader</argument>
3232
<argument name="cacheId" xsi:type="string">Media_Content_Patterns_CacheId</argument>

0 commit comments

Comments
 (0)