Skip to content

Commit acf425b

Browse files
author
Gabriel Galvao da Gama
committed
Fixing EE bugs
1 parent 500acc3 commit acf425b

File tree

5 files changed

+206
-20
lines changed

5 files changed

+206
-20
lines changed

app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByEavContentField.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class GetAssetIdsByEavContentField implements GetAssetIdsByContentFieldInterface
3838
*/
3939
private $entityType;
4040

41+
/**
42+
* @var string
43+
*/
44+
private $entityTable;
45+
4146
/**
4247
* @var array
4348
*/
@@ -50,19 +55,22 @@ class GetAssetIdsByEavContentField implements GetAssetIdsByContentFieldInterface
5055
* @param Config $config
5156
* @param string $attributeCode
5257
* @param string $entityType
58+
* @param string $entityTable
5359
* @param array $valueMap
5460
*/
5561
public function __construct(
5662
ResourceConnection $resource,
5763
Config $config,
5864
string $attributeCode,
5965
string $entityType,
66+
string $entityTable,
6067
array $valueMap = []
6168
) {
6269
$this->connection = $resource;
6370
$this->config = $config;
6471
$this->attributeCode = $attributeCode;
6572
$this->entityType = $entityType;
73+
$this->entityTable = $entityTable;
6674
$this->valueMap = $valueMap;
6775
}
6876

