From dfc733a98eb96cf685938a9cfdb1e10c3aeb1ee1 Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Tue, 7 Jul 2020 12:02:24 +0100 Subject: [PATCH 01/20] Implemented content status filter --- .../Model/GetAssetIdByContentStatus.php | 114 +++++++++++++++ .../GetAssetIdByContentStatusComposite.php | 43 ++++++ .../Model/GetAssetIdByEavContentStatus.php | 136 ++++++++++++++++++ .../Magento/MediaContent/etc/adminhtml/di.xml | 55 +++++++ .../GetAssetIdByContentStatusInterface.php | 20 +++ app/code/Magento/MediaContentUi/LICENSE.txt | 48 +++++++ .../Magento/MediaContentUi/LICENSE_AFL.txt | 48 +++++++ .../FilterProcessor/ContentStatus.php | 47 ++++++ app/code/Magento/MediaContentUi/README.md | 13 ++ app/code/Magento/MediaContentUi/composer.json | 24 ++++ .../MediaContentUi/etc/adminhtml/di.xml | 21 +++ .../Magento/MediaContentUi/etc/module.xml | 10 ++ .../Magento/MediaContentUi/registration.php | 9 ++ 13 files changed, 588 insertions(+) create mode 100644 app/code/Magento/MediaContent/Model/GetAssetIdByContentStatus.php create mode 100644 app/code/Magento/MediaContent/Model/GetAssetIdByContentStatusComposite.php create mode 100644 app/code/Magento/MediaContent/Model/GetAssetIdByEavContentStatus.php create mode 100644 app/code/Magento/MediaContent/etc/adminhtml/di.xml create mode 100644 app/code/Magento/MediaContentApi/Model/GetAssetIdByContentStatusInterface.php create mode 100644 app/code/Magento/MediaContentUi/LICENSE.txt create mode 100644 app/code/Magento/MediaContentUi/LICENSE_AFL.txt create mode 100644 app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/ContentStatus.php create mode 100644 app/code/Magento/MediaContentUi/README.md create mode 100644 app/code/Magento/MediaContentUi/composer.json create mode 100644 app/code/Magento/MediaContentUi/etc/adminhtml/di.xml create mode 100644 app/code/Magento/MediaContentUi/etc/module.xml create mode 100644 app/code/Magento/MediaContentUi/registration.php diff --git a/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatus.php b/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatus.php new file mode 100644 index 0000000000000..05c6ea8ac9b7b --- /dev/null +++ b/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatus.php @@ -0,0 +1,114 @@ +connection = $resource; + $this->entityType = $entityType; + $this->contentTable = $contentTable; + $this->idColumn = $idColumn; + $this->statusColumn = $statusColumn; + $this->valueMap = $valueMap; + } + + /** + * @param string $value + * @return array + */ + public function execute(string $value): array + { + $sql = $this->connection->getConnection()->select()->from( + ['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)], + ['asset_id'] + )->where( + 'entity_type = ?', + $this->entityType + )->joinInner( + ['content_table' => $this->connection->getTableName($this->contentTable)], + 'asset_content_table.entity_id = content_table.' . $this->idColumn, + [] + )->where( + 'content_table.' . $this->statusColumn . ' = ?', + $this->getValueFromMap($value) + ); + + $result = $this->connection->getConnection()->fetchAll($sql); + + return array_map(function ($item) { + return $item['asset_id']; + }, $result); + } + + /** + * @param string $value + * @return string + */ + private function getValueFromMap(string $value): string + { + if (count($this->valueMap) > 0 && array_key_exists($value, $this->valueMap)) { + return $this->valueMap[$value]; + } + return $value; + } +} diff --git a/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatusComposite.php b/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatusComposite.php new file mode 100644 index 0000000000000..72ea5354fae36 --- /dev/null +++ b/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatusComposite.php @@ -0,0 +1,43 @@ +getAssetIdByContentStatusArray = $getAssetIdByContentStatusArray; + } + + /** + * @param string $value + * @return array + */ + public function execute(string $value): array + { + $ids = []; + foreach ($this->getAssetIdByContentStatusArray as $getAssetIdByContentStatus) { + $ids = array_merge($ids, $getAssetIdByContentStatus->execute($value)); + } + return array_unique($ids); + } +} diff --git a/app/code/Magento/MediaContent/Model/GetAssetIdByEavContentStatus.php b/app/code/Magento/MediaContent/Model/GetAssetIdByEavContentStatus.php new file mode 100644 index 0000000000000..c76c7c0623399 --- /dev/null +++ b/app/code/Magento/MediaContent/Model/GetAssetIdByEavContentStatus.php @@ -0,0 +1,136 @@ +connection = $resource; + $this->entityEavTypeTable = $entityEavTypeTable; + $this->attributeCode = $attributeCode; + $this->entityType = $entityType; + $this->entityTypeId = $entityTypeId; + $this->valueMap = $valueMap; + } + + /** + * @param string $value + * @return array + */ + public function execute(string $value): array + { + $statusAttributeId = $this->getAttributeId(); + $sql = $this->connection->getConnection()->select()->from( + ['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)], + ['asset_id'] + )->where( + 'entity_type = ?', + $this->entityType + )->joinInner( + ['entity_eav_type' => $this->connection->getTableName($this->entityEavTypeTable)], + 'asset_content_table.entity_id = entity_eav_type.entity_id AND entity_eav_type.attribute_id = ' . + $statusAttributeId, + [] + )->where( + 'entity_eav_type.value = ?', + $this->getValueFromMap($value) + ); + + $result = $this->connection->getConnection()->fetchAll($sql); + + return array_map(function ($item) { + return $item['asset_id']; + }, $result); + } + + /** + * @return string + */ + private function getAttributeId(): string + { + $sql = $this->connection->getConnection()->select()->from( + ['eav' => $this->connection->getTableName(self::TABLE_EAV_ATTRIBUTE)], + ['attribute_id'] + )->where( + 'entity_type_id = ?', + $this->entityTypeId + )->where( + 'attribute_code = ?', + $this->attributeCode + ); + + return $this->connection->getConnection()->fetchOne($sql); + } + + /** + * @param string $value + * @return string + */ + private function getValueFromMap(string $value): string + { + if (count($this->valueMap) > 0 && array_key_exists($value, $this->valueMap)) { + return $this->valueMap[$value]; + } + return $value; + } +} diff --git a/app/code/Magento/MediaContent/etc/adminhtml/di.xml b/app/code/Magento/MediaContent/etc/adminhtml/di.xml new file mode 100644 index 0000000000000..b85f39e8beda7 --- /dev/null +++ b/app/code/Magento/MediaContent/etc/adminhtml/di.xml @@ -0,0 +1,55 @@ + + + + + + + Magento\MediaContent\Model\GetAssetIdByProductStatus + Magento\MediaContent\Model\GetAssetIdByCategoryStatus + Magento\MediaContent\Model\GetAssetIdByPageStatus + Magento\MediaContent\Model\GetAssetIdByBlockStatus + + + + + + catalog_product_entity_int + status + catalog_product + 4 + + 1 + 2 + + + + + + catalog_category_entity_int + is_active + catalog_category + 3 + + + + + cms_page + cms_page + page_id + is_active + + + + + cms_block + cms_block + block_id + is_active + + + diff --git a/app/code/Magento/MediaContentApi/Model/GetAssetIdByContentStatusInterface.php b/app/code/Magento/MediaContentApi/Model/GetAssetIdByContentStatusInterface.php new file mode 100644 index 0000000000000..6eb609f68a389 --- /dev/null +++ b/app/code/Magento/MediaContentApi/Model/GetAssetIdByContentStatusInterface.php @@ -0,0 +1,20 @@ +" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. \ No newline at end of file diff --git a/app/code/Magento/MediaContentUi/LICENSE_AFL.txt b/app/code/Magento/MediaContentUi/LICENSE_AFL.txt new file mode 100644 index 0000000000000..f39d641b18a19 --- /dev/null +++ b/app/code/Magento/MediaContentUi/LICENSE_AFL.txt @@ -0,0 +1,48 @@ + +Academic Free License ("AFL") v. 3.0 + +This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Academic Free License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. diff --git a/app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/ContentStatus.php b/app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/ContentStatus.php new file mode 100644 index 0000000000000..bf157569586ba --- /dev/null +++ b/app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/ContentStatus.php @@ -0,0 +1,47 @@ +getAssetIdByContentStatus = $getAssetIdByContentStatus; + } + + /** + * @inheritDoc + */ + public function apply(Filter $filter, AbstractDb $collection): bool + { + $collection->addFieldToFilter( + self::TABLE_ALIAS . '.id', + ['in' => $this->getAssetIdByContentStatus->execute($filter->getValue())] + ); + + return true; + } + +} diff --git a/app/code/Magento/MediaContentUi/README.md b/app/code/Magento/MediaContentUi/README.md new file mode 100644 index 0000000000000..2145d9c328914 --- /dev/null +++ b/app/code/Magento/MediaContentUi/README.md @@ -0,0 +1,13 @@ +# Magento_MediaContentUi module + +The Magento_MediaContentUi module is responsible for the media content user interface (UI) implementation. + +## Extensibility + +Extension developers can interact with the Magento_MediaContentUi module. For more information about the Magento extension mechanism, see [Magento plug-ins](https://devdocs.magento.com/guides/v2.4/extension-dev-guide/plugins.html). + +[The Magento dependency injection mechanism](https://devdocs.magento.com/guides/v2.4/extension-dev-guide/depend-inj.html) enables you to override the functionality of the Magento_MediaContentUi module. + +## Additional information + +For information about significant changes in patch releases, see [2.3.x Release information](https://devdocs.magento.com/guides/v2.4/release-notes/bk-release-notes.html). diff --git a/app/code/Magento/MediaContentUi/composer.json b/app/code/Magento/MediaContentUi/composer.json new file mode 100644 index 0000000000000..67b92f925d11d --- /dev/null +++ b/app/code/Magento/MediaContentUi/composer.json @@ -0,0 +1,24 @@ +{ + "name": "magento/module-media-content-ui", + "description": "Magento module responsible for media content user interface", + "require": { + "php": "~7.3.0||~7.4.0", + "magento/framework": "*", + "magento/module-media-content-api": "*", + "magento/module-media-content": "*", + "magento/module-media-gallery-ui": "*" + }, + "type": "magento2-module", + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Magento\\MediaContentUi\\": "" + } + } +} diff --git a/app/code/Magento/MediaContentUi/etc/adminhtml/di.xml b/app/code/Magento/MediaContentUi/etc/adminhtml/di.xml new file mode 100644 index 0000000000000..e8fc8ef9c1ddd --- /dev/null +++ b/app/code/Magento/MediaContentUi/etc/adminhtml/di.xml @@ -0,0 +1,21 @@ + + + + + + + Magento\MediaContentUi\Model\SearchCriteria\CollectionProcessor\FilterProcessor\ContentStatus + + + + + + Magento\MediaContent\Model\GetAssetIdByContentStatusComposite + + + diff --git a/app/code/Magento/MediaContentUi/etc/module.xml b/app/code/Magento/MediaContentUi/etc/module.xml new file mode 100644 index 0000000000000..3f615d11ae2ff --- /dev/null +++ b/app/code/Magento/MediaContentUi/etc/module.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/app/code/Magento/MediaContentUi/registration.php b/app/code/Magento/MediaContentUi/registration.php new file mode 100644 index 0000000000000..5f55c31a5936c --- /dev/null +++ b/app/code/Magento/MediaContentUi/registration.php @@ -0,0 +1,9 @@ + Date: Tue, 7 Jul 2020 12:18:06 +0100 Subject: [PATCH 02/20] Improved attribute fetching --- .../Model/GetAssetIdByContentStatus.php | 14 +---- .../Model/GetAssetIdByEavContentStatus.php | 53 ++++++------------- .../Magento/MediaContent/etc/adminhtml/di.xml | 4 -- 3 files changed, 16 insertions(+), 55 deletions(-) diff --git a/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatus.php b/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatus.php index 05c6ea8ac9b7b..10f974ab104e2 100644 --- a/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatus.php +++ b/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatus.php @@ -90,7 +90,7 @@ public function execute(string $value): array [] )->where( 'content_table.' . $this->statusColumn . ' = ?', - $this->getValueFromMap($value) + $value ); $result = $this->connection->getConnection()->fetchAll($sql); @@ -99,16 +99,4 @@ public function execute(string $value): array return $item['asset_id']; }, $result); } - - /** - * @param string $value - * @return string - */ - private function getValueFromMap(string $value): string - { - if (count($this->valueMap) > 0 && array_key_exists($value, $this->valueMap)) { - return $this->valueMap[$value]; - } - return $value; - } } diff --git a/app/code/Magento/MediaContent/Model/GetAssetIdByEavContentStatus.php b/app/code/Magento/MediaContent/Model/GetAssetIdByEavContentStatus.php index c76c7c0623399..9da0dc1cd3f53 100644 --- a/app/code/Magento/MediaContent/Model/GetAssetIdByEavContentStatus.php +++ b/app/code/Magento/MediaContent/Model/GetAssetIdByEavContentStatus.php @@ -7,6 +7,8 @@ namespace Magento\MediaContent\Model; +use Magento\Eav\Api\Data\AttributeInterface; +use Magento\Eav\Model\Config; use Magento\Framework\App\ResourceConnection; use Magento\MediaContentApi\Model\GetAssetIdByContentStatusInterface; @@ -16,7 +18,6 @@ class GetAssetIdByEavContentStatus implements GetAssetIdByContentStatusInterface { private const TABLE_CONTENT_ASSET = 'media_content_asset'; - private const TABLE_EAV_ATTRIBUTE = 'eav_attribute'; /** * @var ResourceConnection @@ -24,9 +25,9 @@ class GetAssetIdByEavContentStatus implements GetAssetIdByContentStatusInterface private $connection; /** - * @var string + * @var Config */ - private $entityEavTypeTable; + private $config; /** * @var string @@ -38,48 +39,42 @@ class GetAssetIdByEavContentStatus implements GetAssetIdByContentStatusInterface */ private $entityType; - /** - * @var int - */ - private $entityTypeId; - /** * @var array */ private $valueMap; /** - * GetEavContentIdByStatus constructor. + * GetAssetIdByEavContentStatus constructor. * @param ResourceConnection $resource - * @param string $entityEavTypeTable + * @param Config $config * @param string $attributeCode * @param string $entityType - * @param int $entityTypeId * @param array $valueMap */ public function __construct( ResourceConnection $resource, - string $entityEavTypeTable, + Config $config, string $attributeCode, string $entityType, - int $entityTypeId, array $valueMap = [] ) { $this->connection = $resource; - $this->entityEavTypeTable = $entityEavTypeTable; + $this->config = $config; $this->attributeCode = $attributeCode; $this->entityType = $entityType; - $this->entityTypeId = $entityTypeId; $this->valueMap = $valueMap; } /** * @param string $value * @return array + * @throws \Magento\Framework\Exception\LocalizedException */ public function execute(string $value): array { - $statusAttributeId = $this->getAttributeId(); + $statusAttribute = $this->config->getAttribute($this->entityType, $this->attributeCode); + $sql = $this->connection->getConnection()->select()->from( ['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)], ['asset_id'] @@ -87,9 +82,10 @@ public function execute(string $value): array 'entity_type = ?', $this->entityType )->joinInner( - ['entity_eav_type' => $this->connection->getTableName($this->entityEavTypeTable)], - 'asset_content_table.entity_id = entity_eav_type.entity_id AND entity_eav_type.attribute_id = ' . - $statusAttributeId, + ['entity_eav_type' => $statusAttribute->getBackendTable()], + 'asset_content_table.entity_id = entity_eav_type.' . $statusAttribute->getEntityIdField() . + ' AND entity_eav_type.attribute_id = ' . + $statusAttribute->getAttributeId(), [] )->where( 'entity_eav_type.value = ?', @@ -103,25 +99,6 @@ public function execute(string $value): array }, $result); } - /** - * @return string - */ - private function getAttributeId(): string - { - $sql = $this->connection->getConnection()->select()->from( - ['eav' => $this->connection->getTableName(self::TABLE_EAV_ATTRIBUTE)], - ['attribute_id'] - )->where( - 'entity_type_id = ?', - $this->entityTypeId - )->where( - 'attribute_code = ?', - $this->attributeCode - ); - - return $this->connection->getConnection()->fetchOne($sql); - } - /** * @param string $value * @return string diff --git a/app/code/Magento/MediaContent/etc/adminhtml/di.xml b/app/code/Magento/MediaContent/etc/adminhtml/di.xml index b85f39e8beda7..6f0f8efc1ac53 100644 --- a/app/code/Magento/MediaContent/etc/adminhtml/di.xml +++ b/app/code/Magento/MediaContent/etc/adminhtml/di.xml @@ -18,10 +18,8 @@ - catalog_product_entity_int status catalog_product - 4 1 2 @@ -30,10 +28,8 @@ - catalog_category_entity_int is_active catalog_category - 3 From 15aa96f9ee6bebebe8d3102c39e655553ef21ee0 Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Tue, 7 Jul 2020 12:25:29 +0100 Subject: [PATCH 03/20] Improved php doc blocks --- .../Model/GetAssetIdByContentStatus.php | 8 ++++---- .../Model/GetAssetIdByContentStatusComposite.php | 11 +++++++---- .../Model/GetAssetIdByEavContentStatus.php | 13 +++++++------ .../Model/GetAssetIdByContentStatusInterface.php | 4 +++- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatus.php b/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatus.php index 10f974ab104e2..f9ec4cff77bae 100644 --- a/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatus.php +++ b/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatus.php @@ -11,7 +11,7 @@ use Magento\MediaContentApi\Model\GetAssetIdByContentStatusInterface; /** - * Class GetAssetIdByContentStatus + * Class responsible to return Asset id by entity status */ class GetAssetIdByContentStatus implements GetAssetIdByContentStatusInterface { @@ -48,7 +48,8 @@ class GetAssetIdByContentStatus implements GetAssetIdByContentStatusInterface private $valueMap; /** - * GetContentIdByStatus constructor. + * GetAssetIdByContentStatus constructor. + * * @param ResourceConnection $resource * @param string $entityType * @param string $contentTable @@ -73,8 +74,7 @@ public function __construct( } /** - * @param string $value - * @return array + * @inheritDoc */ public function execute(string $value): array { diff --git a/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatusComposite.php b/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatusComposite.php index 72ea5354fae36..f62b3cd2ffb52 100644 --- a/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatusComposite.php +++ b/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatusComposite.php @@ -10,7 +10,7 @@ use Magento\MediaContentApi\Model\GetAssetIdByContentStatusInterface; /** - * Class GetAssetIdByContentStatusComposite + * Class responsible to return Asset ids by content status */ class GetAssetIdByContentStatusComposite implements GetAssetIdByContentStatusInterface { @@ -21,6 +21,7 @@ class GetAssetIdByContentStatusComposite implements GetAssetIdByContentStatusInt /** * GetAssetIdByContentStatusComposite constructor. + * * @param array $getAssetIdByContentStatusArray */ public function __construct($getAssetIdByContentStatusArray = []) @@ -29,14 +30,16 @@ public function __construct($getAssetIdByContentStatusArray = []) } /** - * @param string $value + * Get Asset ids by Content status + * + * @param string $status * @return array */ - public function execute(string $value): array + public function execute(string $status): array { $ids = []; foreach ($this->getAssetIdByContentStatusArray as $getAssetIdByContentStatus) { - $ids = array_merge($ids, $getAssetIdByContentStatus->execute($value)); + $ids = array_merge($ids, $getAssetIdByContentStatus->execute($status)); } return array_unique($ids); } diff --git a/app/code/Magento/MediaContent/Model/GetAssetIdByEavContentStatus.php b/app/code/Magento/MediaContent/Model/GetAssetIdByEavContentStatus.php index 9da0dc1cd3f53..c9d2e93182802 100644 --- a/app/code/Magento/MediaContent/Model/GetAssetIdByEavContentStatus.php +++ b/app/code/Magento/MediaContent/Model/GetAssetIdByEavContentStatus.php @@ -7,13 +7,12 @@ namespace Magento\MediaContent\Model; -use Magento\Eav\Api\Data\AttributeInterface; use Magento\Eav\Model\Config; use Magento\Framework\App\ResourceConnection; use Magento\MediaContentApi\Model\GetAssetIdByContentStatusInterface; /** - * Class GetAssetIdByEavContentStatus + * Class responsible to return Asset id by eav entity status */ class GetAssetIdByEavContentStatus implements GetAssetIdByContentStatusInterface { @@ -46,6 +45,7 @@ class GetAssetIdByEavContentStatus implements GetAssetIdByContentStatusInterface /** * GetAssetIdByEavContentStatus constructor. + * * @param ResourceConnection $resource * @param Config $config * @param string $attributeCode @@ -67,11 +67,10 @@ public function __construct( } /** - * @param string $value - * @return array + * @inheritDoc * @throws \Magento\Framework\Exception\LocalizedException */ - public function execute(string $value): array + public function execute(string $status): array { $statusAttribute = $this->config->getAttribute($this->entityType, $this->attributeCode); @@ -89,7 +88,7 @@ public function execute(string $value): array [] )->where( 'entity_eav_type.value = ?', - $this->getValueFromMap($value) + $this->getValueFromMap($status) ); $result = $this->connection->getConnection()->fetchAll($sql); @@ -100,6 +99,8 @@ public function execute(string $value): array } /** + * Get a value from a value map + * * @param string $value * @return string */ diff --git a/app/code/Magento/MediaContentApi/Model/GetAssetIdByContentStatusInterface.php b/app/code/Magento/MediaContentApi/Model/GetAssetIdByContentStatusInterface.php index 6eb609f68a389..cfd75a8274c4c 100644 --- a/app/code/Magento/MediaContentApi/Model/GetAssetIdByContentStatusInterface.php +++ b/app/code/Magento/MediaContentApi/Model/GetAssetIdByContentStatusInterface.php @@ -8,11 +8,13 @@ namespace Magento\MediaContentApi\Model; /** - * Interface used to return Asset id by content status (enabled, disabled). + * Interface used to return Asset id by content status. */ interface GetAssetIdByContentStatusInterface { /** + * This function returns asset ids by entity status + * * @param string $status * @return int[] */ From 1fcb11a63b832c4811621c636e2571ed261e27ac Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Tue, 7 Jul 2020 12:44:02 +0100 Subject: [PATCH 04/20] Added UI filter to media gallery --- .../Listing/Filters/Options/Status.php | 27 +++++++++++++++++++ .../ui_component/media_gallery_listing.xml | 22 +++++++++++++++ .../standalone_media_gallery_listing.xml | 22 +++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 app/code/Magento/MediaContentUi/Ui/Component/Listing/Filters/Options/Status.php create mode 100644 app/code/Magento/MediaContentUi/view/adminhtml/ui_component/media_gallery_listing.xml create mode 100644 app/code/Magento/MediaContentUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml diff --git a/app/code/Magento/MediaContentUi/Ui/Component/Listing/Filters/Options/Status.php b/app/code/Magento/MediaContentUi/Ui/Component/Listing/Filters/Options/Status.php new file mode 100644 index 0000000000000..4ac4161453d17 --- /dev/null +++ b/app/code/Magento/MediaContentUi/Ui/Component/Listing/Filters/Options/Status.php @@ -0,0 +1,27 @@ + '1', 'label' => __('Enabled')], + ['value' => '0', 'label' => __('Disabled')] + ]; + } +} diff --git a/app/code/Magento/MediaContentUi/view/adminhtml/ui_component/media_gallery_listing.xml b/app/code/Magento/MediaContentUi/view/adminhtml/ui_component/media_gallery_listing.xml new file mode 100644 index 0000000000000..fe6ccd94cd0b1 --- /dev/null +++ b/app/code/Magento/MediaContentUi/view/adminhtml/ui_component/media_gallery_listing.xml @@ -0,0 +1,22 @@ + + ++ + + + + + + All + content_status + + + + + diff --git a/app/code/Magento/MediaContentUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml b/app/code/Magento/MediaContentUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml new file mode 100644 index 0000000000000..fe6ccd94cd0b1 --- /dev/null +++ b/app/code/Magento/MediaContentUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml @@ -0,0 +1,22 @@ + + ++ + + + + + + All + content_status + + + + + From a7e980c8c37b7caebf8500f906b010ea64abc832 Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Thu, 9 Jul 2020 14:11:34 +0100 Subject: [PATCH 05/20] Refactor and added store view filter --- .../GetAssetIdByContentFieldComposite.php | 43 +++++++ .../GetAssetIdByContentStatusComposite.php | 46 ------- .../Magento/MediaContent/etc/adminhtml/di.xml | 51 -------- app/code/Magento/MediaContent/etc/di.xml | 2 + .../GetAssetIdByContentFieldInterface.php | 22 ++++ .../GetAssetIdByContentStatusInterface.php | 22 ---- .../Model/GetAssetIdByCategoryStore.php | 120 ++++++++++++++++++ .../Model/GetAssetIdByEavContentField.php} | 12 +- .../Model/GetAssetIdByProductStore.php | 102 +++++++++++++++ .../Magento/MediaContentCatalog/composer.json | 2 + .../Magento/MediaContentCatalog/etc/di.xml | 32 +++++ .../Model/GetAssetIdByContentField.php} | 41 +++--- .../Magento/MediaContentCms/composer.json | 1 + app/code/Magento/MediaContentCms/etc/di.xml | 48 +++++++ .../FilterProcessor/ContentStatus.php | 8 +- .../FilterProcessor/StoreView.php | 47 +++++++ .../MediaContentUi/etc/adminhtml/di.xml | 6 + .../standalone_media_gallery_listing.xml | 11 ++ 18 files changed, 464 insertions(+), 152 deletions(-) create mode 100644 app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php delete mode 100644 app/code/Magento/MediaContent/Model/GetAssetIdByContentStatusComposite.php delete mode 100644 app/code/Magento/MediaContent/etc/adminhtml/di.xml create mode 100644 app/code/Magento/MediaContentApi/Model/GetAssetIdByContentFieldInterface.php delete mode 100644 app/code/Magento/MediaContentApi/Model/GetAssetIdByContentStatusInterface.php create mode 100644 app/code/Magento/MediaContentCatalog/Model/GetAssetIdByCategoryStore.php rename app/code/Magento/{MediaContent/Model/GetAssetIdByEavContentStatus.php => MediaContentCatalog/Model/GetAssetIdByEavContentField.php} (88%) create mode 100644 app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php rename app/code/Magento/{MediaContent/Model/GetAssetIdByContentStatus.php => MediaContentCms/Model/GetAssetIdByContentField.php} (61%) create mode 100644 app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/StoreView.php diff --git a/app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php b/app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php new file mode 100644 index 0000000000000..b36b112286a8f --- /dev/null +++ b/app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php @@ -0,0 +1,43 @@ +getAssetIdByContentFieldArray = $getAssetIdByContentFieldArray; + } + + /** + * @inheritDoc + */ + public function execute(string $value): array + { + $ids = []; + foreach ($this->getAssetIdByContentFieldArray as $getAssetIdByContentField) { + $ids = array_merge($ids, $getAssetIdByContentField->execute($value)); + } + return array_unique($ids); + } +} diff --git a/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatusComposite.php b/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatusComposite.php deleted file mode 100644 index f62b3cd2ffb52..0000000000000 --- a/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatusComposite.php +++ /dev/null @@ -1,46 +0,0 @@ -getAssetIdByContentStatusArray = $getAssetIdByContentStatusArray; - } - - /** - * Get Asset ids by Content status - * - * @param string $status - * @return array - */ - public function execute(string $status): array - { - $ids = []; - foreach ($this->getAssetIdByContentStatusArray as $getAssetIdByContentStatus) { - $ids = array_merge($ids, $getAssetIdByContentStatus->execute($status)); - } - return array_unique($ids); - } -} diff --git a/app/code/Magento/MediaContent/etc/adminhtml/di.xml b/app/code/Magento/MediaContent/etc/adminhtml/di.xml deleted file mode 100644 index 6f0f8efc1ac53..0000000000000 --- a/app/code/Magento/MediaContent/etc/adminhtml/di.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - Magento\MediaContent\Model\GetAssetIdByProductStatus - Magento\MediaContent\Model\GetAssetIdByCategoryStatus - Magento\MediaContent\Model\GetAssetIdByPageStatus - Magento\MediaContent\Model\GetAssetIdByBlockStatus - - - - - - status - catalog_product - - 1 - 2 - - - - - - is_active - catalog_category - - - - - cms_page - cms_page - page_id - is_active - - - - - cms_block - cms_block - block_id - is_active - - - diff --git a/app/code/Magento/MediaContent/etc/di.xml b/app/code/Magento/MediaContent/etc/di.xml index f2a9459447001..bfce45c797a1a 100644 --- a/app/code/Magento/MediaContent/etc/di.xml +++ b/app/code/Magento/MediaContent/etc/di.xml @@ -43,4 +43,6 @@ Magento\MediaContent\Model\Content\Config\Data + + diff --git a/app/code/Magento/MediaContentApi/Model/GetAssetIdByContentFieldInterface.php b/app/code/Magento/MediaContentApi/Model/GetAssetIdByContentFieldInterface.php new file mode 100644 index 0000000000000..13d29bcfe03c7 --- /dev/null +++ b/app/code/Magento/MediaContentApi/Model/GetAssetIdByContentFieldInterface.php @@ -0,0 +1,22 @@ +connection = $resource; + $this->storeRepository = $storeRepository; + $this->storeGroupRepository = $storeGroupRepository; + $this->entityType = 'catalog_category'; + } + + /** + * @inheritDoc + * @throws LocalizedException + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + public function execute(string $value): array + { + $storeView = $this->storeRepository->getById($value); + $storeGroup = $this->storeGroupRepository->get($storeView->getStoreGroupId()); + $categoryIds = $this->getCategoryIdsByRootCategory($storeGroup->getRootCategoryId()); + $sql = $this->connection->getConnection()->select()->from( + ['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)], + ['asset_id'] + )->where( + 'entity_type = ?', + $this->entityType + )->where( + 'entity_id IN (?)', + $categoryIds + ); + + $result = $this->connection->getConnection()->fetchAll($sql); + + return array_map(function ($item) { + return $item['asset_id']; + }, $result); + } + + private function getCategoryIdsByRootCategory($rootCategoryId) + { + $contentCategoriesSql = $this->connection->getConnection()->select()->from( + ['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)], + ['entity_id'] + )->where( + 'entity_type = ?', + $this->entityType + )->joinInner( + ['category_table' => $this->connection->getTableName('catalog_category_entity')], + 'asset_content_table.entity_id = category_table.entity_id', + ['path'] + ); + + $result = $this->connection->getConnection()->fetchAll($contentCategoriesSql); + + $result = array_filter($result, function ($item) use ($rootCategoryId) { + $pathArray = explode("/", $item['path']); + $isInPath = false; + foreach ($pathArray as $id) { + if ($id == $rootCategoryId) { + $isInPath = true; + } + } + return $isInPath; + }); + + return array_map(function ($item) { + return $item['entity_id']; + }, $result); + } +} diff --git a/app/code/Magento/MediaContent/Model/GetAssetIdByEavContentStatus.php b/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByEavContentField.php similarity index 88% rename from app/code/Magento/MediaContent/Model/GetAssetIdByEavContentStatus.php rename to app/code/Magento/MediaContentCatalog/Model/GetAssetIdByEavContentField.php index c9d2e93182802..91c42df7d76dd 100644 --- a/app/code/Magento/MediaContent/Model/GetAssetIdByEavContentStatus.php +++ b/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByEavContentField.php @@ -5,16 +5,16 @@ */ declare(strict_types=1); -namespace Magento\MediaContent\Model; +namespace Magento\MediaContentCatalog\Model; use Magento\Eav\Model\Config; use Magento\Framework\App\ResourceConnection; -use Magento\MediaContentApi\Model\GetAssetIdByContentStatusInterface; +use Magento\MediaContentApi\Model\GetAssetIdByContentFieldInterface; /** - * Class responsible to return Asset id by eav entity status + * Class responsible to return Asset id by eav content field */ -class GetAssetIdByEavContentStatus implements GetAssetIdByContentStatusInterface +class GetAssetIdByEavContentField implements GetAssetIdByContentFieldInterface { private const TABLE_CONTENT_ASSET = 'media_content_asset'; @@ -70,7 +70,7 @@ public function __construct( * @inheritDoc * @throws \Magento\Framework\Exception\LocalizedException */ - public function execute(string $status): array + public function execute(string $value): array { $statusAttribute = $this->config->getAttribute($this->entityType, $this->attributeCode); @@ -88,7 +88,7 @@ public function execute(string $status): array [] )->where( 'entity_eav_type.value = ?', - $this->getValueFromMap($status) + $this->getValueFromMap($value) ); $result = $this->connection->getConnection()->fetchAll($sql); diff --git a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php b/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php new file mode 100644 index 0000000000000..a13da8d501903 --- /dev/null +++ b/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php @@ -0,0 +1,102 @@ +connection = $resource; + $this->storeRepository = $storeRepository; + $this->entityType = 'catalog_product'; + $this->fieldTable = 'catalog_product_website'; + $this->idColumn = 'product_id'; + $this->fieldColumn = 'website_id'; + } + + /** + * @inheritDoc + * @throws LocalizedException + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + public function execute(string $value): array + { + $store = $this->storeRepository->getById($value); + $sql = $this->connection->getConnection()->select()->from( + ['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)], + ['asset_id'] + )->where( + 'entity_type = ?', + $this->entityType + )->joinInner( + ['field_table' => $this->connection->getTableName($this->fieldTable)], + 'asset_content_table.entity_id = field_table.' . $this->idColumn, + [] + )->where( + 'field_table.' . $this->fieldColumn . ' = ?', + $store->getWebsiteId() + ); + + $result = $this->connection->getConnection()->fetchAll($sql); + + return array_map(function ($item) { + return $item['asset_id']; + }, $result); + } +} diff --git a/app/code/Magento/MediaContentCatalog/composer.json b/app/code/Magento/MediaContentCatalog/composer.json index 21e23e6b18bdc..da592c2bf11be 100644 --- a/app/code/Magento/MediaContentCatalog/composer.json +++ b/app/code/Magento/MediaContentCatalog/composer.json @@ -4,8 +4,10 @@ "require": { "php": "~7.3.0||~7.4.0", "magento/module-media-content-api": "*", + "magento/module-media-content": "*", "magento/module-catalog": "*", "magento/module-eav": "*", + "magento/module-store": "*", "magento/framework": "*" }, "type": "magento2-module", diff --git a/app/code/Magento/MediaContentCatalog/etc/di.xml b/app/code/Magento/MediaContentCatalog/etc/di.xml index 6b0ee83b30788..2bc595151ddfe 100644 --- a/app/code/Magento/MediaContentCatalog/etc/di.xml +++ b/app/code/Magento/MediaContentCatalog/etc/di.xml @@ -46,4 +46,36 @@ + + + status + catalog_product + + 1 + 2 + + + + + + is_active + catalog_category + + + + + + Magento\MediaContentCatalog\Model\GetAssetIdByProductStatus + Magento\MediaContentCatalog\Model\GetAssetIdByCategoryStatus + + + + + + + Magento\MediaContentCatalog\Model\GetAssetIdByProductStore + Magento\MediaContentCatalog\Model\GetAssetIdByCategoryStore + + + diff --git a/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatus.php b/app/code/Magento/MediaContentCms/Model/GetAssetIdByContentField.php similarity index 61% rename from app/code/Magento/MediaContent/Model/GetAssetIdByContentStatus.php rename to app/code/Magento/MediaContentCms/Model/GetAssetIdByContentField.php index f9ec4cff77bae..cb10a097e59ac 100644 --- a/app/code/Magento/MediaContent/Model/GetAssetIdByContentStatus.php +++ b/app/code/Magento/MediaContentCms/Model/GetAssetIdByContentField.php @@ -5,15 +5,17 @@ */ declare(strict_types=1); -namespace Magento\MediaContent\Model; +namespace Magento\MediaContentCms\Model; use Magento\Framework\App\ResourceConnection; -use Magento\MediaContentApi\Model\GetAssetIdByContentStatusInterface; +use Magento\Framework\Exception\LocalizedException; +use Magento\MediaContentApi\Model\GetAssetIdByContentFieldInterface; +use Magento\Store\Api\StoreRepositoryInterface; /** - * Class responsible to return Asset id by entity status + * Class responsible to return Asset id by content field */ -class GetAssetIdByContentStatus implements GetAssetIdByContentStatusInterface +class GetAssetIdByContentField implements GetAssetIdByContentFieldInterface { private const TABLE_CONTENT_ASSET = 'media_content_asset'; @@ -30,47 +32,40 @@ class GetAssetIdByContentStatus implements GetAssetIdByContentStatusInterface /** * @var string */ - private $contentTable; + private $fieldTable; /** * @var string */ - private $statusColumn; + private $fieldColumn; /** * @var string */ private $idColumn; - /** - * @var array - */ - private $valueMap; /** - * GetAssetIdByContentStatus constructor. + * GetAssetIdByContentField constructor. * * @param ResourceConnection $resource * @param string $entityType - * @param string $contentTable + * @param string $fieldTable * @param string $idColumn - * @param string $statusColumn - * @param array $valueMap + * @param string $fieldColumn */ public function __construct( ResourceConnection $resource, string $entityType, - string $contentTable, + string $fieldTable, string $idColumn, - string $statusColumn, - array $valueMap = [] + string $fieldColumn ) { $this->connection = $resource; $this->entityType = $entityType; - $this->contentTable = $contentTable; + $this->fieldTable = $fieldTable; $this->idColumn = $idColumn; - $this->statusColumn = $statusColumn; - $this->valueMap = $valueMap; + $this->fieldColumn = $fieldColumn; } /** @@ -85,11 +80,11 @@ public function execute(string $value): array 'entity_type = ?', $this->entityType )->joinInner( - ['content_table' => $this->connection->getTableName($this->contentTable)], - 'asset_content_table.entity_id = content_table.' . $this->idColumn, + ['field_table' => $this->connection->getTableName($this->fieldTable)], + 'asset_content_table.entity_id = field_table.' . $this->idColumn, [] )->where( - 'content_table.' . $this->statusColumn . ' = ?', + 'field_table.' . $this->fieldColumn . ' = ?', $value ); diff --git a/app/code/Magento/MediaContentCms/composer.json b/app/code/Magento/MediaContentCms/composer.json index ea32fdd7a49fa..ff8bff348770b 100644 --- a/app/code/Magento/MediaContentCms/composer.json +++ b/app/code/Magento/MediaContentCms/composer.json @@ -4,6 +4,7 @@ "require": { "php": "~7.3.0||~7.4.0", "magento/module-media-content-api": "*", + "magento/module-media-content": "*", "magento/module-cms": "*", "magento/framework": "*" }, diff --git a/app/code/Magento/MediaContentCms/etc/di.xml b/app/code/Magento/MediaContentCms/etc/di.xml index 6f196889540af..dc633b95d0517 100644 --- a/app/code/Magento/MediaContentCms/etc/di.xml +++ b/app/code/Magento/MediaContentCms/etc/di.xml @@ -34,4 +34,52 @@ + + + cms_block + cms_block_store + block_id + store_id + + + + + cms_page + cms_page_store + page_id + store_id + + + + + cms_page + cms_page + page_id + is_active + + + + + cms_block + cms_block + block_id + is_active + + + + + + Magento\MediaContentCms\Model\GetAssetIdByPageStatus + Magento\MediaContentCms\Model\GetAssetIdByBlockStatus + + + + + + + Magento\MediaContentCms\Model\GetAssetIdByPageStore + Magento\MediaContentCms\Model\GetAssetIdByBlockStore + + + diff --git a/app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/ContentStatus.php b/app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/ContentStatus.php index bf157569586ba..3a18103b640f2 100644 --- a/app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/ContentStatus.php +++ b/app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/ContentStatus.php @@ -10,23 +10,23 @@ use Magento\Framework\Api\Filter; use Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor\CustomFilterInterface; use Magento\Framework\Data\Collection\AbstractDb; -use Magento\MediaContentApi\Model\GetAssetIdByContentStatusInterface; +use Magento\MediaContentApi\Model\GetAssetIdByContentFieldInterface; class ContentStatus implements CustomFilterInterface { private const TABLE_ALIAS = 'main_table'; /** - * @var GetAssetIdByContentStatusInterface + * @var GetAssetIdByContentFieldInterface */ private $getAssetIdByContentStatus; /** * ContentStatus constructor. - * @param GetAssetIdByContentStatusInterface $getAssetIdByContentStatus + * @param GetAssetIdByContentFieldInterface $getAssetIdByContentStatus */ public function __construct( - GetAssetIdByContentStatusInterface $getAssetIdByContentStatus + GetAssetIdByContentFieldInterface $getAssetIdByContentStatus ) { $this->getAssetIdByContentStatus = $getAssetIdByContentStatus; } diff --git a/app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/StoreView.php b/app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/StoreView.php new file mode 100644 index 0000000000000..ad445c24986cb --- /dev/null +++ b/app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/StoreView.php @@ -0,0 +1,47 @@ +getAssetIdByContentStatus = $getAssetIdByContentStatus; + } + + /** + * @inheritDoc + */ + public function apply(Filter $filter, AbstractDb $collection): bool + { + $collection->addFieldToFilter( + self::TABLE_ALIAS . '.id', + ['in' => $this->getAssetIdByContentStatus->execute($filter->getValue())] + ); + + return true; + } + +} diff --git a/app/code/Magento/MediaContentUi/etc/adminhtml/di.xml b/app/code/Magento/MediaContentUi/etc/adminhtml/di.xml index e8fc8ef9c1ddd..e36e2f1305035 100644 --- a/app/code/Magento/MediaContentUi/etc/adminhtml/di.xml +++ b/app/code/Magento/MediaContentUi/etc/adminhtml/di.xml @@ -10,6 +10,7 @@ Magento\MediaContentUi\Model\SearchCriteria\CollectionProcessor\FilterProcessor\ContentStatus + Magento\MediaContentUi\Model\SearchCriteria\CollectionProcessor\FilterProcessor\StoreView @@ -18,4 +19,9 @@ Magento\MediaContent\Model\GetAssetIdByContentStatusComposite + + + Magento\MediaContent\Model\GetAssetIdByContentStoreComposite + + diff --git a/app/code/Magento/MediaContentUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml b/app/code/Magento/MediaContentUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml index fe6ccd94cd0b1..2cf209d8b6210 100644 --- a/app/code/Magento/MediaContentUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml +++ b/app/code/Magento/MediaContentUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml @@ -17,6 +17,17 @@ content_status + + + 0 + + + store_id + + componentType = column, index = ${ $.index }:visible + + + From 279cf2df2432dc71a6fdab767bcefd8dd91909c8 Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Thu, 9 Jul 2020 14:14:45 +0100 Subject: [PATCH 06/20] Removed MediaContentUi from core repo --- app/code/Magento/MediaContentUi/LICENSE.txt | 48 ------------------- .../Magento/MediaContentUi/LICENSE_AFL.txt | 48 ------------------- .../FilterProcessor/ContentStatus.php | 47 ------------------ .../FilterProcessor/StoreView.php | 47 ------------------ app/code/Magento/MediaContentUi/README.md | 13 ----- .../Listing/Filters/Options/Status.php | 27 ----------- app/code/Magento/MediaContentUi/composer.json | 24 ---------- .../MediaContentUi/etc/adminhtml/di.xml | 27 ----------- .../Magento/MediaContentUi/etc/module.xml | 10 ---- .../Magento/MediaContentUi/registration.php | 9 ---- .../ui_component/media_gallery_listing.xml | 22 --------- .../standalone_media_gallery_listing.xml | 33 ------------- 12 files changed, 355 deletions(-) delete mode 100644 app/code/Magento/MediaContentUi/LICENSE.txt delete mode 100644 app/code/Magento/MediaContentUi/LICENSE_AFL.txt delete mode 100644 app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/ContentStatus.php delete mode 100644 app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/StoreView.php delete mode 100644 app/code/Magento/MediaContentUi/README.md delete mode 100644 app/code/Magento/MediaContentUi/Ui/Component/Listing/Filters/Options/Status.php delete mode 100644 app/code/Magento/MediaContentUi/composer.json delete mode 100644 app/code/Magento/MediaContentUi/etc/adminhtml/di.xml delete mode 100644 app/code/Magento/MediaContentUi/etc/module.xml delete mode 100644 app/code/Magento/MediaContentUi/registration.php delete mode 100644 app/code/Magento/MediaContentUi/view/adminhtml/ui_component/media_gallery_listing.xml delete mode 100644 app/code/Magento/MediaContentUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml diff --git a/app/code/Magento/MediaContentUi/LICENSE.txt b/app/code/Magento/MediaContentUi/LICENSE.txt deleted file mode 100644 index 49525fd99da9c..0000000000000 --- a/app/code/Magento/MediaContentUi/LICENSE.txt +++ /dev/null @@ -1,48 +0,0 @@ - -Open Software License ("OSL") v. 3.0 - -This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: - -Licensed under the Open Software License version 3.0 - - 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: - - 1. to reproduce the Original Work in copies, either alone or as part of a collective work; - - 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; - - 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License; - - 4. to perform the Original Work publicly; and - - 5. to display the Original Work publicly. - - 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. - - 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. - - 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. - - 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). - - 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. - - 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. - - 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. - - 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). - - 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. - - 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. - - 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. - - 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. - - 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. - - 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. - - 16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. \ No newline at end of file diff --git a/app/code/Magento/MediaContentUi/LICENSE_AFL.txt b/app/code/Magento/MediaContentUi/LICENSE_AFL.txt deleted file mode 100644 index f39d641b18a19..0000000000000 --- a/app/code/Magento/MediaContentUi/LICENSE_AFL.txt +++ /dev/null @@ -1,48 +0,0 @@ - -Academic Free License ("AFL") v. 3.0 - -This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: - -Licensed under the Academic Free License version 3.0 - - 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: - - 1. to reproduce the Original Work in copies, either alone or as part of a collective work; - - 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; - - 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License; - - 4. to perform the Original Work publicly; and - - 5. to display the Original Work publicly. - - 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. - - 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. - - 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. - - 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). - - 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. - - 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. - - 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. - - 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). - - 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. - - 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. - - 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. - - 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. - - 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. - - 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. - - 16. Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. diff --git a/app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/ContentStatus.php b/app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/ContentStatus.php deleted file mode 100644 index 3a18103b640f2..0000000000000 --- a/app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/ContentStatus.php +++ /dev/null @@ -1,47 +0,0 @@ -getAssetIdByContentStatus = $getAssetIdByContentStatus; - } - - /** - * @inheritDoc - */ - public function apply(Filter $filter, AbstractDb $collection): bool - { - $collection->addFieldToFilter( - self::TABLE_ALIAS . '.id', - ['in' => $this->getAssetIdByContentStatus->execute($filter->getValue())] - ); - - return true; - } - -} diff --git a/app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/StoreView.php b/app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/StoreView.php deleted file mode 100644 index ad445c24986cb..0000000000000 --- a/app/code/Magento/MediaContentUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/StoreView.php +++ /dev/null @@ -1,47 +0,0 @@ -getAssetIdByContentStatus = $getAssetIdByContentStatus; - } - - /** - * @inheritDoc - */ - public function apply(Filter $filter, AbstractDb $collection): bool - { - $collection->addFieldToFilter( - self::TABLE_ALIAS . '.id', - ['in' => $this->getAssetIdByContentStatus->execute($filter->getValue())] - ); - - return true; - } - -} diff --git a/app/code/Magento/MediaContentUi/README.md b/app/code/Magento/MediaContentUi/README.md deleted file mode 100644 index 2145d9c328914..0000000000000 --- a/app/code/Magento/MediaContentUi/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Magento_MediaContentUi module - -The Magento_MediaContentUi module is responsible for the media content user interface (UI) implementation. - -## Extensibility - -Extension developers can interact with the Magento_MediaContentUi module. For more information about the Magento extension mechanism, see [Magento plug-ins](https://devdocs.magento.com/guides/v2.4/extension-dev-guide/plugins.html). - -[The Magento dependency injection mechanism](https://devdocs.magento.com/guides/v2.4/extension-dev-guide/depend-inj.html) enables you to override the functionality of the Magento_MediaContentUi module. - -## Additional information - -For information about significant changes in patch releases, see [2.3.x Release information](https://devdocs.magento.com/guides/v2.4/release-notes/bk-release-notes.html). diff --git a/app/code/Magento/MediaContentUi/Ui/Component/Listing/Filters/Options/Status.php b/app/code/Magento/MediaContentUi/Ui/Component/Listing/Filters/Options/Status.php deleted file mode 100644 index 4ac4161453d17..0000000000000 --- a/app/code/Magento/MediaContentUi/Ui/Component/Listing/Filters/Options/Status.php +++ /dev/null @@ -1,27 +0,0 @@ - '1', 'label' => __('Enabled')], - ['value' => '0', 'label' => __('Disabled')] - ]; - } -} diff --git a/app/code/Magento/MediaContentUi/composer.json b/app/code/Magento/MediaContentUi/composer.json deleted file mode 100644 index 67b92f925d11d..0000000000000 --- a/app/code/Magento/MediaContentUi/composer.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "magento/module-media-content-ui", - "description": "Magento module responsible for media content user interface", - "require": { - "php": "~7.3.0||~7.4.0", - "magento/framework": "*", - "magento/module-media-content-api": "*", - "magento/module-media-content": "*", - "magento/module-media-gallery-ui": "*" - }, - "type": "magento2-module", - "license": [ - "OSL-3.0", - "AFL-3.0" - ], - "autoload": { - "files": [ - "registration.php" - ], - "psr-4": { - "Magento\\MediaContentUi\\": "" - } - } -} diff --git a/app/code/Magento/MediaContentUi/etc/adminhtml/di.xml b/app/code/Magento/MediaContentUi/etc/adminhtml/di.xml deleted file mode 100644 index e36e2f1305035..0000000000000 --- a/app/code/Magento/MediaContentUi/etc/adminhtml/di.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - Magento\MediaContentUi\Model\SearchCriteria\CollectionProcessor\FilterProcessor\ContentStatus - Magento\MediaContentUi\Model\SearchCriteria\CollectionProcessor\FilterProcessor\StoreView - - - - - - Magento\MediaContent\Model\GetAssetIdByContentStatusComposite - - - - - Magento\MediaContent\Model\GetAssetIdByContentStoreComposite - - - diff --git a/app/code/Magento/MediaContentUi/etc/module.xml b/app/code/Magento/MediaContentUi/etc/module.xml deleted file mode 100644 index 3f615d11ae2ff..0000000000000 --- a/app/code/Magento/MediaContentUi/etc/module.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - diff --git a/app/code/Magento/MediaContentUi/registration.php b/app/code/Magento/MediaContentUi/registration.php deleted file mode 100644 index 5f55c31a5936c..0000000000000 --- a/app/code/Magento/MediaContentUi/registration.php +++ /dev/null @@ -1,9 +0,0 @@ - - -- - - - - - - All - content_status - - - - - diff --git a/app/code/Magento/MediaContentUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml b/app/code/Magento/MediaContentUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml deleted file mode 100644 index 2cf209d8b6210..0000000000000 --- a/app/code/Magento/MediaContentUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml +++ /dev/null @@ -1,33 +0,0 @@ - - -- - - - - - - All - content_status - - - - - 0 - - - store_id - - componentType = column, index = ${ $.index }:visible - - - - - - From 11082e79ed5547da5bd9db408c987ae1e3374722 Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Thu, 9 Jul 2020 14:56:59 +0100 Subject: [PATCH 07/20] Refactor of category store class and removed unecessary stuff --- .../GetAssetIdByContentFieldComposite.php | 1 + .../Model/GetAssetIdByCategoryStore.php | 50 +++++++++++++------ .../Model/GetAssetIdByProductStore.php | 5 +- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php b/app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php index b36b112286a8f..eab2bd05394e1 100644 --- a/app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php +++ b/app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php @@ -36,6 +36,7 @@ public function execute(string $value): array { $ids = []; foreach ($this->getAssetIdByContentFieldArray as $getAssetIdByContentField) { + // phpcs:ignore Magento2.Performance.ForeachArrayMerge $ids = array_merge($ids, $getAssetIdByContentField->execute($value)); } return array_unique($ids); diff --git a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByCategoryStore.php b/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByCategoryStore.php index f6f0d3090a9af..cea27a59a44a5 100644 --- a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByCategoryStore.php +++ b/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByCategoryStore.php @@ -7,6 +7,7 @@ namespace Magento\MediaContentCatalog\Model; +use Magento\Catalog\Api\CategoryManagementInterface; use Magento\Framework\App\ResourceConnection; use Magento\Framework\Exception\LocalizedException; use Magento\MediaContentApi\Model\GetAssetIdByContentFieldInterface; @@ -14,11 +15,12 @@ use Magento\Store\Api\StoreRepositoryInterface; /** - * Class responsible to return Asset id by content field + * Class responsible to return Asset id by category store */ class GetAssetIdByCategoryStore implements GetAssetIdByContentFieldInterface { private const TABLE_CONTENT_ASSET = 'media_content_asset'; + private const TABLE_CATALOG_CATEGORY = 'catalog_category_entity'; /** * @var ResourceConnection @@ -67,7 +69,7 @@ public function execute(string $value): array { $storeView = $this->storeRepository->getById($value); $storeGroup = $this->storeGroupRepository->get($storeView->getStoreGroupId()); - $categoryIds = $this->getCategoryIdsByRootCategory($storeGroup->getRootCategoryId()); + $categoryIds = $this->getCategoryIdsByRootCategory((int) $storeGroup->getRootCategoryId()); $sql = $this->connection->getConnection()->select()->from( ['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)], ['asset_id'] @@ -86,21 +88,15 @@ public function execute(string $value): array }, $result); } - private function getCategoryIdsByRootCategory($rootCategoryId) + /** + * This function returns an array of category ids that have content and are under the root parameter + * + * @param $rootCategoryId + * @return array + */ + private function getCategoryIdsByRootCategory(int $rootCategoryId): array { - $contentCategoriesSql = $this->connection->getConnection()->select()->from( - ['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)], - ['entity_id'] - )->where( - 'entity_type = ?', - $this->entityType - )->joinInner( - ['category_table' => $this->connection->getTableName('catalog_category_entity')], - 'asset_content_table.entity_id = category_table.entity_id', - ['path'] - ); - - $result = $this->connection->getConnection()->fetchAll($contentCategoriesSql); + $result = $this->getCategoryIdsAndPath(); $result = array_filter($result, function ($item) use ($rootCategoryId) { $pathArray = explode("/", $item['path']); @@ -117,4 +113,26 @@ private function getCategoryIdsByRootCategory($rootCategoryId) return $item['entity_id']; }, $result); } + + /** + * This function returns an array of category_id and path of categories that have content + * + * @return array + */ + private function getCategoryIdsAndPath(): array + { + $contentCategoriesSql = $this->connection->getConnection()->select()->from( + ['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)], + ['entity_id'] + )->where( + 'entity_type = ?', + $this->entityType + )->joinInner( + ['category_table' => $this->connection->getTableName(self::TABLE_CATALOG_CATEGORY)], + 'asset_content_table.entity_id = category_table.entity_id', + ['path'] + ); + + return $this->connection->getConnection()->fetchAll($contentCategoriesSql); + } } diff --git a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php b/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php index a13da8d501903..3772b56f82d0f 100644 --- a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php +++ b/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php @@ -13,14 +13,11 @@ use Magento\Store\Api\StoreRepositoryInterface; /** - * Class responsible to return Asset id by content field + * Class responsible to return Asset ids by product store */ class GetAssetIdByProductStore implements GetAssetIdByContentFieldInterface { private const TABLE_CONTENT_ASSET = 'media_content_asset'; - private const ENTITY_STOREVIEW_RELATION = 'store_view'; - private const ENTITY_STOREGROUP_RELATION = 'store_group'; - private const ENTITY_WEBSITE_RELATION = 'website'; /** * @var ResourceConnection From e0a777b1adaff963434d7acc228b897d16ddb762 Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Thu, 9 Jul 2020 15:07:09 +0100 Subject: [PATCH 08/20] Removed contruct params and added constants --- .../Model/GetAssetIdByCategoryStore.php | 11 ++---- .../Model/GetAssetIdByProductStore.php | 36 +++++-------------- 2 files changed, 11 insertions(+), 36 deletions(-) diff --git a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByCategoryStore.php b/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByCategoryStore.php index cea27a59a44a5..7194bbc382539 100644 --- a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByCategoryStore.php +++ b/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByCategoryStore.php @@ -21,6 +21,7 @@ class GetAssetIdByCategoryStore implements GetAssetIdByContentFieldInterface { private const TABLE_CONTENT_ASSET = 'media_content_asset'; private const TABLE_CATALOG_CATEGORY = 'catalog_category_entity'; + private const ENTITY_TYPE = 'catalog_category'; /** * @var ResourceConnection @@ -37,11 +38,6 @@ class GetAssetIdByCategoryStore implements GetAssetIdByContentFieldInterface */ private $storeGroupRepository; - /** - * @var string - */ - private $entityType; - /** * GetAssetIdByProductStore constructor. * @@ -57,7 +53,6 @@ public function __construct( $this->connection = $resource; $this->storeRepository = $storeRepository; $this->storeGroupRepository = $storeGroupRepository; - $this->entityType = 'catalog_category'; } /** @@ -75,7 +70,7 @@ public function execute(string $value): array ['asset_id'] )->where( 'entity_type = ?', - $this->entityType + self::ENTITY_TYPE )->where( 'entity_id IN (?)', $categoryIds @@ -126,7 +121,7 @@ private function getCategoryIdsAndPath(): array ['entity_id'] )->where( 'entity_type = ?', - $this->entityType + self::ENTITY_TYPE )->joinInner( ['category_table' => $this->connection->getTableName(self::TABLE_CATALOG_CATEGORY)], 'asset_content_table.entity_id = category_table.entity_id', diff --git a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php b/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php index 3772b56f82d0f..2e4b7620e52eb 100644 --- a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php +++ b/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php @@ -18,6 +18,10 @@ class GetAssetIdByProductStore implements GetAssetIdByContentFieldInterface { private const TABLE_CONTENT_ASSET = 'media_content_asset'; + private const ENTITY_TYPE = 'catalog_product'; + private const FIELD_TABLE = 'catalog_product_website'; + private const ID_COLUMN = 'product_id'; + private const FIELD_COLUMN = 'website_id'; /** * @var ResourceConnection @@ -29,26 +33,6 @@ class GetAssetIdByProductStore implements GetAssetIdByContentFieldInterface */ private $storeRepository; - /** - * @var string - */ - private $entityType; - - /** - * @var string - */ - private $fieldTable; - - /** - * @var string - */ - private $fieldColumn; - - /** - * @var string - */ - private $idColumn; - /** * GetAssetIdByProductStore constructor. * @@ -61,10 +45,6 @@ public function __construct( ) { $this->connection = $resource; $this->storeRepository = $storeRepository; - $this->entityType = 'catalog_product'; - $this->fieldTable = 'catalog_product_website'; - $this->idColumn = 'product_id'; - $this->fieldColumn = 'website_id'; } /** @@ -80,13 +60,13 @@ public function execute(string $value): array ['asset_id'] )->where( 'entity_type = ?', - $this->entityType + self::ENTITY_TYPE )->joinInner( - ['field_table' => $this->connection->getTableName($this->fieldTable)], - 'asset_content_table.entity_id = field_table.' . $this->idColumn, + ['field_table' => $this->connection->getTableName(self::FIELD_TABLE)], + 'asset_content_table.entity_id = field_table.' . self::ID_COLUMN, [] )->where( - 'field_table.' . $this->fieldColumn . ' = ?', + 'field_table.' . self::FIELD_COLUMN . ' = ?', $store->getWebsiteId() ); From 89551473a49496ac547d27bf8ffc69981f976389 Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Fri, 10 Jul 2020 11:12:19 +0100 Subject: [PATCH 09/20] Implemented suggestions --- .../GetAssetIdByContentFieldComposite.php | 12 ++++++--- app/code/Magento/MediaContent/etc/di.xml | 3 +-- .../Api/GetAssetIdByContentFieldInterface.php | 27 +++++++++++++++++++ .../GetAssetIdByContentFieldInterface.php | 5 ++++ .../Model/GetAssetIdByCategoryStore.php | 8 +----- .../Model/GetAssetIdByEavContentField.php | 7 +---- .../Model/GetAssetIdByProductStore.php | 8 +----- .../Magento/MediaContentCatalog/composer.json | 1 - .../Magento/MediaContentCatalog/etc/di.xml | 20 ++++++++------ .../Model/GetAssetIdByContentField.php | 9 +------ .../Magento/MediaContentCms/composer.json | 1 - app/code/Magento/MediaContentCms/etc/di.xml | 20 ++++++++------ 12 files changed, 70 insertions(+), 51 deletions(-) create mode 100644 app/code/Magento/MediaContentApi/Api/GetAssetIdByContentFieldInterface.php diff --git a/app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php b/app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php index eab2bd05394e1..577ea6898f665 100644 --- a/app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php +++ b/app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php @@ -7,12 +7,15 @@ namespace Magento\MediaContent\Model; +use Magento\Framework\Exception\InvalidArgumentException; +use Magento\Framework\Exception\LocalizedException; +use Magento\MediaContentApi\Api\GetAssetIdByContentFieldInterface as GetAssetIdByContentFieldApiInterface; use Magento\MediaContentApi\Model\GetAssetIdByContentFieldInterface; /** * Class responsible to return Asset ids by content field */ -class GetAssetIdByContentFieldComposite implements GetAssetIdByContentFieldInterface +class GetAssetIdByContentFieldComposite implements GetAssetIdByContentFieldApiInterface { /** * @var GetAssetIdByContentFieldInterface[] @@ -32,10 +35,13 @@ public function __construct($getAssetIdByContentFieldArray = []) /** * @inheritDoc */ - public function execute(string $value): array + public function execute(string $field, string $value): array { + if (!array_key_exists($field, $this->getAssetIdByContentFieldArray)) { + throw new InvalidArgumentException(__('The field argument is invalid.')); + } $ids = []; - foreach ($this->getAssetIdByContentFieldArray as $getAssetIdByContentField) { + foreach ($this->getAssetIdByContentFieldArray[$field] as $getAssetIdByContentField) { // phpcs:ignore Magento2.Performance.ForeachArrayMerge $ids = array_merge($ids, $getAssetIdByContentField->execute($value)); } diff --git a/app/code/Magento/MediaContent/etc/di.xml b/app/code/Magento/MediaContent/etc/di.xml index bfce45c797a1a..4817c262e0bd1 100644 --- a/app/code/Magento/MediaContent/etc/di.xml +++ b/app/code/Magento/MediaContent/etc/di.xml @@ -16,6 +16,7 @@ + @@ -43,6 +44,4 @@ Magento\MediaContent\Model\Content\Config\Data - - diff --git a/app/code/Magento/MediaContentApi/Api/GetAssetIdByContentFieldInterface.php b/app/code/Magento/MediaContentApi/Api/GetAssetIdByContentFieldInterface.php new file mode 100644 index 0000000000000..f66c7ffe4bc05 --- /dev/null +++ b/app/code/Magento/MediaContentApi/Api/GetAssetIdByContentFieldInterface.php @@ -0,0 +1,27 @@ +connection->getConnection()->fetchAll($sql); - - return array_map(function ($item) { - return $item['asset_id']; - }, $result); + return $this->connection->getConnection()->fetchCol($sql); } /** diff --git a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByEavContentField.php b/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByEavContentField.php index 91c42df7d76dd..c1560331a78ee 100644 --- a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByEavContentField.php +++ b/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByEavContentField.php @@ -68,7 +68,6 @@ public function __construct( /** * @inheritDoc - * @throws \Magento\Framework\Exception\LocalizedException */ public function execute(string $value): array { @@ -91,11 +90,7 @@ public function execute(string $value): array $this->getValueFromMap($value) ); - $result = $this->connection->getConnection()->fetchAll($sql); - - return array_map(function ($item) { - return $item['asset_id']; - }, $result); + return $this->connection->getConnection()->fetchCol($sql); } /** diff --git a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php b/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php index 2e4b7620e52eb..141198dc3e8df 100644 --- a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php +++ b/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php @@ -49,8 +49,6 @@ public function __construct( /** * @inheritDoc - * @throws LocalizedException - * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function execute(string $value): array { @@ -70,10 +68,6 @@ public function execute(string $value): array $store->getWebsiteId() ); - $result = $this->connection->getConnection()->fetchAll($sql); - - return array_map(function ($item) { - return $item['asset_id']; - }, $result); + return $this->connection->getConnection()->fetchCol($sql); } } diff --git a/app/code/Magento/MediaContentCatalog/composer.json b/app/code/Magento/MediaContentCatalog/composer.json index da592c2bf11be..2b19bc95f6ed3 100644 --- a/app/code/Magento/MediaContentCatalog/composer.json +++ b/app/code/Magento/MediaContentCatalog/composer.json @@ -4,7 +4,6 @@ "require": { "php": "~7.3.0||~7.4.0", "magento/module-media-content-api": "*", - "magento/module-media-content": "*", "magento/module-catalog": "*", "magento/module-eav": "*", "magento/module-store": "*", diff --git a/app/code/Magento/MediaContentCatalog/etc/di.xml b/app/code/Magento/MediaContentCatalog/etc/di.xml index 2bc595151ddfe..adbddaa25a122 100644 --- a/app/code/Magento/MediaContentCatalog/etc/di.xml +++ b/app/code/Magento/MediaContentCatalog/etc/di.xml @@ -62,20 +62,24 @@ catalog_category - + - Magento\MediaContentCatalog\Model\GetAssetIdByProductStatus - Magento\MediaContentCatalog\Model\GetAssetIdByCategoryStatus + + Magento\MediaContentCatalog\Model\GetAssetIdByProductStatus + Magento\MediaContentCatalog\Model\GetAssetIdByCategoryStatus + - - + + - Magento\MediaContentCatalog\Model\GetAssetIdByProductStore - Magento\MediaContentCatalog\Model\GetAssetIdByCategoryStore + + Magento\MediaContentCatalog\Model\GetAssetIdByProductStore + Magento\MediaContentCatalog\Model\GetAssetIdByCategoryStore + - + diff --git a/app/code/Magento/MediaContentCms/Model/GetAssetIdByContentField.php b/app/code/Magento/MediaContentCms/Model/GetAssetIdByContentField.php index cb10a097e59ac..611fcb0fde1e1 100644 --- a/app/code/Magento/MediaContentCms/Model/GetAssetIdByContentField.php +++ b/app/code/Magento/MediaContentCms/Model/GetAssetIdByContentField.php @@ -8,9 +8,7 @@ namespace Magento\MediaContentCms\Model; use Magento\Framework\App\ResourceConnection; -use Magento\Framework\Exception\LocalizedException; use Magento\MediaContentApi\Model\GetAssetIdByContentFieldInterface; -use Magento\Store\Api\StoreRepositoryInterface; /** * Class responsible to return Asset id by content field @@ -44,7 +42,6 @@ class GetAssetIdByContentField implements GetAssetIdByContentFieldInterface */ private $idColumn; - /** * GetAssetIdByContentField constructor. * @@ -88,10 +85,6 @@ public function execute(string $value): array $value ); - $result = $this->connection->getConnection()->fetchAll($sql); - - return array_map(function ($item) { - return $item['asset_id']; - }, $result); + return $this->connection->getConnection()->fetchCol($sql); } } diff --git a/app/code/Magento/MediaContentCms/composer.json b/app/code/Magento/MediaContentCms/composer.json index ff8bff348770b..ea32fdd7a49fa 100644 --- a/app/code/Magento/MediaContentCms/composer.json +++ b/app/code/Magento/MediaContentCms/composer.json @@ -4,7 +4,6 @@ "require": { "php": "~7.3.0||~7.4.0", "magento/module-media-content-api": "*", - "magento/module-media-content": "*", "magento/module-cms": "*", "magento/framework": "*" }, diff --git a/app/code/Magento/MediaContentCms/etc/di.xml b/app/code/Magento/MediaContentCms/etc/di.xml index dc633b95d0517..a673cf59e2127 100644 --- a/app/code/Magento/MediaContentCms/etc/di.xml +++ b/app/code/Magento/MediaContentCms/etc/di.xml @@ -66,20 +66,24 @@ is_active - + - Magento\MediaContentCms\Model\GetAssetIdByPageStatus - Magento\MediaContentCms\Model\GetAssetIdByBlockStatus + + Magento\MediaContentCms\Model\GetAssetIdByPageStatus + Magento\MediaContentCms\Model\GetAssetIdByBlockStatus + - - + + - Magento\MediaContentCms\Model\GetAssetIdByPageStore - Magento\MediaContentCms\Model\GetAssetIdByBlockStore + + Magento\MediaContentCms\Model\GetAssetIdByPageStore + Magento\MediaContentCms\Model\GetAssetIdByBlockStore + - + From 545f886e6b97b30f083592d05c589239aa07ab6b Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Fri, 10 Jul 2020 15:58:34 +0100 Subject: [PATCH 10/20] Added integration tests --- .../GetAssetIdByContentFieldComposite.php | 1 + .../GetAssetIdByContentFieldTest.php | 101 ++++++++++++++++++ .../GetAssetIdByContentFieldTest.php | 87 +++++++++++++++ 3 files changed, 189 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdByContentFieldTest.php create mode 100644 dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdByContentFieldTest.php diff --git a/app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php b/app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php index 577ea6898f665..57bf5d6458577 100644 --- a/app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php +++ b/app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php @@ -41,6 +41,7 @@ public function execute(string $field, string $value): array throw new InvalidArgumentException(__('The field argument is invalid.')); } $ids = []; + /** @var GetAssetIdByContentFieldInterface $getAssetIdByContentField */ foreach ($this->getAssetIdByContentFieldArray[$field] as $getAssetIdByContentField) { // phpcs:ignore Magento2.Performance.ForeachArrayMerge $ids = array_merge($ids, $getAssetIdByContentField->execute($value)); diff --git a/dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdByContentFieldTest.php b/dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdByContentFieldTest.php new file mode 100644 index 0000000000000..7ca595a72f1f4 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdByContentFieldTest.php @@ -0,0 +1,101 @@ +storeId = $objectManager->get(StoreManagerInterface::class)->getStore()->getId(); + $this->getAssetIdByContentField = $objectManager->get(GetAssetIdByContentFieldInterface::class); + } + + /** + * Test for getting asset id by store view of a category + * + * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php + * @magentoDataFixture Magento/MediaContentCatalog/_files/category_with_asset.php + */ + public function testCategoryStoreView(): void + { + $this->assertEquals( + [2020], + $this->getAssetIdByContentField->execute(self::STORE_FIELD, (string)$this->storeId) + ); + } + + /** + * Test for getting asset id by store view of a product + * + * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php + * @magentoDataFixture Magento/MediaContentCatalog/_files/product_with_asset.php + */ + public function testProductStoreView(): void + { + $this->assertEquals( + [2020], + $this->getAssetIdByContentField->execute(self::STORE_FIELD, (string)$this->storeId) + ); + } + + /** + * Test for getting asset id by enabled status of a product + * + * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php + * @magentoDataFixture Magento/MediaContentCatalog/_files/category_with_asset.php + */ + public function testProductStatusEnabled(): void + { + $this->assertEquals( + [2020], + $this->getAssetIdByContentField->execute(self::STATUS_FIELD, self::STATUS_ENABLED) + ); + } + + /** + * Test for getting asset id by disabled status of a product + * + * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php + * @magentoDataFixture Magento/MediaContentCatalog/_files/product_with_asset.php + */ + public function testProductStatusDisabled(): void + { + $this->assertEquals( + [], + $this->getAssetIdByContentField->execute(self::STATUS_FIELD, self::STATUS_DISABLED) + ); + } +} diff --git a/dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdByContentFieldTest.php b/dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdByContentFieldTest.php new file mode 100644 index 0000000000000..33eb4f2dcff41 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdByContentFieldTest.php @@ -0,0 +1,87 @@ +storeId = $objectManager->get(StoreManagerInterface::class)->getStore()->getId(); + $this->getAssetIdByContentField = $objectManager->get(GetAssetIdByContentFieldInterface::class); + } + + /** + * Test for getting asset id by store view of a block + * + * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php + * @magentoDataFixture Magento/MediaContentCms/_files/block_with_asset.php + */ + public function testBlockStoreView(): void + { + $this->assertEquals( + [2020], + $this->getAssetIdByContentField->execute(self::STORE_FIELD, (string)$this->storeId) + ); + } + + /** + * Test for getting asset id by enabled status of a page + * + * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php + * @magentoDataFixture Magento/MediaContentCms/_files/page_with_asset.php + */ + public function testPageStatusEnabled(): void + { + $this->assertEquals( + [2020], + $this->getAssetIdByContentField->execute(self::STATUS_FIELD, self::STATUS_ENABLED) + ); + } + + /** + * Test for getting asset id by disabled status of a page + * + * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php + * @magentoDataFixture Magento/MediaContentCms/_files/page_with_asset.php + */ + public function testPageStatusDisabled(): void + { + $this->assertEquals( + [], + $this->getAssetIdByContentField->execute(self::STATUS_FIELD, self::STATUS_DISABLED) + ); + } +} From 5f82525415fb2cc76ee4dc08e9cc0ce995762ffd Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Mon, 13 Jul 2020 10:44:46 +0100 Subject: [PATCH 11/20] Updated names --- .../GetAssetIdByContentFieldComposite.php | 51 ------------------- app/code/Magento/MediaContent/etc/di.xml | 2 +- ...=> GetAssetIdsByContentFieldInterface.php} | 3 +- .../Composite/GetAssetIdsByContentField.php | 50 ++++++++++++++++++ ...=> GetAssetIdsByContentFieldInterface.php} | 2 +- .../GetAssetIdsByCategoryStore.php} | 10 ++-- .../GetAssetIdsByEavContentField.php} | 21 ++++---- .../GetAssetIdsByProductStore.php} | 8 +-- .../Magento/MediaContentCatalog/etc/di.xml | 20 ++++---- .../GetAssetIdsByContentField.php} | 8 +-- app/code/Magento/MediaContentCms/etc/di.xml | 24 ++++----- 11 files changed, 97 insertions(+), 102 deletions(-) delete mode 100644 app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php rename app/code/Magento/MediaContentApi/Api/{GetAssetIdByContentFieldInterface.php => GetAssetIdsByContentFieldInterface.php} (91%) create mode 100644 app/code/Magento/MediaContentApi/Model/Composite/GetAssetIdsByContentField.php rename app/code/Magento/MediaContentApi/Model/{GetAssetIdByContentFieldInterface.php => GetAssetIdsByContentFieldInterface.php} (93%) rename app/code/Magento/MediaContentCatalog/Model/{GetAssetIdByCategoryStore.php => ResourceModel/GetAssetIdsByCategoryStore.php} (92%) rename app/code/Magento/MediaContentCatalog/Model/{GetAssetIdByEavContentField.php => ResourceModel/GetAssetIdsByEavContentField.php} (76%) rename app/code/Magento/MediaContentCatalog/Model/{GetAssetIdByProductStore.php => ResourceModel/GetAssetIdsByProductStore.php} (88%) rename app/code/Magento/MediaContentCms/Model/{GetAssetIdByContentField.php => ResourceModel/GetAssetIdsByContentField.php} (88%) diff --git a/app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php b/app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php deleted file mode 100644 index 57bf5d6458577..0000000000000 --- a/app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php +++ /dev/null @@ -1,51 +0,0 @@ -getAssetIdByContentFieldArray = $getAssetIdByContentFieldArray; - } - - /** - * @inheritDoc - */ - public function execute(string $field, string $value): array - { - if (!array_key_exists($field, $this->getAssetIdByContentFieldArray)) { - throw new InvalidArgumentException(__('The field argument is invalid.')); - } - $ids = []; - /** @var GetAssetIdByContentFieldInterface $getAssetIdByContentField */ - foreach ($this->getAssetIdByContentFieldArray[$field] as $getAssetIdByContentField) { - // phpcs:ignore Magento2.Performance.ForeachArrayMerge - $ids = array_merge($ids, $getAssetIdByContentField->execute($value)); - } - return array_unique($ids); - } -} diff --git a/app/code/Magento/MediaContent/etc/di.xml b/app/code/Magento/MediaContent/etc/di.xml index 4817c262e0bd1..df84ad7bb0f70 100644 --- a/app/code/Magento/MediaContent/etc/di.xml +++ b/app/code/Magento/MediaContent/etc/di.xml @@ -16,7 +16,7 @@ - + diff --git a/app/code/Magento/MediaContentApi/Api/GetAssetIdByContentFieldInterface.php b/app/code/Magento/MediaContentApi/Api/GetAssetIdsByContentFieldInterface.php similarity index 91% rename from app/code/Magento/MediaContentApi/Api/GetAssetIdByContentFieldInterface.php rename to app/code/Magento/MediaContentApi/Api/GetAssetIdsByContentFieldInterface.php index f66c7ffe4bc05..f2f9ddbf11956 100644 --- a/app/code/Magento/MediaContentApi/Api/GetAssetIdByContentFieldInterface.php +++ b/app/code/Magento/MediaContentApi/Api/GetAssetIdsByContentFieldInterface.php @@ -10,10 +10,9 @@ use Magento\Framework\Exception\InvalidArgumentException; /** - * @api * Interface used to return Asset id by content field. */ -interface GetAssetIdByContentFieldInterface +interface GetAssetIdsByContentFieldInterface { /** * This function returns asset ids by content field diff --git a/app/code/Magento/MediaContentApi/Model/Composite/GetAssetIdsByContentField.php b/app/code/Magento/MediaContentApi/Model/Composite/GetAssetIdsByContentField.php new file mode 100644 index 0000000000000..7130bee56d90a --- /dev/null +++ b/app/code/Magento/MediaContentApi/Model/Composite/GetAssetIdsByContentField.php @@ -0,0 +1,50 @@ +fieldHandlers = $fieldHandlers; + } + + /** + * @inheritDoc + */ + public function execute(string $field, string $value): array + { + if (!array_key_exists($field, $this->fieldHandlers)) { + throw new InvalidArgumentException(__('The field argument is invalid.')); + } + $ids = []; + /** @var GetAssetIdsByContentFieldInterface $fieldHandlers */ + foreach ($this->fieldHandlers[$field] as $fieldHandlers) { + // phpcs:ignore Magento2.Performance.ForeachArrayMerge + $ids = array_merge($ids, $fieldHandlers->execute($value)); + } + return array_unique($ids); + } +} diff --git a/app/code/Magento/MediaContentApi/Model/GetAssetIdByContentFieldInterface.php b/app/code/Magento/MediaContentApi/Model/GetAssetIdsByContentFieldInterface.php similarity index 93% rename from app/code/Magento/MediaContentApi/Model/GetAssetIdByContentFieldInterface.php rename to app/code/Magento/MediaContentApi/Model/GetAssetIdsByContentFieldInterface.php index 410b2aaceb60c..f38ffecedc202 100644 --- a/app/code/Magento/MediaContentApi/Model/GetAssetIdByContentFieldInterface.php +++ b/app/code/Magento/MediaContentApi/Model/GetAssetIdsByContentFieldInterface.php @@ -13,7 +13,7 @@ /** * Interface used to return Asset id by content field. */ -interface GetAssetIdByContentFieldInterface +interface GetAssetIdsByContentFieldInterface { /** * This function returns asset ids by content field diff --git a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByCategoryStore.php b/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByCategoryStore.php similarity index 92% rename from app/code/Magento/MediaContentCatalog/Model/GetAssetIdByCategoryStore.php rename to app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByCategoryStore.php index da6b08a062269..386bc659ab681 100644 --- a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByCategoryStore.php +++ b/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByCategoryStore.php @@ -5,19 +5,19 @@ */ declare(strict_types=1); -namespace Magento\MediaContentCatalog\Model; +namespace Magento\MediaContentCatalog\Model\ResourceModel; use Magento\Catalog\Api\CategoryManagementInterface; use Magento\Framework\App\ResourceConnection; use Magento\Framework\Exception\LocalizedException; -use Magento\MediaContentApi\Model\GetAssetIdByContentFieldInterface; +use Magento\MediaContentApi\Model\GetAssetIdsByContentFieldInterface; use Magento\Store\Api\GroupRepositoryInterface; use Magento\Store\Api\StoreRepositoryInterface; /** * Class responsible to return Asset id by category store */ -class GetAssetIdByCategoryStore implements GetAssetIdByContentFieldInterface +class GetAssetIdsByCategoryStore implements GetAssetIdsByContentFieldInterface { private const TABLE_CONTENT_ASSET = 'media_content_asset'; private const TABLE_CATALOG_CATEGORY = 'catalog_category_entity'; @@ -39,7 +39,7 @@ class GetAssetIdByCategoryStore implements GetAssetIdByContentFieldInterface private $storeGroupRepository; /** - * GetAssetIdByProductStore constructor. + * GetAssetIdsByCategoryStore constructor. * * @param ResourceConnection $resource * @param StoreRepositoryInterface $storeRepository @@ -88,7 +88,7 @@ private function getCategoryIdsByRootCategory(int $rootCategoryId): array $result = $this->getCategoryIdsAndPath(); $result = array_filter($result, function ($item) use ($rootCategoryId) { - $pathArray = explode("/", $item['path']); + $pathArray = explode('/', $item['path']); $isInPath = false; foreach ($pathArray as $id) { if ($id == $rootCategoryId) { diff --git a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByEavContentField.php b/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByEavContentField.php similarity index 76% rename from app/code/Magento/MediaContentCatalog/Model/GetAssetIdByEavContentField.php rename to app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByEavContentField.php index c1560331a78ee..1be610e1fea77 100644 --- a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByEavContentField.php +++ b/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByEavContentField.php @@ -5,16 +5,16 @@ */ declare(strict_types=1); -namespace Magento\MediaContentCatalog\Model; +namespace Magento\MediaContentCatalog\Model\ResourceModel; use Magento\Eav\Model\Config; use Magento\Framework\App\ResourceConnection; -use Magento\MediaContentApi\Model\GetAssetIdByContentFieldInterface; +use Magento\MediaContentApi\Model\GetAssetIdsByContentFieldInterface; /** * Class responsible to return Asset id by eav content field */ -class GetAssetIdByEavContentField implements GetAssetIdByContentFieldInterface +class GetAssetIdsByEavContentField implements GetAssetIdsByContentFieldInterface { private const TABLE_CONTENT_ASSET = 'media_content_asset'; @@ -44,7 +44,7 @@ class GetAssetIdByEavContentField implements GetAssetIdByContentFieldInterface private $valueMap; /** - * GetAssetIdByEavContentStatus constructor. + * GetAssetIdsByEavContentField constructor. * * @param ResourceConnection $resource * @param Config $config @@ -71,7 +71,7 @@ public function __construct( */ public function execute(string $value): array { - $statusAttribute = $this->config->getAttribute($this->entityType, $this->attributeCode); + $attribute = $this->config->getAttribute($this->entityType, $this->attributeCode); $sql = $this->connection->getConnection()->select()->from( ['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)], @@ -80,10 +80,10 @@ public function execute(string $value): array 'entity_type = ?', $this->entityType )->joinInner( - ['entity_eav_type' => $statusAttribute->getBackendTable()], - 'asset_content_table.entity_id = entity_eav_type.' . $statusAttribute->getEntityIdField() . + ['entity_eav_type' => $attribute->getBackendTable()], + 'asset_content_table.entity_id = entity_eav_type.' . $attribute->getEntityIdField() . ' AND entity_eav_type.attribute_id = ' . - $statusAttribute->getAttributeId(), + $attribute->getAttributeId(), [] )->where( 'entity_eav_type.value = ?', @@ -101,9 +101,6 @@ public function execute(string $value): array */ private function getValueFromMap(string $value): string { - if (count($this->valueMap) > 0 && array_key_exists($value, $this->valueMap)) { - return $this->valueMap[$value]; - } - return $value; + return $this->valueMap[$value] ?? $value; } } diff --git a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php b/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByProductStore.php similarity index 88% rename from app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php rename to app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByProductStore.php index 141198dc3e8df..6548b2964caaf 100644 --- a/app/code/Magento/MediaContentCatalog/Model/GetAssetIdByProductStore.php +++ b/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByProductStore.php @@ -5,17 +5,17 @@ */ declare(strict_types=1); -namespace Magento\MediaContentCatalog\Model; +namespace Magento\MediaContentCatalog\Model\ResourceModel; use Magento\Framework\App\ResourceConnection; use Magento\Framework\Exception\LocalizedException; -use Magento\MediaContentApi\Model\GetAssetIdByContentFieldInterface; +use Magento\MediaContentApi\Model\GetAssetIdsByContentFieldInterface; use Magento\Store\Api\StoreRepositoryInterface; /** * Class responsible to return Asset ids by product store */ -class GetAssetIdByProductStore implements GetAssetIdByContentFieldInterface +class GetAssetIdsByProductStore implements GetAssetIdsByContentFieldInterface { private const TABLE_CONTENT_ASSET = 'media_content_asset'; private const ENTITY_TYPE = 'catalog_product'; @@ -34,7 +34,7 @@ class GetAssetIdByProductStore implements GetAssetIdByContentFieldInterface private $storeRepository; /** - * GetAssetIdByProductStore constructor. + * GetAssetIdsByProductStore constructor. * * @param ResourceConnection $resource * @param StoreRepositoryInterface $storeRepository diff --git a/app/code/Magento/MediaContentCatalog/etc/di.xml b/app/code/Magento/MediaContentCatalog/etc/di.xml index adbddaa25a122..865c72dfa4a5b 100644 --- a/app/code/Magento/MediaContentCatalog/etc/di.xml +++ b/app/code/Magento/MediaContentCatalog/etc/di.xml @@ -46,7 +46,7 @@ - + status catalog_product @@ -56,28 +56,28 @@ - + is_active catalog_category - + - + - Magento\MediaContentCatalog\Model\GetAssetIdByProductStatus - Magento\MediaContentCatalog\Model\GetAssetIdByCategoryStatus + Magento\MediaContentCatalog\Model\ResourceModel\GetAssetIdsByProductStatus + Magento\MediaContentCatalog\Model\ResourceModel\GetAssetIdsByCategoryStatus - + - + - Magento\MediaContentCatalog\Model\GetAssetIdByProductStore - Magento\MediaContentCatalog\Model\GetAssetIdByCategoryStore + Magento\MediaContentCatalog\Model\ResourceModel\GetAssetIdsByProductStore + Magento\MediaContentCatalog\Model\ResourceModel\GetAssetIdsByCategoryStore diff --git a/app/code/Magento/MediaContentCms/Model/GetAssetIdByContentField.php b/app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByContentField.php similarity index 88% rename from app/code/Magento/MediaContentCms/Model/GetAssetIdByContentField.php rename to app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByContentField.php index 611fcb0fde1e1..9c223fd870645 100644 --- a/app/code/Magento/MediaContentCms/Model/GetAssetIdByContentField.php +++ b/app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByContentField.php @@ -5,15 +5,15 @@ */ declare(strict_types=1); -namespace Magento\MediaContentCms\Model; +namespace Magento\MediaContentCms\Model\ResourceModel; use Magento\Framework\App\ResourceConnection; -use Magento\MediaContentApi\Model\GetAssetIdByContentFieldInterface; +use Magento\MediaContentApi\Model\GetAssetIdsByContentFieldInterface; /** * Class responsible to return Asset id by content field */ -class GetAssetIdByContentField implements GetAssetIdByContentFieldInterface +class GetAssetIdsByContentField implements GetAssetIdsByContentFieldInterface { private const TABLE_CONTENT_ASSET = 'media_content_asset'; @@ -43,7 +43,7 @@ class GetAssetIdByContentField implements GetAssetIdByContentFieldInterface private $idColumn; /** - * GetAssetIdByContentField constructor. + * GetAssetIdsByContentField constructor. * * @param ResourceConnection $resource * @param string $entityType diff --git a/app/code/Magento/MediaContentCms/etc/di.xml b/app/code/Magento/MediaContentCms/etc/di.xml index a673cf59e2127..436c2ce94d786 100644 --- a/app/code/Magento/MediaContentCms/etc/di.xml +++ b/app/code/Magento/MediaContentCms/etc/di.xml @@ -34,7 +34,7 @@ - + cms_block cms_block_store @@ -42,7 +42,7 @@ store_id - + cms_page cms_page_store @@ -50,7 +50,7 @@ store_id - + cms_page cms_page @@ -58,7 +58,7 @@ is_active - + cms_block cms_block @@ -66,22 +66,22 @@ is_active - + - + - Magento\MediaContentCms\Model\GetAssetIdByPageStatus - Magento\MediaContentCms\Model\GetAssetIdByBlockStatus + Magento\MediaContentCms\Model\ResourceModel\GetAssetIdsByPageStatus + Magento\MediaContentCms\Model\ResourceModel\GetAssetIdsByBlockStatus - + - + - Magento\MediaContentCms\Model\GetAssetIdByPageStore - Magento\MediaContentCms\Model\GetAssetIdByBlockStore + Magento\MediaContentCms\Model\ResourceModel\GetAssetIdsByPageStore + Magento\MediaContentCms\Model\ResourceModel\GetAssetIdsByBlockStore From aa11cf598727bffcc356ef44e11d1825d2075569 Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Mon, 13 Jul 2020 10:53:25 +0100 Subject: [PATCH 12/20] Updated test names --- ...t.php => GetAssetIdsByContentFieldTest.php} | 18 +++++++++--------- ...t.php => GetAssetIdsByContentFieldTest.php} | 16 ++++++++-------- 2 files changed, 17 insertions(+), 17 deletions(-) rename dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/{GetAssetIdByContentFieldTest.php => GetAssetIdsByContentFieldTest.php} (76%) rename dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/{GetAssetIdByContentFieldTest.php => GetAssetIdsByContentFieldTest.php} (75%) diff --git a/dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdByContentFieldTest.php b/dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByContentFieldTest.php similarity index 76% rename from dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdByContentFieldTest.php rename to dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByContentFieldTest.php index 7ca595a72f1f4..9719c1756f2bc 100644 --- a/dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdByContentFieldTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByContentFieldTest.php @@ -8,7 +8,7 @@ namespace Magento\MediaContentCatalog\Model\ResourceModel; -use Magento\MediaContentApi\Api\GetAssetIdByContentFieldInterface; +use Magento\MediaContentApi\Api\GetAssetIdsByContentFieldInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\TestFramework\Helper\Bootstrap; use PHPUnit\Framework\TestCase; @@ -16,7 +16,7 @@ /** * Test for GetAssetIdByContentFieldTest */ -class GetAssetIdByContentFieldTest extends TestCase +class GetAssetIdsByContentFieldTest extends TestCase { private const STORE_FIELD = 'store_id'; private const STATUS_FIELD = 'content_status'; @@ -24,9 +24,9 @@ class GetAssetIdByContentFieldTest extends TestCase private const STATUS_DISABLED = '0'; /** - * @var GetAssetIdByContentFieldInterface + * @var GetAssetIdsByContentFieldInterface */ - private $getAssetIdByContentField; + private $getAssetIdsByContentField; /** * @var int @@ -40,7 +40,7 @@ protected function setUp(): void { $objectManager = Bootstrap::getObjectManager(); $this->storeId = $objectManager->get(StoreManagerInterface::class)->getStore()->getId(); - $this->getAssetIdByContentField = $objectManager->get(GetAssetIdByContentFieldInterface::class); + $this->getAssetIdsByContentField = $objectManager->get(GetAssetIdsByContentFieldInterface::class); } /** @@ -53,7 +53,7 @@ public function testCategoryStoreView(): void { $this->assertEquals( [2020], - $this->getAssetIdByContentField->execute(self::STORE_FIELD, (string)$this->storeId) + $this->getAssetIdsByContentField->execute(self::STORE_FIELD, (string)$this->storeId) ); } @@ -67,7 +67,7 @@ public function testProductStoreView(): void { $this->assertEquals( [2020], - $this->getAssetIdByContentField->execute(self::STORE_FIELD, (string)$this->storeId) + $this->getAssetIdsByContentField->execute(self::STORE_FIELD, (string)$this->storeId) ); } @@ -81,7 +81,7 @@ public function testProductStatusEnabled(): void { $this->assertEquals( [2020], - $this->getAssetIdByContentField->execute(self::STATUS_FIELD, self::STATUS_ENABLED) + $this->getAssetIdsByContentField->execute(self::STATUS_FIELD, self::STATUS_ENABLED) ); } @@ -95,7 +95,7 @@ public function testProductStatusDisabled(): void { $this->assertEquals( [], - $this->getAssetIdByContentField->execute(self::STATUS_FIELD, self::STATUS_DISABLED) + $this->getAssetIdsByContentField->execute(self::STATUS_FIELD, self::STATUS_DISABLED) ); } } diff --git a/dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdByContentFieldTest.php b/dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByContentFieldTest.php similarity index 75% rename from dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdByContentFieldTest.php rename to dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByContentFieldTest.php index 33eb4f2dcff41..e9ca4d33adc63 100644 --- a/dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdByContentFieldTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByContentFieldTest.php @@ -8,7 +8,7 @@ namespace Magento\MediaContentCms\Model\ResourceModel; -use Magento\MediaContentApi\Api\GetAssetIdByContentFieldInterface; +use Magento\MediaContentApi\Api\GetAssetIdsByContentFieldInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\TestFramework\Helper\Bootstrap; use PHPUnit\Framework\TestCase; @@ -16,7 +16,7 @@ /** * Test for GetAssetIdByContentFieldTest */ -class GetAssetIdByContentFieldTest extends TestCase +class GetAssetIdsByContentFieldTest extends TestCase { private const STORE_FIELD = 'store_id'; private const STATUS_FIELD = 'content_status'; @@ -24,9 +24,9 @@ class GetAssetIdByContentFieldTest extends TestCase private const STATUS_DISABLED = '0'; /** - * @var GetAssetIdByContentFieldInterface + * @var GetAssetIdsByContentFieldInterface */ - private $getAssetIdByContentField; + private $getAssetIdsByContentField; /** * @var int @@ -40,7 +40,7 @@ protected function setUp(): void { $objectManager = Bootstrap::getObjectManager(); $this->storeId = $objectManager->get(StoreManagerInterface::class)->getStore()->getId(); - $this->getAssetIdByContentField = $objectManager->get(GetAssetIdByContentFieldInterface::class); + $this->getAssetIdsByContentField = $objectManager->get(GetAssetIdsByContentFieldInterface::class); } /** @@ -53,7 +53,7 @@ public function testBlockStoreView(): void { $this->assertEquals( [2020], - $this->getAssetIdByContentField->execute(self::STORE_FIELD, (string)$this->storeId) + $this->getAssetIdsByContentField->execute(self::STORE_FIELD, (string)$this->storeId) ); } @@ -67,7 +67,7 @@ public function testPageStatusEnabled(): void { $this->assertEquals( [2020], - $this->getAssetIdByContentField->execute(self::STATUS_FIELD, self::STATUS_ENABLED) + $this->getAssetIdsByContentField->execute(self::STATUS_FIELD, self::STATUS_ENABLED) ); } @@ -81,7 +81,7 @@ public function testPageStatusDisabled(): void { $this->assertEquals( [], - $this->getAssetIdByContentField->execute(self::STATUS_FIELD, self::STATUS_DISABLED) + $this->getAssetIdsByContentField->execute(self::STATUS_FIELD, self::STATUS_DISABLED) ); } } From 752eb5af9e1581c8a1508d63390d1fb07ea3ddae Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Mon, 13 Jul 2020 11:58:24 +0100 Subject: [PATCH 13/20] Added data provider to tests --- .../GetAssetIdsByContentFieldTest.php | 68 ++++++++---------- .../GetAssetIdsByContentFieldTest.php | 71 ++++++++++++------- 2 files changed, 77 insertions(+), 62 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByContentFieldTest.php b/dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByContentFieldTest.php index 9719c1756f2bc..d776c681ae6e7 100644 --- a/dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByContentFieldTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByContentFieldTest.php @@ -8,13 +8,13 @@ namespace Magento\MediaContentCatalog\Model\ResourceModel; +use Magento\Framework\Exception\InvalidArgumentException; use Magento\MediaContentApi\Api\GetAssetIdsByContentFieldInterface; -use Magento\Store\Model\StoreManagerInterface; use Magento\TestFramework\Helper\Bootstrap; use PHPUnit\Framework\TestCase; /** - * Test for GetAssetIdByContentFieldTest + * Test for GetAssetIdsByContentFieldTest */ class GetAssetIdsByContentFieldTest extends TestCase { @@ -22,80 +22,72 @@ class GetAssetIdsByContentFieldTest extends TestCase private const STATUS_FIELD = 'content_status'; private const STATUS_ENABLED = '1'; private const STATUS_DISABLED = '0'; + private const FIXTURE_ASSET_ID = 2020; + private const DEFAULT_STORE_ID = '1'; /** * @var GetAssetIdsByContentFieldInterface */ private $getAssetIdsByContentField; - /** - * @var int - */ - private $storeId; - /** * @inheritdoc */ protected function setUp(): void { $objectManager = Bootstrap::getObjectManager(); - $this->storeId = $objectManager->get(StoreManagerInterface::class)->getStore()->getId(); $this->getAssetIdsByContentField = $objectManager->get(GetAssetIdsByContentFieldInterface::class); } /** - * Test for getting asset id by store view of a category + * Test for getting asset id by category fields * + * @dataProvider testProvider * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php * @magentoDataFixture Magento/MediaContentCatalog/_files/category_with_asset.php + * @param string $field + * @param string $value + * @param array $expectedAssetIds + * @throws InvalidArgumentException */ - public function testCategoryStoreView(): void + public function testCategoryFields(string $field, string $value, array $expectedAssetIds): void { $this->assertEquals( - [2020], - $this->getAssetIdsByContentField->execute(self::STORE_FIELD, (string)$this->storeId) + $expectedAssetIds, + $this->getAssetIdsByContentField->execute($field, $value) ); } /** - * Test for getting asset id by store view of a product + * Test for getting asset id by product fields * + * @dataProvider testProvider * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php * @magentoDataFixture Magento/MediaContentCatalog/_files/product_with_asset.php + * @param string $field + * @param string $value + * @param array $expectedAssetIds + * @throws InvalidArgumentException */ - public function testProductStoreView(): void + public function testProductFields(string $field, string $value, array $expectedAssetIds): void { $this->assertEquals( - [2020], - $this->getAssetIdsByContentField->execute(self::STORE_FIELD, (string)$this->storeId) + $expectedAssetIds, + $this->getAssetIdsByContentField->execute($field, $value) ); } /** - * Test for getting asset id by enabled status of a product + * Data provider for tests * - * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php - * @magentoDataFixture Magento/MediaContentCatalog/_files/category_with_asset.php + * @return array */ - public function testProductStatusEnabled(): void + public static function testProvider(): array { - $this->assertEquals( - [2020], - $this->getAssetIdsByContentField->execute(self::STATUS_FIELD, self::STATUS_ENABLED) - ); - } - - /** - * Test for getting asset id by disabled status of a product - * - * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php - * @magentoDataFixture Magento/MediaContentCatalog/_files/product_with_asset.php - */ - public function testProductStatusDisabled(): void - { - $this->assertEquals( - [], - $this->getAssetIdsByContentField->execute(self::STATUS_FIELD, self::STATUS_DISABLED) - ); + return [ + [self::STATUS_FIELD, self::STATUS_ENABLED, [self::FIXTURE_ASSET_ID]], + [self::STATUS_FIELD, self::STATUS_DISABLED, []], + [self::STORE_FIELD, self::DEFAULT_STORE_ID, [self::FIXTURE_ASSET_ID]], + ]; } } diff --git a/dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByContentFieldTest.php b/dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByContentFieldTest.php index e9ca4d33adc63..f136a26580e96 100644 --- a/dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByContentFieldTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByContentFieldTest.php @@ -8,13 +8,13 @@ namespace Magento\MediaContentCms\Model\ResourceModel; +use Magento\Framework\Exception\InvalidArgumentException; use Magento\MediaContentApi\Api\GetAssetIdsByContentFieldInterface; -use Magento\Store\Model\StoreManagerInterface; use Magento\TestFramework\Helper\Bootstrap; use PHPUnit\Framework\TestCase; /** - * Test for GetAssetIdByContentFieldTest + * Test for GetAssetIdsByContentFieldTest */ class GetAssetIdsByContentFieldTest extends TestCase { @@ -22,66 +22,89 @@ class GetAssetIdsByContentFieldTest extends TestCase private const STATUS_FIELD = 'content_status'; private const STATUS_ENABLED = '1'; private const STATUS_DISABLED = '0'; + private const FIXTURE_ASSET_ID = 2020; + private const DEFAULT_STORE_ID = '1'; + private const ADMIN_STORE_ID = '0'; /** * @var GetAssetIdsByContentFieldInterface */ private $getAssetIdsByContentField; - /** - * @var int - */ - private $storeId; - /** * @inheritdoc */ protected function setUp(): void { $objectManager = Bootstrap::getObjectManager(); - $this->storeId = $objectManager->get(StoreManagerInterface::class)->getStore()->getId(); $this->getAssetIdsByContentField = $objectManager->get(GetAssetIdsByContentFieldInterface::class); } /** - * Test for getting asset id by store view of a block + * Test for getting asset id by block field * + * @dataProvider testBlockDataProvider * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php * @magentoDataFixture Magento/MediaContentCms/_files/block_with_asset.php + * + * @param string $field + * @param string $value + * @param array $expectedAssetIds + * @throws InvalidArgumentException */ - public function testBlockStoreView(): void + public function testBlockFields(string $field, string $value, array $expectedAssetIds): void { $this->assertEquals( - [2020], - $this->getAssetIdsByContentField->execute(self::STORE_FIELD, (string)$this->storeId) + $expectedAssetIds, + $this->getAssetIdsByContentField->execute($field, $value) ); } /** - * Test for getting asset id by enabled status of a page + * Test for getting asset id by page field * + * @dataProvider testPageDataProvider * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php * @magentoDataFixture Magento/MediaContentCms/_files/page_with_asset.php + * + * @param string $field + * @param string $value + * @param array $expectedAssetIds + * @throws InvalidArgumentException */ - public function testPageStatusEnabled(): void + public function testPageFields(string $field, string $value, array $expectedAssetIds): void { $this->assertEquals( - [2020], - $this->getAssetIdsByContentField->execute(self::STATUS_FIELD, self::STATUS_ENABLED) + $expectedAssetIds, + $this->getAssetIdsByContentField->execute($field, $value) ); } /** - * Test for getting asset id by disabled status of a page + * Data provider for block tests * - * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php - * @magentoDataFixture Magento/MediaContentCms/_files/page_with_asset.php + * @return array */ - public function testPageStatusDisabled(): void + public static function testBlockDataProvider(): array { - $this->assertEquals( - [], - $this->getAssetIdsByContentField->execute(self::STATUS_FIELD, self::STATUS_DISABLED) - ); + return [ + [self::STATUS_FIELD, self::STATUS_ENABLED, [self::FIXTURE_ASSET_ID]], + [self::STATUS_FIELD, self::STATUS_DISABLED, []], + [self::STORE_FIELD, self::DEFAULT_STORE_ID, [self::FIXTURE_ASSET_ID]], + ]; + } + + /** + * Data provider for page tests + * + * @return array + */ + public static function testPageDataProvider(): array + { + return [ + [self::STATUS_FIELD, self::STATUS_ENABLED, [self::FIXTURE_ASSET_ID]], + [self::STATUS_FIELD, self::STATUS_DISABLED, []], + [self::STORE_FIELD, self::ADMIN_STORE_ID, [self::FIXTURE_ASSET_ID]], + ]; } } From 9dffdc53f0e415e4f664b26861148136218b359c Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Mon, 13 Jul 2020 12:03:35 +0100 Subject: [PATCH 14/20] Fixed static test --- app/code/Magento/MediaContentCatalog/etc/di.xml | 6 ------ app/code/Magento/MediaContentCms/etc/di.xml | 6 ------ 2 files changed, 12 deletions(-) diff --git a/app/code/Magento/MediaContentCatalog/etc/di.xml b/app/code/Magento/MediaContentCatalog/etc/di.xml index 865c72dfa4a5b..f8d03a1cb2e56 100644 --- a/app/code/Magento/MediaContentCatalog/etc/di.xml +++ b/app/code/Magento/MediaContentCatalog/etc/di.xml @@ -69,12 +69,6 @@ Magento\MediaContentCatalog\Model\ResourceModel\GetAssetIdsByProductStatus Magento\MediaContentCatalog\Model\ResourceModel\GetAssetIdsByCategoryStatus - - - - - - Magento\MediaContentCatalog\Model\ResourceModel\GetAssetIdsByProductStore Magento\MediaContentCatalog\Model\ResourceModel\GetAssetIdsByCategoryStore diff --git a/app/code/Magento/MediaContentCms/etc/di.xml b/app/code/Magento/MediaContentCms/etc/di.xml index 436c2ce94d786..551d24e02e9b2 100644 --- a/app/code/Magento/MediaContentCms/etc/di.xml +++ b/app/code/Magento/MediaContentCms/etc/di.xml @@ -73,12 +73,6 @@ Magento\MediaContentCms\Model\ResourceModel\GetAssetIdsByPageStatus Magento\MediaContentCms\Model\ResourceModel\GetAssetIdsByBlockStatus - - - - - - Magento\MediaContentCms\Model\ResourceModel\GetAssetIdsByPageStore Magento\MediaContentCms\Model\ResourceModel\GetAssetIdsByBlockStore From f02a540efc7863011743f1878cd7b1c6b668aee6 Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Mon, 13 Jul 2020 14:24:01 +0100 Subject: [PATCH 15/20] Fixing static tests --- .../Model/ResourceModel/GetAssetIdsByCategoryStore.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByCategoryStore.php b/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByCategoryStore.php index 386bc659ab681..c427b49309c30 100644 --- a/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByCategoryStore.php +++ b/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByCategoryStore.php @@ -80,7 +80,7 @@ public function execute(string $value): array /** * This function returns an array of category ids that have content and are under the root parameter * - * @param $rootCategoryId + * @param int $rootCategoryId * @return array */ private function getCategoryIdsByRootCategory(int $rootCategoryId): array From 500acc33cdaca4ac3629e298ee23c73880f74eec Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Tue, 14 Jul 2020 10:51:20 +0100 Subject: [PATCH 16/20] Removing test prefix from data providers --- .../Model/ResourceModel/GetAssetIdsByContentFieldTest.php | 8 +++++--- .../Model/ResourceModel/GetAssetIdsByContentFieldTest.php | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByContentFieldTest.php b/dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByContentFieldTest.php index d776c681ae6e7..2194200181729 100644 --- a/dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByContentFieldTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByContentFieldTest.php @@ -42,9 +42,10 @@ protected function setUp(): void /** * Test for getting asset id by category fields * - * @dataProvider testProvider + * @dataProvider dataProvider * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php * @magentoDataFixture Magento/MediaContentCatalog/_files/category_with_asset.php + * * @param string $field * @param string $value * @param array $expectedAssetIds @@ -61,9 +62,10 @@ public function testCategoryFields(string $field, string $value, array $expected /** * Test for getting asset id by product fields * - * @dataProvider testProvider + * @dataProvider dataProvider * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php * @magentoDataFixture Magento/MediaContentCatalog/_files/product_with_asset.php + * * @param string $field * @param string $value * @param array $expectedAssetIds @@ -82,7 +84,7 @@ public function testProductFields(string $field, string $value, array $expectedA * * @return array */ - public static function testProvider(): array + public static function dataProvider(): array { return [ [self::STATUS_FIELD, self::STATUS_ENABLED, [self::FIXTURE_ASSET_ID]], diff --git a/dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByContentFieldTest.php b/dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByContentFieldTest.php index f136a26580e96..bd6a08a7ab189 100644 --- a/dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByContentFieldTest.php +++ b/dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByContentFieldTest.php @@ -43,7 +43,7 @@ protected function setUp(): void /** * Test for getting asset id by block field * - * @dataProvider testBlockDataProvider + * @dataProvider blockDataProvider * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php * @magentoDataFixture Magento/MediaContentCms/_files/block_with_asset.php * @@ -63,7 +63,7 @@ public function testBlockFields(string $field, string $value, array $expectedAss /** * Test for getting asset id by page field * - * @dataProvider testPageDataProvider + * @dataProvider pageDataProvider * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php * @magentoDataFixture Magento/MediaContentCms/_files/page_with_asset.php * @@ -85,7 +85,7 @@ public function testPageFields(string $field, string $value, array $expectedAsse * * @return array */ - public static function testBlockDataProvider(): array + public static function blockDataProvider(): array { return [ [self::STATUS_FIELD, self::STATUS_ENABLED, [self::FIXTURE_ASSET_ID]], @@ -99,7 +99,7 @@ public static function testBlockDataProvider(): array * * @return array */ - public static function testPageDataProvider(): array + public static function pageDataProvider(): array { return [ [self::STATUS_FIELD, self::STATUS_ENABLED, [self::FIXTURE_ASSET_ID]], From acf425b4171db3d9b153b153eb7e17f35af719ce Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Tue, 14 Jul 2020 14:14:51 +0100 Subject: [PATCH 17/20] Fixing EE bugs --- .../GetAssetIdsByEavContentField.php | 19 +++- .../Magento/MediaContentCatalog/etc/di.xml | 2 + .../ResourceModel/GetAssetIdsByBlockStore.php | 94 ++++++++++++++++++ .../ResourceModel/GetAssetIdsByPageStore.php | 95 +++++++++++++++++++ app/code/Magento/MediaContentCms/etc/di.xml | 16 ---- 5 files changed, 206 insertions(+), 20 deletions(-) create mode 100644 app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByBlockStore.php create mode 100644 app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByPageStore.php diff --git a/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByEavContentField.php b/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByEavContentField.php index 1be610e1fea77..00c6e2f180a6f 100644 --- a/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByEavContentField.php +++ b/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByEavContentField.php @@ -38,6 +38,11 @@ class GetAssetIdsByEavContentField implements GetAssetIdsByContentFieldInterface */ private $entityType; + /** + * @var string + */ + private $entityTable; + /** * @var array */ @@ -50,6 +55,7 @@ class GetAssetIdsByEavContentField implements GetAssetIdsByContentFieldInterface * @param Config $config * @param string $attributeCode * @param string $entityType + * @param string $entityTable * @param array $valueMap */ public function __construct( @@ -57,12 +63,14 @@ public function __construct( Config $config, string $attributeCode, string $entityType, + string $entityTable, array $valueMap = [] ) { $this->connection = $resource; $this->config = $config; $this->attributeCode = $attributeCode; $this->entityType = $entityType; + $this->entityTable = $entityTable; $this->valueMap = $valueMap; } @@ -80,10 +88,13 @@ public function execute(string $value): array 'entity_type = ?', $this->entityType )->joinInner( - ['entity_eav_type' => $attribute->getBackendTable()], - 'asset_content_table.entity_id = entity_eav_type.' . $attribute->getEntityIdField() . - ' AND entity_eav_type.attribute_id = ' . - $attribute->getAttributeId(), + ['entity_table' => $this->connection->getTableName($this->entityTable)], + 'asset_content_table.entity_id = entity_table.entity_id', + [] + )->joinInner( + ['entity_eav_type' => $this->connection->getTableName($attribute->getBackendTable())], + 'entity_table.' . $attribute->getEntityIdField() . ' = entity_eav_type.' . $attribute->getEntityIdField() . + ' AND entity_eav_type.attribute_id = ' . $attribute->getAttributeId(), [] )->where( 'entity_eav_type.value = ?', diff --git a/app/code/Magento/MediaContentCatalog/etc/di.xml b/app/code/Magento/MediaContentCatalog/etc/di.xml index f8d03a1cb2e56..8c606a3cae49f 100644 --- a/app/code/Magento/MediaContentCatalog/etc/di.xml +++ b/app/code/Magento/MediaContentCatalog/etc/di.xml @@ -50,6 +50,7 @@ status catalog_product + catalog_product_entity 1 2 @@ -60,6 +61,7 @@ is_active catalog_category + catalog_category_entity diff --git a/app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByBlockStore.php b/app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByBlockStore.php new file mode 100644 index 0000000000000..675f26c8d6504 --- /dev/null +++ b/app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByBlockStore.php @@ -0,0 +1,94 @@ +connection = $resource; + $this->blockRepository = $blockRepository; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + } + + /** + * @inheritDoc + */ + public function execute(string $value): array + { + $sql = $this->connection->getConnection()->select()->from( + ['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)], + ['asset_id'] + )->where( + 'entity_type = ?', + self::ENTITY_TYPE + )->where( + 'entity_id IN (?)', + $this->getBlockIdsByStore((int) $value) + ); + + return $this->connection->getConnection()->fetchCol($sql); + } + + /** + * @param int $storeId + * @return array + * @throws LocalizedException + */ + private function getBlockIdsByStore(int $storeId): array + { + $searchCriteria = $this->searchCriteriaBuilder + ->addFilter(self::STORE_FIELD, $storeId) + ->create(); + + $searchResult = $this->blockRepository->getList($searchCriteria); + + return array_map(function (BlockInterface $block) { + return $block->getId(); + }, $searchResult->getItems()); + } +} diff --git a/app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByPageStore.php b/app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByPageStore.php new file mode 100644 index 0000000000000..2eae127ab33a2 --- /dev/null +++ b/app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByPageStore.php @@ -0,0 +1,95 @@ +connection = $resource; + $this->pageRepository = $pageRepository; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + } + + /** + * @inheritDoc + */ + public function execute(string $value): array + { + $sql = $this->connection->getConnection()->select()->from( + ['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)], + ['asset_id'] + )->where( + 'entity_type = ?', + self::ENTITY_TYPE + )->where( + 'entity_id IN (?)', + $this->getPageIdsByStore((int) $value) + ); + + return $this->connection->getConnection()->fetchCol($sql); + } + + /** + * @param int $storeId + * @return array + * @throws LocalizedException + */ + private function getPageIdsByStore(int $storeId): array + { + $searchCriteria = $this->searchCriteriaBuilder + ->addFilter(self::STORE_FIELD, $storeId) + ->create(); + + $searchResult = $this->pageRepository->getList($searchCriteria); + + return array_map(function (PageInterface $page) { + return $page->getId(); + }, $searchResult->getItems()); + } +} diff --git a/app/code/Magento/MediaContentCms/etc/di.xml b/app/code/Magento/MediaContentCms/etc/di.xml index 551d24e02e9b2..c157fbf22b7ad 100644 --- a/app/code/Magento/MediaContentCms/etc/di.xml +++ b/app/code/Magento/MediaContentCms/etc/di.xml @@ -34,22 +34,6 @@ - - - cms_block - cms_block_store - block_id - store_id - - - - - cms_page - cms_page_store - page_id - store_id - - cms_page From 377ed536493b73bbdb0c58f2b6ef6723327230bf Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Tue, 14 Jul 2020 15:16:24 +0100 Subject: [PATCH 18/20] Fixed static tests --- .../Model/ResourceModel/GetAssetIdsByBlockStore.php | 2 ++ .../Model/ResourceModel/GetAssetIdsByPageStore.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByBlockStore.php b/app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByBlockStore.php index 675f26c8d6504..f1f8d81ec32f2 100644 --- a/app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByBlockStore.php +++ b/app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByBlockStore.php @@ -75,6 +75,8 @@ public function execute(string $value): array } /** + * Get block ids by store + * * @param int $storeId * @return array * @throws LocalizedException diff --git a/app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByPageStore.php b/app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByPageStore.php index 2eae127ab33a2..92cf67e7d03e4 100644 --- a/app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByPageStore.php +++ b/app/code/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByPageStore.php @@ -76,6 +76,8 @@ public function execute(string $value): array } /** + * Get page ids by store + * * @param int $storeId * @return array * @throws LocalizedException From 193765d016180d1cf6bcadf904d741f483f0f1ba Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Fri, 17 Jul 2020 11:05:41 +0100 Subject: [PATCH 19/20] Implemented suggestions --- .../Composite/GetAssetIdsByContentField.php | 10 +-- .../GetAssetIdsByCategoryStore.php | 71 +++++-------------- 2 files changed, 24 insertions(+), 57 deletions(-) diff --git a/app/code/Magento/MediaContentApi/Model/Composite/GetAssetIdsByContentField.php b/app/code/Magento/MediaContentApi/Model/Composite/GetAssetIdsByContentField.php index 7130bee56d90a..61df8504b4c77 100644 --- a/app/code/Magento/MediaContentApi/Model/Composite/GetAssetIdsByContentField.php +++ b/app/code/Magento/MediaContentApi/Model/Composite/GetAssetIdsByContentField.php @@ -17,7 +17,7 @@ class GetAssetIdsByContentField implements GetAssetIdsByContentFieldApiInterface { /** - * @var GetAssetIdsByContentFieldInterface[] + * @var array */ private $fieldHandlers; @@ -26,7 +26,7 @@ class GetAssetIdsByContentField implements GetAssetIdsByContentFieldApiInterface * * @param array $fieldHandlers */ - public function __construct($fieldHandlers = []) + public function __construct(array $fieldHandlers = []) { $this->fieldHandlers = $fieldHandlers; } @@ -40,10 +40,10 @@ public function execute(string $field, string $value): array throw new InvalidArgumentException(__('The field argument is invalid.')); } $ids = []; - /** @var GetAssetIdsByContentFieldInterface $fieldHandlers */ - foreach ($this->fieldHandlers[$field] as $fieldHandlers) { + /** @var GetAssetIdsByContentFieldInterface $fieldHandler */ + foreach ($this->fieldHandlers[$field] as $fieldHandler) { // phpcs:ignore Magento2.Performance.ForeachArrayMerge - $ids = array_merge($ids, $fieldHandlers->execute($value)); + $ids = array_merge($ids, $fieldHandler->execute($value)); } return array_unique($ids); } diff --git a/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByCategoryStore.php b/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByCategoryStore.php index c427b49309c30..4b9e3d1265a21 100644 --- a/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByCategoryStore.php +++ b/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByCategoryStore.php @@ -8,6 +8,7 @@ namespace Magento\MediaContentCatalog\Model\ResourceModel; use Magento\Catalog\Api\CategoryManagementInterface; +use Magento\Catalog\Api\CategoryRepositoryInterface; use Magento\Framework\App\ResourceConnection; use Magento\Framework\Exception\LocalizedException; use Magento\MediaContentApi\Model\GetAssetIdsByContentFieldInterface; @@ -22,6 +23,7 @@ class GetAssetIdsByCategoryStore implements GetAssetIdsByContentFieldInterface private const TABLE_CONTENT_ASSET = 'media_content_asset'; private const TABLE_CATALOG_CATEGORY = 'catalog_category_entity'; private const ENTITY_TYPE = 'catalog_category'; + private const ID_COLUMN = 'entity_id'; /** * @var ResourceConnection @@ -38,21 +40,29 @@ class GetAssetIdsByCategoryStore implements GetAssetIdsByContentFieldInterface */ private $storeGroupRepository; + /** + * @var CategoryRepositoryInterface + */ + private $categoryRepository; + /** * GetAssetIdsByCategoryStore constructor. * * @param ResourceConnection $resource * @param StoreRepositoryInterface $storeRepository * @param GroupRepositoryInterface $storeGroupRepository + * @param CategoryRepositoryInterface $categoryRepository */ public function __construct( ResourceConnection $resource, StoreRepositoryInterface $storeRepository, - GroupRepositoryInterface $storeGroupRepository + GroupRepositoryInterface $storeGroupRepository, + CategoryRepositoryInterface $categoryRepository ) { $this->connection = $resource; $this->storeRepository = $storeRepository; $this->storeGroupRepository = $storeGroupRepository; + $this->categoryRepository = $categoryRepository; } /** @@ -62,66 +72,23 @@ public function execute(string $value): array { $storeView = $this->storeRepository->getById($value); $storeGroup = $this->storeGroupRepository->get($storeView->getStoreGroupId()); - $categoryIds = $this->getCategoryIdsByRootCategory((int) $storeGroup->getRootCategoryId()); + $rootCategory = $this->categoryRepository->get($storeGroup->getRootCategoryId()); + $sql = $this->connection->getConnection()->select()->from( ['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)], ['asset_id'] + )->joinInner( + ['category_table' => $this->connection->getTableName(self::TABLE_CATALOG_CATEGORY)], + 'asset_content_table.entity_id = category_table.' . self::ID_COLUMN, + [] )->where( 'entity_type = ?', self::ENTITY_TYPE )->where( - 'entity_id IN (?)', - $categoryIds + 'path LIKE ?', + $rootCategory->getPath() . '%' ); return $this->connection->getConnection()->fetchCol($sql); } - - /** - * This function returns an array of category ids that have content and are under the root parameter - * - * @param int $rootCategoryId - * @return array - */ - private function getCategoryIdsByRootCategory(int $rootCategoryId): array - { - $result = $this->getCategoryIdsAndPath(); - - $result = array_filter($result, function ($item) use ($rootCategoryId) { - $pathArray = explode('/', $item['path']); - $isInPath = false; - foreach ($pathArray as $id) { - if ($id == $rootCategoryId) { - $isInPath = true; - } - } - return $isInPath; - }); - - return array_map(function ($item) { - return $item['entity_id']; - }, $result); - } - - /** - * This function returns an array of category_id and path of categories that have content - * - * @return array - */ - private function getCategoryIdsAndPath(): array - { - $contentCategoriesSql = $this->connection->getConnection()->select()->from( - ['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)], - ['entity_id'] - )->where( - 'entity_type = ?', - self::ENTITY_TYPE - )->joinInner( - ['category_table' => $this->connection->getTableName(self::TABLE_CATALOG_CATEGORY)], - 'asset_content_table.entity_id = category_table.entity_id', - ['path'] - ); - - return $this->connection->getConnection()->fetchAll($contentCategoriesSql); - } } From 095dcc631d8e84ece779f7d4490e4a980fb61360 Mon Sep 17 00:00:00 2001 From: Gabriel Galvao da Gama Date: Fri, 17 Jul 2020 14:05:24 +0100 Subject: [PATCH 20/20] Added try to cover case when root category doesnt exists --- .../ResourceModel/GetAssetIdsByCategoryStore.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByCategoryStore.php b/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByCategoryStore.php index 4b9e3d1265a21..232577b77c802 100644 --- a/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByCategoryStore.php +++ b/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByCategoryStore.php @@ -11,6 +11,7 @@ use Magento\Catalog\Api\CategoryRepositoryInterface; use Magento\Framework\App\ResourceConnection; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\MediaContentApi\Model\GetAssetIdsByContentFieldInterface; use Magento\Store\Api\GroupRepositoryInterface; use Magento\Store\Api\StoreRepositoryInterface; @@ -70,9 +71,13 @@ public function __construct( */ public function execute(string $value): array { - $storeView = $this->storeRepository->getById($value); - $storeGroup = $this->storeGroupRepository->get($storeView->getStoreGroupId()); - $rootCategory = $this->categoryRepository->get($storeGroup->getRootCategoryId()); + try { + $storeView = $this->storeRepository->getById($value); + $storeGroup = $this->storeGroupRepository->get($storeView->getStoreGroupId()); + $rootCategory = $this->categoryRepository->get($storeGroup->getRootCategoryId()); + } catch (NoSuchEntityException $exception) { + return []; + } $sql = $this->connection->getConnection()->select()->from( ['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)],