@@ -80,10 +88,13 @@ public function execute(string $value): array
8088
'entity_type = ?',
8189
$this->entityType
8290
)->joinInner(
83-
['entity_eav_type' => $attribute->getBackendTable()],
84-
'asset_content_table.entity_id = entity_eav_type.' . $attribute->getEntityIdField() .
85-
' AND entity_eav_type.attribute_id = ' .
86-
$attribute->getAttributeId(),
91+
['entity_table' => $this->connection->getTableName($this->entityTable)],
92+
'asset_content_table.entity_id = entity_table.entity_id',
93+
[]
94+
)->joinInner(
95+
['entity_eav_type' => $this->connection->getTableName($attribute->getBackendTable())],
96+
'entity_table.' . $attribute->getEntityIdField() . ' = entity_eav_type.' . $attribute->getEntityIdField() .
97+
' AND entity_eav_type.attribute_id = ' . $attribute->getAttributeId(),
8798
[]
8899
)->where(
89100
'entity_eav_type.value = ?',

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<arguments>
5151
<argument name="attributeCode" xsi:type="string">status</argument>
5252
<argument name="entityType" xsi:type="string">catalog_product</argument>
53+
<argument name="entityTable" xsi:type="string">catalog_product_entity</argument>
5354
<argument name="valueMap" xsi:type="array">
5455
<item name="1" xsi:type="string">1</item>
5556
<item name="0" xsi:type="string">2</item>
@@ -60,6 +61,7 @@
6061
<arguments>
6162
<argument name="attributeCode" xsi:type="string">is_active</argument>
6263
<argument name="entityType" xsi:type="string">catalog_category</argument>
64+
<argument name="entityTable" xsi:type="string">catalog_category_entity</argument>
6365
</arguments>
6466
</virtualType>
6567
<type name="Magento\MediaContentApi\Model\Composite\GetAssetIdsByContentField">
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MediaContentCms\Model\ResourceModel;
9+
10+
use Magento\Cms\Api\BlockRepositoryInterface;
11+
use Magento\Cms\Api\Data\BlockInterface;
12+
use Magento\Framework\Api\SearchCriteriaBuilder;
13+
use Magento\Framework\App\ResourceConnection;
14+
use Magento\Framework\Exception\LocalizedException;
15+
use Magento\MediaContentApi\Model\GetAssetIdsByContentFieldInterface;
16+
17+
/**
18+
* Class responsible to return Asset id by content field
19+
*/
20+
class GetAssetIdsByBlockStore implements GetAssetIdsByContentFieldInterface
21+
{
22+
private const TABLE_CONTENT_ASSET = 'media_content_asset';
23+
private const ENTITY_TYPE = 'cms_block';
24+
private const STORE_FIELD = 'store_id';
25+
26+
/**
27+
* @var ResourceConnection
28+
*/
29+
private $connection;
30+
31+
/**
32+
* @var BlockRepositoryInterface
33+
*/
34+
private $blockRepository;
35+
36+
/**
37+
* @var SearchCriteriaBuilder
38+
*/
39+
private $searchCriteriaBuilder;
40+
41+
/**
42+
* GetAssetIdsByContentField constructor.
43+
*
44+
* @param ResourceConnection $resource
45+
* @param BlockRepositoryInterface $blockRepository
46+
* @param SearchCriteriaBuilder $searchCriteriaBuilder
47+
*/
48+
public function __construct(
49+
ResourceConnection $resource,
50+
BlockRepositoryInterface $blockRepository,
51+
SearchCriteriaBuilder $searchCriteriaBuilder
52+
) {
53+
$this->connection = $resource;
54+
$this->blockRepository = $blockRepository;
55+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
56+
}
57+
58+
/**
59+
* @inheritDoc
60+
*/
61+
public function execute(string $value): array
62+
{
63+
$sql = $this->connection->getConnection()->select()->from(
64+
['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)],
65+
['asset_id']
66+
)->where(
67+
'entity_type = ?',
68+
self::ENTITY_TYPE
69+
)->where(
70+
'entity_id IN (?)',
71+
$this->getBlockIdsByStore((int) $value)
72+
);
73+
74+
return $this->connection->getConnection()->fetchCol($sql);
75+
}
76+
77+
/**
78+
* @param int $storeId
79+
* @return array
80+
* @throws LocalizedException
81+
*/
82+
private function getBlockIdsByStore(int $storeId): array
83+
{
84+
$searchCriteria = $this->searchCriteriaBuilder
85+
->addFilter(self::STORE_FIELD, $storeId)
86+
->create();
87+
88+
$searchResult = $this->blockRepository->getList($searchCriteria);
89+
90+
return array_map(function (BlockInterface $block) {
91+
return $block->getId();
92+
}, $searchResult->getItems());
93+
}
94+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MediaContentCms\Model\ResourceModel;
9+
10+
use Magento\Cms\Api\Data\PageInterface;
11+
use Magento\Cms\Api\PageRepositoryInterface;
12+
use Magento\Framework\Api\FilterBuilder;
13+
use Magento\Framework\Api\SearchCriteriaBuilder;
14+
use Magento\Framework\App\ResourceConnection;
15+
use Magento\Framework\Exception\LocalizedException;
16+
use Magento\MediaContentApi\Model\GetAssetIdsByContentFieldInterface;
17+
18+
/**
19+
* Class responsible to return Asset id by content field
20+
*/
21+
class GetAssetIdsByPageStore implements GetAssetIdsByContentFieldInterface
22+
{
23+
private const TABLE_CONTENT_ASSET = 'media_content_asset';
24+
private const ENTITY_TYPE = 'cms_page';
25+
private const STORE_FIELD = 'store_id';
26+
27+
/**
28+
* @var ResourceConnection
29+
*/
30+
private $connection;
31+
32+
/**
33+
* @var PageRepositoryInterface
34+
*/
35+
private $pageRepository;
36+
37+
/**
38+
* @var SearchCriteriaBuilder
39+
*/
40+
private $searchCriteriaBuilder;
41+
42+
/**
43+
* GetAssetIdsByContentField constructor.
44+
*
45+
* @param ResourceConnection $resource
46+
* @param PageRepositoryInterface $pageRepository
47+
* @param SearchCriteriaBuilder $searchCriteriaBuilder
48+
*/
49+
public function __construct(
50+
ResourceConnection $resource,
51+
PageRepositoryInterface $pageRepository,
52+
SearchCriteriaBuilder $searchCriteriaBuilder
53+
) {
54+
$this->connection = $resource;
55+
$this->pageRepository = $pageRepository;
56+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
57+
}
58+
59+
/**
60+
* @inheritDoc
61+
*/
62+
public function execute(string $value): array
63+
{
64+
$sql = $this->connection->getConnection()->select()->from(
65+
['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)],
66+
['asset_id']
67+
)->where(
68+
'entity_type = ?',
69+
self::ENTITY_TYPE
70+
)->where(
71+
'entity_id IN (?)',
72+
$this->getPageIdsByStore((int) $value)
73+
);
74+
75+
return $this->connection->getConnection()->fetchCol($sql);
76+
}
77+
78+
/**
79+
* @param int $storeId
80+
* @return array
81+
* @throws LocalizedException
82+
*/
83+
private function getPageIdsByStore(int $storeId): array
84+
{
85+
$searchCriteria = $this->searchCriteriaBuilder
86+
->addFilter(self::STORE_FIELD, $storeId)
87+
->create();
88+
89+
$searchResult = $this->pageRepository->getList($searchCriteria);
90+
91+
return array_map(function (PageInterface $page) {
92+
return $page->getId();
93+
}, $searchResult->getItems());
94+
}
95+
}

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,6 @@
3434
</argument>
3535
</arguments>
3636
</type>
37-
<virtualType name="Magento\MediaContentCms\Model\ResourceModel\GetAssetIdsByBlockStore" type="Magento\MediaContentCms\Model\ResourceModel\GetAssetIdsByContentField">
38-
<arguments>
39-
<argument name="entityType" xsi:type="string">cms_block</argument>
40-
<argument name="fieldTable" xsi:type="string">cms_block_store</argument>
41-
<argument name="idColumn" xsi:type="string">block_id</argument>
42-
<argument name="fieldColumn" xsi:type="string">store_id</argument>
43-
</arguments>
44-
</virtualType>
45-
<virtualType name="Magento\MediaContentCms\Model\ResourceModel\GetAssetIdsByPageStore" type="Magento\MediaContentCms\Model\ResourceModel\GetAssetIdsByContentField">
46-
<arguments>
47-
<argument name="entityType" xsi:type="string">cms_page</argument>
48-
<argument name="fieldTable" xsi:type="string">cms_page_store</argument>
49-
<argument name="idColumn" xsi:type="string">page_id</argument>
50-
<argument name="fieldColumn" xsi:type="string">store_id</argument>
51-
</arguments>
52-
</virtualType>
5337
<virtualType name="Magento\MediaContentCms\Model\ResourceModel\GetAssetIdsByPageStatus" type="Magento\MediaContentCms\Model\ResourceModel\GetAssetIdsByContentField">
5438
<arguments>
5539
<argument name="entityType" xsi:type="string">cms_page</argument>

0 commit comments

Comments
 (0)