From eb105087310e1c02c2e18381ff7b086798a336ec Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Tue, 6 Oct 2020 13:15:28 +0300 Subject: [PATCH 01/24] Support for ratings & reviews in Storefront App - et_schema - New feed tables --- .../CatalogDataExporter/etc/db_schema.xml | 78 +++++++++++++++++++ .../etc/db_schema_whitelist.json | 37 +++++++++ .../CatalogDataExporter/etc/et_schema.xml | 37 +++++++++ 3 files changed, 152 insertions(+) diff --git a/app/code/Magento/CatalogDataExporter/etc/db_schema.xml b/app/code/Magento/CatalogDataExporter/etc/db_schema.xml index f127827db..f2c35d934 100644 --- a/app/code/Magento/CatalogDataExporter/etc/db_schema.xml +++ b/app/code/Magento/CatalogDataExporter/etc/db_schema.xml @@ -139,4 +139,82 @@ + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
diff --git a/app/code/Magento/CatalogDataExporter/etc/db_schema_whitelist.json b/app/code/Magento/CatalogDataExporter/etc/db_schema_whitelist.json index dca402371..368d2d3c6 100644 --- a/app/code/Magento/CatalogDataExporter/etc/db_schema_whitelist.json +++ b/app/code/Magento/CatalogDataExporter/etc/db_schema_whitelist.json @@ -34,6 +34,43 @@ "index": { "CATALOG_DATA_EXPORTER_PRODUCT_ATTRIBUTES_MODIFIED_AT": true }, + "constraint": { + "PRIMARY": true + }, + "column": { + "id": true, + "store_view_code": true, + "feed_data": true, + "modified_at": true, + "is_deleted": true + } + }, + "catalog_data_exporter_product_reviews": { + "column": { + "id": true, + "store_view_code": true, + "feed_data": true, + "modified_at": true, + "is_deleted": true + }, + "index": { + "CATALOG_DATA_EXPORTER_PRODUCT_REVIEWS_MODIFIED_AT": true + }, + "constraint": { + "PRIMARY": true + } + }, + "catalog_data_exporter_rating_metadata": { + "column": { + "id": true, + "store_view_code": true, + "feed_data": true, + "modified_at": true, + "is_deleted": true + }, + "index": { + "CATALOG_DATA_EXPORTER_RATING_METADATA_MODIFIED_AT": true + }, "constraint": { "PRIMARY": true } diff --git a/app/code/Magento/CatalogDataExporter/etc/et_schema.xml b/app/code/Magento/CatalogDataExporter/etc/et_schema.xml index cb522f695..8a5fa7fad 100644 --- a/app/code/Magento/CatalogDataExporter/etc/et_schema.xml +++ b/app/code/Magento/CatalogDataExporter/etc/et_schema.xml @@ -23,7 +23,44 @@ provider="Magento\CatalogDataExporter\Model\Provider\ProductVariants"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 2379303acbe75011cacd20166c6de7f395578597 Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Tue, 6 Oct 2020 14:04:45 +0300 Subject: [PATCH 02/24] Support for ratings & reviews in Storefront App - et_schema --- app/code/Magento/CatalogDataExporter/etc/et_schema.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogDataExporter/etc/et_schema.xml b/app/code/Magento/CatalogDataExporter/etc/et_schema.xml index 8a5fa7fad..02e9bb5cf 100644 --- a/app/code/Magento/CatalogDataExporter/etc/et_schema.xml +++ b/app/code/Magento/CatalogDataExporter/etc/et_schema.xml @@ -37,6 +37,7 @@ + @@ -52,8 +53,11 @@ + - + + + From dff90f8de4ef2cacac13d6eb4192f229a1000f79 Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Mon, 12 Oct 2020 14:10:26 +0300 Subject: [PATCH 03/24] Support for ratings & reviews in Storefront App - Removed customerId --- app/code/Magento/CatalogDataExporter/etc/et_schema.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/CatalogDataExporter/etc/et_schema.xml b/app/code/Magento/CatalogDataExporter/etc/et_schema.xml index 02e9bb5cf..f0b8e5cad 100644 --- a/app/code/Magento/CatalogDataExporter/etc/et_schema.xml +++ b/app/code/Magento/CatalogDataExporter/etc/et_schema.xml @@ -41,7 +41,6 @@ - From 924304b93f516ca37a5bd4d74429d560e2f6cbf2 Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Mon, 12 Oct 2020 18:15:11 +0300 Subject: [PATCH 04/24] Support for ratings & reviews in Storefront App - Separation in Import / Read reviews --- app/code/Magento/CatalogDataExporter/etc/et_schema.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/CatalogDataExporter/etc/et_schema.xml b/app/code/Magento/CatalogDataExporter/etc/et_schema.xml index f0b8e5cad..02e9bb5cf 100644 --- a/app/code/Magento/CatalogDataExporter/etc/et_schema.xml +++ b/app/code/Magento/CatalogDataExporter/etc/et_schema.xml @@ -41,6 +41,7 @@ + From 72e92c672de9deb3a89983ccee5288129f7f75e6 Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Fri, 16 Oct 2020 13:37:25 +0300 Subject: [PATCH 05/24] Support for ratings & reviews in Storefront App - Review and rating metadata export --- .../CatalogDataExporter/etc/db_schema.xml | 78 ------------- .../etc/db_schema_whitelist.json | 37 ------ .../CatalogDataExporter/etc/et_schema.xml | 40 ------- .../Model/Indexer/FeedIndexer.php | 5 +- .../ProductReviewDataExporter/LICENSE.txt | 48 ++++++++ .../ProductReviewDataExporter/LICENSE_AFL.txt | 48 ++++++++ .../Model/Provider/ProductReviews.php | 107 ++++++++++++++++++ .../Model/Provider/RatingMetadata.php | 104 +++++++++++++++++ .../Model/Query/ProductReviewsQuery.php | 96 ++++++++++++++++ .../Model/Query/RatingMetadataQuery.php | 80 +++++++++++++ .../ProductReviewDataExporter/README.md | 3 + .../ProductReviewDataExporter/composer.json | 25 ++++ .../etc/db_schema.xml | 84 ++++++++++++++ .../etc/db_schema_whitelist.json | 31 +++++ .../ProductReviewDataExporter/etc/di.xml | 85 ++++++++++++++ .../etc/et_schema.xml | 46 ++++++++ .../ProductReviewDataExporter/etc/indexer.xml | 26 +++++ .../ProductReviewDataExporter/etc/module.xml | 14 +++ .../ProductReviewDataExporter/etc/mview.xml | 32 ++++++ .../registration.php | 9 ++ .../composer_root_modules_data_export.txt | 1 + 21 files changed, 842 insertions(+), 157 deletions(-) create mode 100644 app/code/Magento/ProductReviewDataExporter/LICENSE.txt create mode 100644 app/code/Magento/ProductReviewDataExporter/LICENSE_AFL.txt create mode 100644 app/code/Magento/ProductReviewDataExporter/Model/Provider/ProductReviews.php create mode 100644 app/code/Magento/ProductReviewDataExporter/Model/Provider/RatingMetadata.php create mode 100644 app/code/Magento/ProductReviewDataExporter/Model/Query/ProductReviewsQuery.php create mode 100644 app/code/Magento/ProductReviewDataExporter/Model/Query/RatingMetadataQuery.php create mode 100644 app/code/Magento/ProductReviewDataExporter/README.md create mode 100644 app/code/Magento/ProductReviewDataExporter/composer.json create mode 100644 app/code/Magento/ProductReviewDataExporter/etc/db_schema.xml create mode 100644 app/code/Magento/ProductReviewDataExporter/etc/db_schema_whitelist.json create mode 100644 app/code/Magento/ProductReviewDataExporter/etc/di.xml create mode 100644 app/code/Magento/ProductReviewDataExporter/etc/et_schema.xml create mode 100644 app/code/Magento/ProductReviewDataExporter/etc/indexer.xml create mode 100644 app/code/Magento/ProductReviewDataExporter/etc/module.xml create mode 100644 app/code/Magento/ProductReviewDataExporter/etc/mview.xml create mode 100644 app/code/Magento/ProductReviewDataExporter/registration.php diff --git a/app/code/Magento/CatalogDataExporter/etc/db_schema.xml b/app/code/Magento/CatalogDataExporter/etc/db_schema.xml index f2c35d934..f127827db 100644 --- a/app/code/Magento/CatalogDataExporter/etc/db_schema.xml +++ b/app/code/Magento/CatalogDataExporter/etc/db_schema.xml @@ -139,82 +139,4 @@ - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
diff --git a/app/code/Magento/CatalogDataExporter/etc/db_schema_whitelist.json b/app/code/Magento/CatalogDataExporter/etc/db_schema_whitelist.json index 368d2d3c6..dca402371 100644 --- a/app/code/Magento/CatalogDataExporter/etc/db_schema_whitelist.json +++ b/app/code/Magento/CatalogDataExporter/etc/db_schema_whitelist.json @@ -34,43 +34,6 @@ "index": { "CATALOG_DATA_EXPORTER_PRODUCT_ATTRIBUTES_MODIFIED_AT": true }, - "constraint": { - "PRIMARY": true - }, - "column": { - "id": true, - "store_view_code": true, - "feed_data": true, - "modified_at": true, - "is_deleted": true - } - }, - "catalog_data_exporter_product_reviews": { - "column": { - "id": true, - "store_view_code": true, - "feed_data": true, - "modified_at": true, - "is_deleted": true - }, - "index": { - "CATALOG_DATA_EXPORTER_PRODUCT_REVIEWS_MODIFIED_AT": true - }, - "constraint": { - "PRIMARY": true - } - }, - "catalog_data_exporter_rating_metadata": { - "column": { - "id": true, - "store_view_code": true, - "feed_data": true, - "modified_at": true, - "is_deleted": true - }, - "index": { - "CATALOG_DATA_EXPORTER_RATING_METADATA_MODIFIED_AT": true - }, "constraint": { "PRIMARY": true } diff --git a/app/code/Magento/CatalogDataExporter/etc/et_schema.xml b/app/code/Magento/CatalogDataExporter/etc/et_schema.xml index 02e9bb5cf..8fa143ccb 100644 --- a/app/code/Magento/CatalogDataExporter/etc/et_schema.xml +++ b/app/code/Magento/CatalogDataExporter/etc/et_schema.xml @@ -23,46 +23,6 @@ provider="Magento\CatalogDataExporter\Model\Provider\ProductVariants">
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/code/Magento/DataExporter/Model/Indexer/FeedIndexer.php b/app/code/Magento/DataExporter/Model/Indexer/FeedIndexer.php index eaab78cc5..a96a50e58 100644 --- a/app/code/Magento/DataExporter/Model/Indexer/FeedIndexer.php +++ b/app/code/Magento/DataExporter/Model/Indexer/FeedIndexer.php @@ -269,7 +269,8 @@ private function prepareChunkData(array $chunk, array $existingFeedData, array & $feedIdentity = $this->feedIndexMetadata->getFeedIdentity(); foreach ($chunk as &$feedData) { - $existingData = $existingFeedData[$feedData['storeViewCode']][$feedData[$feedIdentity]] ?? null; + $storeViewCode = $feedData['storeViewCode'] ?? null; + $existingData = $existingFeedData[$storeViewCode][$feedData[$feedIdentity]] ?? null; $attributes = []; if (null !== $existingData) { @@ -282,7 +283,7 @@ private function prepareChunkData(array $chunk, array $existingFeedData, array & $callbackData[] = \array_filter( [ $feedIdentity => $feedData[$feedIdentity], - 'storeViewCode' => $feedData['storeViewCode'], + 'storeViewCode' => $storeViewCode, 'attributes' => $attributes, ] ); diff --git a/app/code/Magento/ProductReviewDataExporter/LICENSE.txt b/app/code/Magento/ProductReviewDataExporter/LICENSE.txt new file mode 100644 index 000000000..36b2459f6 --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/LICENSE.txt @@ -0,0 +1,48 @@ + +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. diff --git a/app/code/Magento/ProductReviewDataExporter/LICENSE_AFL.txt b/app/code/Magento/ProductReviewDataExporter/LICENSE_AFL.txt new file mode 100644 index 000000000..496bf10ad --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/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 © 2016 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/ProductReviewDataExporter/Model/Provider/ProductReviews.php b/app/code/Magento/ProductReviewDataExporter/Model/Provider/ProductReviews.php new file mode 100644 index 000000000..149ca0e70 --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/Model/Provider/ProductReviews.php @@ -0,0 +1,107 @@ +resourceConnection = $resourceConnection; + $this->productReviewsQuery = $productReviewsQuery; + $this->logger = $logger; + } + + /** + * Returns attribute data + * + * @param array $values + * + * @return array + * + * @throws UnableRetrieveData + */ + public function get(array $values): array + { + $output = []; + $queryArguments = []; + + try { + foreach ($values as $value) { + $queryArguments[$value['reviewId']] = $value['reviewId']; + } + + $connection = $this->resourceConnection->getConnection(); + $cursor = $connection->query($this->productReviewsQuery->getQuery($queryArguments)); + + while ($row = $cursor->fetch()) { + $key = $row['reviewId']; + $output[$key] = $output[$key] ?? $this->formatReviewRow($row); + $output[$key]['ratings'][] = [ + 'ratingId' => \base64_encode($row['ratingId']), + 'value' => $row['ratingValue'], + ]; + } + } catch (\Throwable $exception) { + $this->logger->error($exception->getMessage()); + throw new UnableRetrieveData('Unable to retrieve product reviews data'); + } + + return \array_values($output); + } + + /** + * Format review row + * + * @param array $row + * + * @return array + */ + private function formatReviewRow(array $row): array + { + return [ + 'reviewId' => $row['reviewId'], + 'productId' => $row['productId'], + 'visibility' => \explode(',', $row['visibility']), + 'title' => $row['title'], + 'nickname' => $row['nickname'], + 'text' => $row['text'], + 'customerId' => $row['customerId'], + ]; + } +} diff --git a/app/code/Magento/ProductReviewDataExporter/Model/Provider/RatingMetadata.php b/app/code/Magento/ProductReviewDataExporter/Model/Provider/RatingMetadata.php new file mode 100644 index 000000000..8873f8580 --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/Model/Provider/RatingMetadata.php @@ -0,0 +1,104 @@ +resourceConnection = $resourceConnection; + $this->ratingMetadataQuery = $ratingMetadataQuery; + $this->logger = $logger; + } + + /** + * Returns attribute data + * + * @param array $values + * + * @return array + * + * @throws UnableRetrieveData + */ + public function get(array $values): array + { + $output = []; + $queryArguments = []; + + try { + foreach ($values as $value) { + $queryArguments[$value['ratingId']] = $value['ratingId']; + } + + $connection = $this->resourceConnection->getConnection(); + $cursor = $connection->query($this->ratingMetadataQuery->getQuery($queryArguments)); + + while ($row = $cursor->fetch()) { + $key = $row['ratingId'] . $row['storeViewCode']; + $output[$key] = $output[$key] ?? $this->formatRatingRow($row); + $output[$key]['values'][] = [ + 'valueId' => \base64_encode($row['valueId']), + 'value' => $row['value'], + 'position' => $row['position'], + ]; + } + } catch (\Throwable $exception) { + $this->logger->error($exception->getMessage()); + throw new UnableRetrieveData('Unable to retrieve rating metadata data'); + } + + return \array_values($output); + } + + /** + * Format rating row + * + * @param array $row + * + * @return array + */ + private function formatRatingRow(array $row): array + { + return [ + 'ratingId' => \base64_encode($row['ratingId']), + 'storeViewCode' => $row['storeViewCode'], + 'name' => $row['name'], + ]; + } +} diff --git a/app/code/Magento/ProductReviewDataExporter/Model/Query/ProductReviewsQuery.php b/app/code/Magento/ProductReviewDataExporter/Model/Query/ProductReviewsQuery.php new file mode 100644 index 000000000..fe6397fbf --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/Model/Query/ProductReviewsQuery.php @@ -0,0 +1,96 @@ +resourceConnection = $resourceConnection; + } + + /** + * Get query for provider + * + * @param int[] $reviewIds + * + * @return Select + */ + public function getQuery(array $reviewIds) : Select + { + $connection = $this->resourceConnection->getConnection(); + + return $connection->select() + ->from(['r' => $this->resourceConnection->getTableName('review')], []) + ->join( + ['rd' => $this->resourceConnection->getTableName('review_detail')], + 'r.review_id = rd.review_id', + [] + ) + ->join( + ['rs' => $this->resourceConnection->getTableName('review_store')], + 'r.review_id = rs.review_id', + [] + ) + ->join( + ['s' => $this->resourceConnection->getTableName('store')], + 'rs.store_id = s.store_id', + [] + ) + ->join( + ['re' => $this->resourceConnection->getTableName('review_entity')], + 'r.entity_id = re.entity_id', + [] + ) + ->join( + ['rov' => $this->resourceConnection->getTableName('rating_option_vote')], + 'r.review_id = rov.review_id', + [] + ) + ->join( + ['ro' => $this->resourceConnection->getTableName('rating_option')], + 'rov.option_id = ro.option_id', + [] + )->columns( + [ + 'reviewId' => 'r.review_id', + 'productId' => 'r.entity_pk_value', + 'visibility' => new Expression('GROUP_CONCAT(s.code)'), + 'title' => 'rd.title', + 'nickname' => 'rd.nickname', + 'text' => 'rd.detail', + 'customerId' => 'rd.customer_id', + 'ratingId' => 'rov.rating_id', + 'ratingValue' => 'ro.value', + ] + ) + ->where('r.review_id IN (?)', $reviewIds) + ->where('r.status_id = ?', Review::STATUS_APPROVED) + ->where('s.store_id != ?', Store::DEFAULT_STORE_ID) + ->where('re.entity_code = ?', Review::ENTITY_PRODUCT_CODE) + ->group(['r.review_id', 'rov.rating_id']); + } +} diff --git a/app/code/Magento/ProductReviewDataExporter/Model/Query/RatingMetadataQuery.php b/app/code/Magento/ProductReviewDataExporter/Model/Query/RatingMetadataQuery.php new file mode 100644 index 000000000..365ec92d7 --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/Model/Query/RatingMetadataQuery.php @@ -0,0 +1,80 @@ +resourceConnection = $resourceConnection; + } + + /** + * Get query for provider + * + * @param array $ratingIds + * + * @return Select + */ + public function getQuery(array $ratingIds) : Select + { + $connection = $this->resourceConnection->getConnection(); + + return $connection->select() + ->from(['r' => $this->resourceConnection->getTableName('rating')], []) + ->join( + ['rs' => $this->resourceConnection->getTableName('rating_store')], + 'r.rating_id = rs.rating_id', + [] + ) + ->join( + ['s' => $this->resourceConnection->getTableName('store')], + 'rs.store_id = s.store_id', + [] + ) + ->joinLeft( + ['rt' => $this->resourceConnection->getTableName('rating_title')], + 'r.rating_id = rt.rating_id AND rt.store_id = s.store_id', + [] + ) + ->join( + ['ro' => $this->resourceConnection->getTableName('rating_option')], + 'r.rating_id = ro.rating_id', + [] + ) + ->columns( + [ + 'ratingId' => 'r.rating_id', + 'storeViewCode' => 's.code', + 'name' => $connection->getIfNullSql('rt.value', 'r.rating_code'), + 'valueId' => 'ro.option_id', + 'value' => 'ro.value', + 'position' => 'ro.position', + ] + ) + ->where('r.rating_id IN (?)', $ratingIds) + ->where('r.is_active = ?', 1) + ->where('s.store_id != ?', Store::DEFAULT_STORE_ID); + } +} diff --git a/app/code/Magento/ProductReviewDataExporter/README.md b/app/code/Magento/ProductReviewDataExporter/README.md new file mode 100644 index 000000000..dffbf4a04 --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/README.md @@ -0,0 +1,3 @@ +## Release notes + +*Magento_ProductReviewDataExporter* module diff --git a/app/code/Magento/ProductReviewDataExporter/composer.json b/app/code/Magento/ProductReviewDataExporter/composer.json new file mode 100644 index 000000000..b0cf953b2 --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/composer.json @@ -0,0 +1,25 @@ +{ + "name": "magento/module-product-review-data-exporter", + "description": "Product review data exporter", + "config": { + "sort-packages": true + }, + "type": "magento2-module", + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Magento\\ProductReviewDataExporter\\": "" + } + }, + "require": { + "php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0", + "magento/framework": "*", + "magento/module-data-exporter": "*" + } +} diff --git a/app/code/Magento/ProductReviewDataExporter/etc/db_schema.xml b/app/code/Magento/ProductReviewDataExporter/etc/db_schema.xml new file mode 100644 index 000000000..156405619 --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/etc/db_schema.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+
diff --git a/app/code/Magento/ProductReviewDataExporter/etc/db_schema_whitelist.json b/app/code/Magento/ProductReviewDataExporter/etc/db_schema_whitelist.json new file mode 100644 index 000000000..3e9c08ee6 --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/etc/db_schema_whitelist.json @@ -0,0 +1,31 @@ +{ + "catalog_data_exporter_product_reviews": { + "column": { + "id": true, + "feed_data": true, + "modified_at": true, + "is_deleted": true + }, + "index": { + "CATALOG_DATA_EXPORTER_PRODUCT_REVIEWS_MODIFIED_AT": true + }, + "constraint": { + "PRIMARY": true + } + }, + "catalog_data_exporter_rating_metadata": { + "column": { + "id": true, + "store_view_code": true, + "feed_data": true, + "modified_at": true, + "is_deleted": true + }, + "index": { + "CATALOG_DATA_EXPORTER_RATING_METADATA_MODIFIED_AT": true + }, + "constraint": { + "PRIMARY": true + } + } +} \ No newline at end of file diff --git a/app/code/Magento/ProductReviewDataExporter/etc/di.xml b/app/code/Magento/ProductReviewDataExporter/etc/di.xml new file mode 100644 index 000000000..95ebfeb5f --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/etc/di.xml @@ -0,0 +1,85 @@ + + + + + + + reviews + reviewId + review + review_id + catalog_data_exporter_product_reviews + id + + feed_data + is_deleted + + + + + + + + reviewId + + + + + + + + Magento\ProductReviewDataExporter\Model\Indexer\ProductReviewsFeedIndexMetadata + + + Magento\ProductReviewDataExporter\Model\Indexer\ProductReviewsDataSerializer + + + + + + + + ratingMetadata + ratingId + rating + rating_id + catalog_data_exporter_rating_metadata + id + + feed_data + is_deleted + + + + + + + + ratingId + storeViewCode + + + + + + + + Magento\ProductReviewDataExporter\Model\Indexer\RatingFeedIndexMetadata + + + Magento\ProductReviewDataExporter\Model\Indexer\RatingDataSerializer + + + + diff --git a/app/code/Magento/ProductReviewDataExporter/etc/et_schema.xml b/app/code/Magento/ProductReviewDataExporter/etc/et_schema.xml new file mode 100644 index 000000000..64a9a9b7b --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/etc/et_schema.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/ProductReviewDataExporter/etc/indexer.xml b/app/code/Magento/ProductReviewDataExporter/etc/indexer.xml new file mode 100644 index 000000000..91e3a1395 --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/etc/indexer.xml @@ -0,0 +1,26 @@ + + + + + Product Reviews Feed + Collects data for a Product Reviews Feed + + + + Product Rating Metadata Feed + Collects data for a Product Rating Metadata Feed + + diff --git a/app/code/Magento/ProductReviewDataExporter/etc/module.xml b/app/code/Magento/ProductReviewDataExporter/etc/module.xml new file mode 100644 index 000000000..4ec0f07f8 --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/etc/module.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/app/code/Magento/ProductReviewDataExporter/etc/mview.xml b/app/code/Magento/ProductReviewDataExporter/etc/mview.xml new file mode 100644 index 000000000..f724649bc --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/etc/mview.xml @@ -0,0 +1,32 @@ + + + + + + +
+
+
+ + + + + +
+
+
+
+ + + diff --git a/app/code/Magento/ProductReviewDataExporter/registration.php b/app/code/Magento/ProductReviewDataExporter/registration.php new file mode 100644 index 000000000..ea6e76769 --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/registration.php @@ -0,0 +1,9 @@ + Date: Mon, 19 Oct 2020 15:31:05 +0300 Subject: [PATCH 06/24] Support for ratings & reviews in Storefront App - Mark entities as removed --- .../Magento/CatalogDataExporter/etc/di.xml | 3 + .../Model/Indexer/FeedIndexMetadata.php | 54 ++++++++++++++ .../Model/Indexer/FeedIndexer.php | 47 +++--------- .../Model/Indexer/MarkRemovedEntities.php | 72 ++++++++++++++++++ .../Indexer/MarkRemovedEntitiesInterface.php | 24 ++++++ app/code/Magento/DataExporter/etc/di.xml | 2 + .../Indexer/MarkRemovedRatingMetadata.php | 74 +++++++++++++++++++ .../ProductReviewDataExporter/etc/di.xml | 6 ++ 8 files changed, 247 insertions(+), 35 deletions(-) create mode 100644 app/code/Magento/DataExporter/Model/Indexer/MarkRemovedEntities.php create mode 100644 app/code/Magento/DataExporter/Model/Indexer/MarkRemovedEntitiesInterface.php create mode 100644 app/code/Magento/ProductReviewDataExporter/Model/Indexer/MarkRemovedRatingMetadata.php diff --git a/app/code/Magento/CatalogDataExporter/etc/di.xml b/app/code/Magento/CatalogDataExporter/etc/di.xml index ca77f0599..400ed3397 100644 --- a/app/code/Magento/CatalogDataExporter/etc/di.xml +++ b/app/code/Magento/CatalogDataExporter/etc/di.xml @@ -249,6 +249,9 @@ productIdcatalog_product_entityentity_id + catalog_product_website + product_id + website_idcatalog_data_exporter_productsid diff --git a/app/code/Magento/DataExporter/Model/Indexer/FeedIndexMetadata.php b/app/code/Magento/DataExporter/Model/Indexer/FeedIndexMetadata.php index dadcd9a7d..d9d76a4b3 100644 --- a/app/code/Magento/DataExporter/Model/Indexer/FeedIndexMetadata.php +++ b/app/code/Magento/DataExporter/Model/Indexer/FeedIndexMetadata.php @@ -52,10 +52,28 @@ class FeedIndexMetadata */ private $feedTableMutableColumns; + /** + * @var string + */ + private $scopeTableName; + + /** + * @var string + */ + private $scopeTableField; + + /** + * @var string + */ + private $scopeCode; + /** * @param string $feedName * @param string $sourceTableName * @param string $sourceTableField + * @param string $scopeTableName + * @param string $scopeTableField + * @param string $scopeCode * @param string $feedIdentity * @param string $feedTableName * @param string $feedTableField @@ -70,6 +88,9 @@ public function __construct( string $feedTableName, string $feedTableField, array $feedTableMutableColumns, + string $scopeTableName = '', + string $scopeTableField = '', + string $scopeCode = '', int $batchSize = 100 ) { $this->sourceTableName = $sourceTableName; @@ -80,6 +101,9 @@ public function __construct( $this->batchSize = $batchSize; $this->feedName = $feedName; $this->feedTableMutableColumns = $feedTableMutableColumns; + $this->scopeTableName = $scopeTableName; + $this->scopeTableField = $scopeTableField; + $this->scopeCode = $scopeCode; } /** @@ -161,4 +185,34 @@ public function getFeedTableMutableColumns(): array { return $this->feedTableMutableColumns; } + + /** + * Get scope table name + * + * @return string + */ + public function getScopeTableName(): string + { + return $this->scopeTableName; + } + + /** + * Get scope table field + * + * @return string + */ + public function getScopeTableField(): string + { + return $this->scopeTableField; + } + + /** + * Get scope table scope code + * + * @return string + */ + public function getScopeCode(): string + { + return $this->scopeCode; + } } diff --git a/app/code/Magento/DataExporter/Model/Indexer/FeedIndexer.php b/app/code/Magento/DataExporter/Model/Indexer/FeedIndexer.php index a96a50e58..d1d2ce80a 100644 --- a/app/code/Magento/DataExporter/Model/Indexer/FeedIndexer.php +++ b/app/code/Magento/DataExporter/Model/Indexer/FeedIndexer.php @@ -54,6 +54,11 @@ class FeedIndexer implements IndexerActionInterface, MviewActionInterface */ private $feedPool; + /** + * @var MarkRemovedEntitiesInterface + */ + private $markRemovedEntities; + /** * @param Processor $processor * @param ResourceConnection $resourceConnection @@ -61,6 +66,7 @@ class FeedIndexer implements IndexerActionInterface, MviewActionInterface * @param FeedIndexMetadata $feedIndexMetadata * @param FeedIndexerCallbackInterface $feedIndexerCallback * @param FeedPool $feedPool + * @param MarkRemovedEntitiesInterface $markRemovedEntities * @param array $callbackSkipAttributes */ public function __construct( @@ -70,6 +76,7 @@ public function __construct( FeedIndexMetadata $feedIndexMetadata, FeedIndexerCallbackInterface $feedIndexerCallback, FeedPool $feedPool, + MarkRemovedEntitiesInterface $markRemovedEntities, array $callbackSkipAttributes = [] ) { $this->processor = $processor; @@ -78,6 +85,7 @@ public function __construct( $this->dataSerializer = $serializer; $this->feedIndexerCallback = $feedIndexerCallback; $this->feedPool = $feedPool; + $this->markRemovedEntities = $markRemovedEntities; $this->callbackSkipAttributes = $callbackSkipAttributes; } @@ -137,7 +145,7 @@ public function executeFull() { $this->truncateFeedTable(); foreach ($this->getAllIds() as $ids) { - $this->markRemoved($ids); + $this->markRemovedEntities->execute($ids, $this->feedIndexMetadata); $this->process($ids); } } @@ -154,7 +162,7 @@ public function executeList(array $ids) foreach ($ids as $id) { $arguments[] = [$this->feedIndexMetadata->getFeedIdentity() => $id]; } - $this->markRemoved($ids); + $this->markRemovedEntities->execute($ids, $this->feedIndexMetadata); $this->process($arguments); } @@ -166,7 +174,7 @@ public function executeList(array $ids) */ public function executeRow($id) { - $this->markRemoved([$id]); + $this->markRemovedEntities->execute([$id], $this->feedIndexMetadata); $this->process([[$this->feedIndexMetadata->getFeedIdentity() => $id]]); } @@ -188,7 +196,7 @@ public function execute($ids) ]; } - $this->markRemoved(\array_column($arguments, $feedIdentity)); + $this->markRemovedEntities->execute(\array_column($arguments, $feedIdentity), $this->feedIndexMetadata); $this->process($arguments); } @@ -312,37 +320,6 @@ private function fetchFeedData(array $ids): array return $output; } - /** - * Mark field removed - * - * @param array $ids - * @return void - */ - private function markRemoved(array $ids) : void - { - $connection = $this->resourceConnection->getConnection(); - $select = $connection->select() - ->joinLeft( - ['s' => $this->resourceConnection->getTableName($this->feedIndexMetadata->getSourceTableName())], - sprintf( - 'f.%s = s.%s', - $this->feedIndexMetadata->getFeedTableField(), - $this->feedIndexMetadata->getSourceTableField() - ), - ['is_deleted' => new \Zend_Db_Expr('1')] - ) - ->where(sprintf('s.%s IS NULL', $this->feedIndexMetadata->getSourceTableField())) - ->where( - sprintf('f.%s IN (?)', $this->feedIndexMetadata->getFeedTableField()), - $ids - ); - $update = $connection->updateFromSelect( - $select, - ['f' => $this->resourceConnection->getTableName($this->feedIndexMetadata->getFeedTableName())] - ); - $connection->query($update); - } - /** * Truncate feed table * diff --git a/app/code/Magento/DataExporter/Model/Indexer/MarkRemovedEntities.php b/app/code/Magento/DataExporter/Model/Indexer/MarkRemovedEntities.php new file mode 100644 index 000000000..78a4c42fc --- /dev/null +++ b/app/code/Magento/DataExporter/Model/Indexer/MarkRemovedEntities.php @@ -0,0 +1,72 @@ +resourceConnection = $resourceConnection; + } + + /** + * @inheritdoc + */ + public function execute(array $ids, FeedIndexMetadata $metadata): void + { + $connection = $this->resourceConnection->getConnection(); + $select = $connection->select() + ->joinLeft( + ['s' => $this->resourceConnection->getTableName($metadata->getSourceTableName())], + \sprintf('f.%s = s.%s', $metadata->getFeedTableField(), $metadata->getSourceTableField()), + ['is_deleted' => new \Zend_Db_Expr('1')] + ) + ->where(\sprintf('f.%s IN (?)', $metadata->getFeedTableField()), $ids); + + if ($metadata->getScopeTableName()) { + $select + ->join( + ['st' => $this->resourceConnection->getTableName('store')], + 'f.store_view_code = st.code', + [] + ) + ->joinLeft( + ['sc' => $this->resourceConnection->getTableName($metadata->getScopeTableName())], + \sprintf( + 'sc.%s = s.%s AND sc.%3$s = st.%3$s', + $metadata->getScopeTableField(), + $metadata->getSourceTableField(), + $metadata->getScopeCode(), + ), + [] + ) + ->where(\sprintf('sc.%s IS NULL', $metadata->getScopeTableField())); + } else { + $select->where(\sprintf('s.%s IS NULL', $metadata->getSourceTableField())); + } + + $update = $connection->updateFromSelect( + $select, + ['f' => $this->resourceConnection->getTableName($metadata->getFeedTableName())] + ); + $connection->query($update); + } +} diff --git a/app/code/Magento/DataExporter/Model/Indexer/MarkRemovedEntitiesInterface.php b/app/code/Magento/DataExporter/Model/Indexer/MarkRemovedEntitiesInterface.php new file mode 100644 index 000000000..065046f3a --- /dev/null +++ b/app/code/Magento/DataExporter/Model/Indexer/MarkRemovedEntitiesInterface.php @@ -0,0 +1,24 @@ + + diff --git a/app/code/Magento/ProductReviewDataExporter/Model/Indexer/MarkRemovedRatingMetadata.php b/app/code/Magento/ProductReviewDataExporter/Model/Indexer/MarkRemovedRatingMetadata.php new file mode 100644 index 000000000..27129f401 --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/Model/Indexer/MarkRemovedRatingMetadata.php @@ -0,0 +1,74 @@ +resourceConnection = $resourceConnection; + } + + /** + * @inheritdoc + */ + public function execute(array $ids, FeedIndexMetadata $metadata): void + { + $connection = $this->resourceConnection->getConnection(); + $select = $connection->select() + ->joinLeft( + ['s' => $this->resourceConnection->getTableName($metadata->getSourceTableName())], + \sprintf( + new Expression('FROM_BASE64(f.%s)') . ' = s.%s', + $metadata->getFeedTableField(), + $metadata->getSourceTableField() + ), + ['is_deleted' => new \Zend_Db_Expr('1')] + ) + ->join( + ['st' => $this->resourceConnection->getTableName('store')], + 'f.store_view_code = st.code', + [] + ) + ->joinLeft( + ['sc' => $this->resourceConnection->getTableName($metadata->getScopeTableName())], + \sprintf( + 'sc.%s = s.%s AND sc.%3$s = st.%3$s', + $metadata->getScopeTableField(), + $metadata->getSourceTableField(), + $metadata->getScopeCode(), + ), + [] + ) + ->where(\sprintf('sc.%s IS NULL', $metadata->getScopeTableField())) + ->where(\sprintf('s.%s IN (?)', $metadata->getSourceTableField()), $ids); + + $update = $connection->updateFromSelect( + $select, + ['f' => $this->resourceConnection->getTableName($metadata->getFeedTableName())] + ); + + $connection->query($update); + } +} diff --git a/app/code/Magento/ProductReviewDataExporter/etc/di.xml b/app/code/Magento/ProductReviewDataExporter/etc/di.xml index 95ebfeb5f..40ea4e281 100644 --- a/app/code/Magento/ProductReviewDataExporter/etc/di.xml +++ b/app/code/Magento/ProductReviewDataExporter/etc/di.xml @@ -52,6 +52,9 @@ ratingId rating rating_id + rating_store + rating_id + store_id catalog_data_exporter_rating_metadata id @@ -80,6 +83,9 @@ Magento\ProductReviewDataExporter\Model\Indexer\RatingDataSerializer + + Magento\ProductReviewDataExporter\Model\Indexer\MarkRemovedRatingMetadata + From 2646128a3a329a1e5869be983a221d8051065fb3 Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Tue, 20 Oct 2020 14:16:49 +0300 Subject: [PATCH 07/24] Support for ratings & reviews in Storefront App - Reviews and rating metadata callbacks --- .../CatalogExport/Event/Data/Entity.php | 10 ++-- .../Model/ChangedEntitiesMessageBuilder.php | 4 +- .../Model/Indexer/EntityIndexerCallback.php | 10 ++-- .../CatalogExport/etc/communication.xml | 2 + app/code/Magento/CatalogExport/etc/di.xml | 23 ++++++++++ .../CatalogExport/etc/queue_publisher.xml | 6 +++ .../CatalogExport/etc/queue_topology.xml | 2 + .../ProductReviewDataExporter/etc/di.xml | 46 +++++++++++++++++++ 8 files changed, 91 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/CatalogExport/Event/Data/Entity.php b/app/code/Magento/CatalogExport/Event/Data/Entity.php index 0d27bd082..6a82a09b8 100644 --- a/app/code/Magento/CatalogExport/Event/Data/Entity.php +++ b/app/code/Magento/CatalogExport/Event/Data/Entity.php @@ -14,7 +14,7 @@ class Entity { /** - * @var int + * @var string */ private $entityId; @@ -26,9 +26,9 @@ class Entity /** * Get entity id. * - * @return int + * @return string */ - public function getEntityId(): int + public function getEntityId(): string { return $this->entityId; } @@ -36,11 +36,11 @@ public function getEntityId(): int /** * Set entity id. * - * @param int $entityId + * @param string $entityId * * @return void */ - public function setEntityId(int $entityId): void + public function setEntityId(string $entityId): void { $this->entityId = $entityId; } diff --git a/app/code/Magento/CatalogExport/Model/ChangedEntitiesMessageBuilder.php b/app/code/Magento/CatalogExport/Model/ChangedEntitiesMessageBuilder.php index 2ff0b8d03..286330a04 100644 --- a/app/code/Magento/CatalogExport/Model/ChangedEntitiesMessageBuilder.php +++ b/app/code/Magento/CatalogExport/Model/ChangedEntitiesMessageBuilder.php @@ -65,7 +65,7 @@ public function __construct( * * @return \Magento\CatalogExport\Event\Data\ChangedEntities */ - public function build(string $eventType, array $entities, string $scope): ChangedEntities + public function build(string $eventType, array $entities, string $scope = null): ChangedEntities { $meta = $this->metaFactory->create(); $meta->setScope($scope); @@ -74,7 +74,7 @@ public function build(string $eventType, array $entities, string $scope): Change $entitiesArray = []; foreach ($entities as $entityData) { $entity = $this->entityFactory->create(); - $entity->setEntityId($entityData['entity_id']); + $entity->setEntityId((string)$entityData['entity_id']); $entity->setAttributes($entityData['attributes'] ?? []); $entitiesArray[] = $entity; diff --git a/app/code/Magento/CatalogExport/Model/Indexer/EntityIndexerCallback.php b/app/code/Magento/CatalogExport/Model/Indexer/EntityIndexerCallback.php index 5f4c6b19b..6ed4ebda5 100644 --- a/app/code/Magento/CatalogExport/Model/Indexer/EntityIndexerCallback.php +++ b/app/code/Magento/CatalogExport/Model/Indexer/EntityIndexerCallback.php @@ -135,8 +135,8 @@ private function getDeleteEntitiesData(array $deleteIds): array $deleted = []; $feed = $this->feedPool->getFeed($this->feedIndexMetadata->getFeedName()); foreach ($feed->getDeletedByIds($deleteIds) as $entity) { - $deleted[$entity['storeViewCode']][] = [ - 'entity_id' => (int)$entity[$this->feedIndexMetadata->getFeedIdentity()], + $deleted[$entity['storeViewCode'] ?? null][] = [ + 'entity_id' => $entity[$this->feedIndexMetadata->getFeedIdentity()], ]; } @@ -154,8 +154,8 @@ private function getUpdateEntitiesData(array $entityData): array { $entitiesArray = []; foreach ($entityData as $entity) { - $entitiesArray[$entity['storeViewCode']][] = [ - 'entity_id' => (int)$entity[$this->feedIndexMetadata->getFeedIdentity()], + $entitiesArray[$entity['storeViewCode'] ?? null][] = [ + 'entity_id' => $entity[$this->feedIndexMetadata->getFeedIdentity()], 'attributes' => $entity['attributes'] ?? [], ]; } @@ -174,7 +174,7 @@ private function getUpdateEntitiesData(array $entityData): array */ private function publishMessage(string $eventType, array $entities, string $scope): void { - $message = $this->messageBuilder->build($eventType, $entities, $scope); + $message = $this->messageBuilder->build($eventType, $entities, $scope ?: null); try { $this->queuePublisher->publish($this->topicName, $message); diff --git a/app/code/Magento/CatalogExport/etc/communication.xml b/app/code/Magento/CatalogExport/etc/communication.xml index ad696c117..a096412ab 100644 --- a/app/code/Magento/CatalogExport/etc/communication.xml +++ b/app/code/Magento/CatalogExport/etc/communication.xml @@ -8,4 +8,6 @@ + + diff --git a/app/code/Magento/CatalogExport/etc/di.xml b/app/code/Magento/CatalogExport/etc/di.xml index 0a30d68f2..c643e085b 100644 --- a/app/code/Magento/CatalogExport/etc/di.xml +++ b/app/code/Magento/CatalogExport/etc/di.xml @@ -10,6 +10,9 @@ + + + CatalogStorefrontConnectorLogger @@ -45,4 +48,24 @@ + + + + Magento\ProductReviewDataExporter\Model\Indexer\ProductReviewsFeedIndexMetadata + export.product.reviews + reviews_updated + reviews_deleted + + + + + + Magento\ProductReviewDataExporter\Model\Indexer\RatingFeedIndexMetadata + export.rating.metadata + rating_metadata_updated + rating_metadata_deleted + + diff --git a/app/code/Magento/CatalogExport/etc/queue_publisher.xml b/app/code/Magento/CatalogExport/etc/queue_publisher.xml index d143286af..6ad24fa53 100644 --- a/app/code/Magento/CatalogExport/etc/queue_publisher.xml +++ b/app/code/Magento/CatalogExport/etc/queue_publisher.xml @@ -12,4 +12,10 @@ + + + + + + diff --git a/app/code/Magento/CatalogExport/etc/queue_topology.xml b/app/code/Magento/CatalogExport/etc/queue_topology.xml index 359b2498f..d89b265d3 100644 --- a/app/code/Magento/CatalogExport/etc/queue_topology.xml +++ b/app/code/Magento/CatalogExport/etc/queue_topology.xml @@ -9,5 +9,7 @@ + + diff --git a/app/code/Magento/ProductReviewDataExporter/etc/di.xml b/app/code/Magento/ProductReviewDataExporter/etc/di.xml index 40ea4e281..df4e6bd09 100644 --- a/app/code/Magento/ProductReviewDataExporter/etc/di.xml +++ b/app/code/Magento/ProductReviewDataExporter/etc/di.xml @@ -32,18 +32,34 @@ + + + Magento\ProductReviewDataExporter\Model\Indexer\ProductReviewsFeedIndexMetadata + + Magento\ProductReviewDataExporter\Model\Indexer\ReviewsIndexerCallbackInterface + Magento\ProductReviewDataExporter\Model\Indexer\ProductReviewsDataSerializer + + + + Magento\ProductReviewDataExporter\Model\Indexer\ProductReviewsFeedIndexMetadata + + + + @@ -74,12 +90,20 @@ + + + Magento\ProductReviewDataExporter\Model\Indexer\RatingFeedIndexMetadata + + Magento\ProductReviewDataExporter\Model\Indexer\RatingMetadataIndexerCallbackInterface + Magento\ProductReviewDataExporter\Model\Indexer\RatingDataSerializer @@ -88,4 +112,26 @@ + + + + + Magento\ProductReviewDataExporter\Model\Indexer\RatingFeedIndexMetadata + + + + + + + + + + Magento\ProductReviewDataExporter\Model\ReviewsFeed + + + Magento\ProductReviewDataExporter\Model\RatingMetadataFeed + + + + From aaf6fd7186dfead29fbfe4fcdb436bd5b04ddbba Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Wed, 21 Oct 2020 02:28:15 +0300 Subject: [PATCH 08/24] Support for ratings & reviews in Storefront App - Review repository --- .../Console/Command/GenerateDTOFiles.php | 2 + .../CatalogExport/Model/ReviewRepository.php | 90 ++++++++ app/code/Magento/CatalogExport/etc/di.xml | 1 + app/code/Magento/CatalogExport/etc/module.xml | 1 + app/code/Magento/CatalogExport/etc/webapi.xml | 6 + .../CatalogExportApi/Api/Data/Rating.php | 73 ++++++ .../Api/Data/RatingMetadata.php | 121 ++++++++++ .../CatalogExportApi/Api/Data/RatingValue.php | 97 ++++++++ .../CatalogExportApi/Api/Data/Review.php | 217 ++++++++++++++++++ .../Api/ReviewRepositoryInterface.php | 22 ++ 10 files changed, 630 insertions(+) create mode 100644 app/code/Magento/CatalogExport/Model/ReviewRepository.php create mode 100644 app/code/Magento/CatalogExportApi/Api/Data/Rating.php create mode 100644 app/code/Magento/CatalogExportApi/Api/Data/RatingMetadata.php create mode 100644 app/code/Magento/CatalogExportApi/Api/Data/RatingValue.php create mode 100644 app/code/Magento/CatalogExportApi/Api/Data/Review.php create mode 100644 app/code/Magento/CatalogExportApi/Api/ReviewRepositoryInterface.php diff --git a/app/code/Magento/CatalogExport/Console/Command/GenerateDTOFiles.php b/app/code/Magento/CatalogExport/Console/Command/GenerateDTOFiles.php index 5cc38a372..bb2d421f4 100644 --- a/app/code/Magento/CatalogExport/Console/Command/GenerateDTOFiles.php +++ b/app/code/Magento/CatalogExport/Console/Command/GenerateDTOFiles.php @@ -68,6 +68,8 @@ class GenerateDTOFiles extends Command 'Product', 'Category', 'ProductVariant', + 'Review', + 'RatingMetadata', ]; /** diff --git a/app/code/Magento/CatalogExport/Model/ReviewRepository.php b/app/code/Magento/CatalogExport/Model/ReviewRepository.php new file mode 100644 index 000000000..668767149 --- /dev/null +++ b/app/code/Magento/CatalogExport/Model/ReviewRepository.php @@ -0,0 +1,90 @@ +feedPool = $feedPool; + $this->reviewFactory = $reviewFactory; + $this->dataObjectHelper = $dataObjectHelper; + $this->exportConfiguration = $exportConfiguration; + } + + /** + * @inheritdoc + */ + public function get(EntityRequest $request) + { + $ids = \array_map(function (Item $item) { + return $item->getEntityId(); + }, $request->getEntities()); + + if (count($ids) > $this->exportConfiguration->getMaxItemsInResponse()) { + throw new \InvalidArgumentException( + 'Max items in the response can\'t exceed ' + . $this->exportConfiguration->getMaxItemsInResponse() + . '.' + ); + } + + $reviews = []; + $feedData = $this->feedPool->getFeed('reviews')->getFeedByIds($ids); + + foreach ($feedData['feed'] as $feedItem) { + $review = $this->reviewFactory->create(); + $feedItem['id'] = $feedItem['reviewId']; + $this->dataObjectHelper->populateWithArray($review, $feedItem, Review::class); + $reviews[] = $review; + } + + return $reviews; + } +} diff --git a/app/code/Magento/CatalogExport/etc/di.xml b/app/code/Magento/CatalogExport/etc/di.xml index c643e085b..c3837681a 100644 --- a/app/code/Magento/CatalogExport/etc/di.xml +++ b/app/code/Magento/CatalogExport/etc/di.xml @@ -8,6 +8,7 @@ + diff --git a/app/code/Magento/CatalogExport/etc/module.xml b/app/code/Magento/CatalogExport/etc/module.xml index ccccaceff..1a0eb97b1 100644 --- a/app/code/Magento/CatalogExport/etc/module.xml +++ b/app/code/Magento/CatalogExport/etc/module.xml @@ -9,6 +9,7 @@ + diff --git a/app/code/Magento/CatalogExport/etc/webapi.xml b/app/code/Magento/CatalogExport/etc/webapi.xml index 5f95a8853..c716108ad 100644 --- a/app/code/Magento/CatalogExport/etc/webapi.xml +++ b/app/code/Magento/CatalogExport/etc/webapi.xml @@ -23,4 +23,10 @@ + + + + + + diff --git a/app/code/Magento/CatalogExportApi/Api/Data/Rating.php b/app/code/Magento/CatalogExportApi/Api/Data/Rating.php new file mode 100644 index 000000000..ae0882ae4 --- /dev/null +++ b/app/code/Magento/CatalogExportApi/Api/Data/Rating.php @@ -0,0 +1,73 @@ +ratingId; + } + + /** + * Set rating id + * + * @param string $ratingId + * @return void + */ + public function setRatingId(?string $ratingId): void + { + $this->ratingId = $ratingId; + } + + /** + * Get value + * + * @return string + */ + public function getValue(): ?string + { + return $this->value; + } + + /** + * Set value + * + * @param string $value + * @return void + */ + public function setValue(?string $value): void + { + $this->value = $value; + } +} diff --git a/app/code/Magento/CatalogExportApi/Api/Data/RatingMetadata.php b/app/code/Magento/CatalogExportApi/Api/Data/RatingMetadata.php new file mode 100644 index 000000000..c654ebabb --- /dev/null +++ b/app/code/Magento/CatalogExportApi/Api/Data/RatingMetadata.php @@ -0,0 +1,121 @@ +ratingId; + } + + /** + * Set rating id + * + * @param string $ratingId + * @return void + */ + public function setRatingId(?string $ratingId): void + { + $this->ratingId = $ratingId; + } + + /** + * Get store view code + * + * @return string + */ + public function getStoreViewCode(): ?string + { + return $this->storeViewCode; + } + + /** + * Set store view code + * + * @param string $storeViewCode + * @return void + */ + public function setStoreViewCode(?string $storeViewCode): void + { + $this->storeViewCode = $storeViewCode; + } + + /** + * Get name + * + * @return string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * Set name + * + * @param string $name + * @return void + */ + public function setName(?string $name): void + { + $this->name = $name; + } + + /** + * Get values + * + * @return \Magento\CatalogExportApi\Api\Data\RatingValue[]|null + */ + public function getValues(): ?array + { + return $this->values; + } + + /** + * Set values + * + * @param \Magento\CatalogExportApi\Api\Data\RatingValue[] $values + * @return void + */ + public function setValues(?array $values = null): void + { + $this->values = $values; + } +} diff --git a/app/code/Magento/CatalogExportApi/Api/Data/RatingValue.php b/app/code/Magento/CatalogExportApi/Api/Data/RatingValue.php new file mode 100644 index 000000000..a32cad217 --- /dev/null +++ b/app/code/Magento/CatalogExportApi/Api/Data/RatingValue.php @@ -0,0 +1,97 @@ +valueId; + } + + /** + * Set value id + * + * @param string $valueId + * @return void + */ + public function setValueId(?string $valueId): void + { + $this->valueId = $valueId; + } + + /** + * Get value + * + * @return string + */ + public function getValue(): ?string + { + return $this->value; + } + + /** + * Set value + * + * @param string $value + * @return void + */ + public function setValue(?string $value): void + { + $this->value = $value; + } + + /** + * Get position + * + * @return int + */ + public function getPosition(): ?int + { + return $this->position; + } + + /** + * Set position + * + * @param int $position + * @return void + */ + public function setPosition(?int $position): void + { + $this->position = $position; + } +} diff --git a/app/code/Magento/CatalogExportApi/Api/Data/Review.php b/app/code/Magento/CatalogExportApi/Api/Data/Review.php new file mode 100644 index 000000000..a426d7305 --- /dev/null +++ b/app/code/Magento/CatalogExportApi/Api/Data/Review.php @@ -0,0 +1,217 @@ +reviewId; + } + + /** + * Set review id + * + * @param string $reviewId + * @return void + */ + public function setReviewId(?string $reviewId): void + { + $this->reviewId = $reviewId; + } + + /** + * Get product id + * + * @return int + */ + public function getProductId(): ?int + { + return $this->productId; + } + + /** + * Set product id + * + * @param int $productId + * @return void + */ + public function setProductId(?int $productId): void + { + $this->productId = $productId; + } + + /** + * Get visibility + * + * @return string[] + */ + public function getVisibility(): ?array + { + return $this->visibility; + } + + /** + * Set visibility + * + * @param string[] $visibility + * @return void + */ + public function setVisibility(?array $visibility = null): void + { + $this->visibility = $visibility; + } + + /** + * Get title + * + * @return string + */ + public function getTitle(): ?string + { + return $this->title; + } + + /** + * Set title + * + * @param string $title + * @return void + */ + public function setTitle(?string $title): void + { + $this->title = $title; + } + + /** + * Get nickname + * + * @return string + */ + public function getNickname(): ?string + { + return $this->nickname; + } + + /** + * Set nickname + * + * @param string $nickname + * @return void + */ + public function setNickname(?string $nickname): void + { + $this->nickname = $nickname; + } + + /** + * Get text + * + * @return string + */ + public function getText(): ?string + { + return $this->text; + } + + /** + * Set text + * + * @param string $text + * @return void + */ + public function setText(?string $text): void + { + $this->text = $text; + } + + /** + * Get customer id + * + * @return string + */ + public function getCustomerId(): ?string + { + return $this->customerId; + } + + /** + * Set customer id + * + * @param string $customerId + * @return void + */ + public function setCustomerId(?string $customerId): void + { + $this->customerId = $customerId; + } + + /** + * Get ratings + * + * @return \Magento\CatalogExportApi\Api\Data\Rating[]|null + */ + public function getRatings(): ?array + { + return $this->ratings; + } + + /** + * Set ratings + * + * @param \Magento\CatalogExportApi\Api\Data\Rating[] $ratings + * @return void + */ + public function setRatings(?array $ratings = null): void + { + $this->ratings = $ratings; + } +} diff --git a/app/code/Magento/CatalogExportApi/Api/ReviewRepositoryInterface.php b/app/code/Magento/CatalogExportApi/Api/ReviewRepositoryInterface.php new file mode 100644 index 000000000..6a2585d25 --- /dev/null +++ b/app/code/Magento/CatalogExportApi/Api/ReviewRepositoryInterface.php @@ -0,0 +1,22 @@ + Date: Wed, 21 Oct 2020 15:31:52 +0300 Subject: [PATCH 09/24] Support for ratings & reviews in Storefront App - Rating metadata repository --- .../Model/RatingMetadataRepository.php | 91 +++++++++++++++++++ app/code/Magento/CatalogExport/etc/di.xml | 1 + app/code/Magento/CatalogExport/etc/webapi.xml | 6 ++ .../Api/EntityRequest/Item.php | 10 +- .../Api/RatingMetadataRepositoryInterface.php | 24 +++++ .../Api/ReviewRepositoryInterface.php | 4 +- 6 files changed, 130 insertions(+), 6 deletions(-) create mode 100644 app/code/Magento/CatalogExport/Model/RatingMetadataRepository.php create mode 100644 app/code/Magento/CatalogExportApi/Api/RatingMetadataRepositoryInterface.php diff --git a/app/code/Magento/CatalogExport/Model/RatingMetadataRepository.php b/app/code/Magento/CatalogExport/Model/RatingMetadataRepository.php new file mode 100644 index 000000000..cd9ee254f --- /dev/null +++ b/app/code/Magento/CatalogExport/Model/RatingMetadataRepository.php @@ -0,0 +1,91 @@ +feedPool = $feedPool; + $this->ratingMetadataFactory = $ratingMetadataFactory; + $this->dataObjectHelper = $dataObjectHelper; + $this->exportConfiguration = $exportConfiguration; + } + + /** + * @inheritdoc + */ + public function get(EntityRequest $request) + { + $storeViewCodes = $request->getStoreViewCodes(); + $ids = \array_map(function (Item $item) { + return $item->getEntityId(); + }, $request->getEntities()); + + if (count($ids) > $this->exportConfiguration->getMaxItemsInResponse()) { + throw new \InvalidArgumentException( + 'Max items in the response can\'t exceed ' + . $this->exportConfiguration->getMaxItemsInResponse() + . '.' + ); + } + + $ratingsMetadata = []; + $feedData = $this->feedPool->getFeed('ratingMetadata')->getFeedByIds($ids, $storeViewCodes); + + foreach ($feedData['feed'] as $feedItem) { + $ratingMetadata = $this->ratingMetadataFactory->create(); + $feedItem['id'] = $feedItem['ratingId']; + $this->dataObjectHelper->populateWithArray($ratingMetadata, $feedItem, RatingMetadata::class); + $ratingsMetadata[] = $ratingMetadata; + } + + return $ratingsMetadata; + } +} diff --git a/app/code/Magento/CatalogExport/etc/di.xml b/app/code/Magento/CatalogExport/etc/di.xml index c3837681a..171b81319 100644 --- a/app/code/Magento/CatalogExport/etc/di.xml +++ b/app/code/Magento/CatalogExport/etc/di.xml @@ -9,6 +9,7 @@ + diff --git a/app/code/Magento/CatalogExport/etc/webapi.xml b/app/code/Magento/CatalogExport/etc/webapi.xml index c716108ad..ebcb60573 100644 --- a/app/code/Magento/CatalogExport/etc/webapi.xml +++ b/app/code/Magento/CatalogExport/etc/webapi.xml @@ -29,4 +29,10 @@ + + + + + + diff --git a/app/code/Magento/CatalogExportApi/Api/EntityRequest/Item.php b/app/code/Magento/CatalogExportApi/Api/EntityRequest/Item.php index 3ab72e7e3..6925c8515 100644 --- a/app/code/Magento/CatalogExportApi/Api/EntityRequest/Item.php +++ b/app/code/Magento/CatalogExportApi/Api/EntityRequest/Item.php @@ -14,7 +14,7 @@ class Item { /** - * @var int + * @var string */ private $entityId; @@ -26,9 +26,9 @@ class Item /** * Get requested entity id. * - * @return int + * @return string */ - public function getEntityId(): int + public function getEntityId(): string { return $this->entityId; } @@ -36,11 +36,11 @@ public function getEntityId(): int /** * Set requested entity id. * - * @param int $entityId + * @param string $entityId * * @return void */ - public function setEntityId(int $entityId): void + public function setEntityId(string $entityId): void { $this->entityId = $entityId; } diff --git a/app/code/Magento/CatalogExportApi/Api/RatingMetadataRepositoryInterface.php b/app/code/Magento/CatalogExportApi/Api/RatingMetadataRepositoryInterface.php new file mode 100644 index 000000000..56f4e82f6 --- /dev/null +++ b/app/code/Magento/CatalogExportApi/Api/RatingMetadataRepositoryInterface.php @@ -0,0 +1,24 @@ + Date: Tue, 27 Oct 2020 03:56:08 +0200 Subject: [PATCH 10/24] Support for ratings & reviews in Storefront App - Reviews and ratings events --- .../Model/Indexer/FeedIndexer.php | 5 +- .../Indexer/MarkRemovedRatingMetadata.php | 74 ----------------- .../Model/Indexer/RatingDataSerializer.php | 76 ++++++++++++++++++ .../Model/Provider/RatingMetadata.php | 2 +- .../Plugin/ReindexRatingMetadataFeed.php | 80 +++++++++++++++++++ .../ReindexRatingMetadataFeedOnOptionSave.php | 54 +++++++++++++ .../etc/db_schema.xml | 8 +- .../ProductReviewDataExporter/etc/di.xml | 19 +++-- 8 files changed, 229 insertions(+), 89 deletions(-) delete mode 100644 app/code/Magento/ProductReviewDataExporter/Model/Indexer/MarkRemovedRatingMetadata.php create mode 100644 app/code/Magento/ProductReviewDataExporter/Model/Indexer/RatingDataSerializer.php create mode 100644 app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeed.php create mode 100644 app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeedOnOptionSave.php diff --git a/app/code/Magento/DataExporter/Model/Indexer/FeedIndexer.php b/app/code/Magento/DataExporter/Model/Indexer/FeedIndexer.php index d1d2ce80a..175acb3a1 100644 --- a/app/code/Magento/DataExporter/Model/Indexer/FeedIndexer.php +++ b/app/code/Magento/DataExporter/Model/Indexer/FeedIndexer.php @@ -145,7 +145,10 @@ public function executeFull() { $this->truncateFeedTable(); foreach ($this->getAllIds() as $ids) { - $this->markRemovedEntities->execute($ids, $this->feedIndexMetadata); + $this->markRemovedEntities->execute( + \array_column($ids, $this->feedIndexMetadata->getFeedIdentity()), + $this->feedIndexMetadata + ); $this->process($ids); } } diff --git a/app/code/Magento/ProductReviewDataExporter/Model/Indexer/MarkRemovedRatingMetadata.php b/app/code/Magento/ProductReviewDataExporter/Model/Indexer/MarkRemovedRatingMetadata.php deleted file mode 100644 index 27129f401..000000000 --- a/app/code/Magento/ProductReviewDataExporter/Model/Indexer/MarkRemovedRatingMetadata.php +++ /dev/null @@ -1,74 +0,0 @@ -resourceConnection = $resourceConnection; - } - - /** - * @inheritdoc - */ - public function execute(array $ids, FeedIndexMetadata $metadata): void - { - $connection = $this->resourceConnection->getConnection(); - $select = $connection->select() - ->joinLeft( - ['s' => $this->resourceConnection->getTableName($metadata->getSourceTableName())], - \sprintf( - new Expression('FROM_BASE64(f.%s)') . ' = s.%s', - $metadata->getFeedTableField(), - $metadata->getSourceTableField() - ), - ['is_deleted' => new \Zend_Db_Expr('1')] - ) - ->join( - ['st' => $this->resourceConnection->getTableName('store')], - 'f.store_view_code = st.code', - [] - ) - ->joinLeft( - ['sc' => $this->resourceConnection->getTableName($metadata->getScopeTableName())], - \sprintf( - 'sc.%s = s.%s AND sc.%3$s = st.%3$s', - $metadata->getScopeTableField(), - $metadata->getSourceTableField(), - $metadata->getScopeCode(), - ), - [] - ) - ->where(\sprintf('sc.%s IS NULL', $metadata->getScopeTableField())) - ->where(\sprintf('s.%s IN (?)', $metadata->getSourceTableField()), $ids); - - $update = $connection->updateFromSelect( - $select, - ['f' => $this->resourceConnection->getTableName($metadata->getFeedTableName())] - ); - - $connection->query($update); - } -} diff --git a/app/code/Magento/ProductReviewDataExporter/Model/Indexer/RatingDataSerializer.php b/app/code/Magento/ProductReviewDataExporter/Model/Indexer/RatingDataSerializer.php new file mode 100644 index 000000000..7587717d4 --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/Model/Indexer/RatingDataSerializer.php @@ -0,0 +1,76 @@ +serializer = $serializer; + $this->feedIdentity = $feedIdentity; + $this->mapping = $mapping; + } + + /** + * Serialize feed data + * + * @param array $data + * + * @return array + * + * @throws \InvalidArgumentException + */ + public function serialize(array $data): array + { + $output = []; + foreach ($data as $row) { + $outputRow = []; + + foreach ($this->mapping as $field => $index) { + $outputRow[$field] = isset($row[$index]) ? $row[$index] : null; + } + + // Keep feed table "id" decoded and encode "feed data identity" + $row[$this->feedIdentity] = \base64_encode($row[$this->feedIdentity]); + $outputRow['feed_data'] = $this->serializer->serialize($row); + $output[] = $outputRow; + } + + return $output; + } +} diff --git a/app/code/Magento/ProductReviewDataExporter/Model/Provider/RatingMetadata.php b/app/code/Magento/ProductReviewDataExporter/Model/Provider/RatingMetadata.php index 8873f8580..55b219a29 100644 --- a/app/code/Magento/ProductReviewDataExporter/Model/Provider/RatingMetadata.php +++ b/app/code/Magento/ProductReviewDataExporter/Model/Provider/RatingMetadata.php @@ -96,7 +96,7 @@ public function get(array $values): array private function formatRatingRow(array $row): array { return [ - 'ratingId' => \base64_encode($row['ratingId']), + 'ratingId' => $row['ratingId'], 'storeViewCode' => $row['storeViewCode'], 'name' => $row['name'], ]; diff --git a/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeed.php b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeed.php new file mode 100644 index 000000000..12b3813fb --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeed.php @@ -0,0 +1,80 @@ +indexerRegistry = $indexerRegistry; + } + + /** + * Execute reindex process on delete callback + * + * @param Rating $subject + * + * @return Rating + */ + public function beforeAfterDeleteCommit(Rating $subject): Rating + { + $this->reindex($subject); + + return $subject; + } + + /** + * Execute reindex process on save commit callback + * + * @param Rating $subject + * + * @return Rating + */ + public function beforeAfterCommitCallback(Rating $subject): Rating + { + $this->reindex($subject); + + return $subject; + } + + /** + * Re-indexation process of rating metadata feed + * + * @param Rating $rating + * + * @return void + */ + public function reindex(Rating $rating): void + { + $indexer = $this->indexerRegistry->get(self::RATING_METADATA_FEED_INDEXER); + if (!$indexer->isScheduled()) { + $indexer->reindexRow($rating->getId()); + } + } +} diff --git a/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeedOnOptionSave.php b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeedOnOptionSave.php new file mode 100644 index 000000000..f7a82bcaf --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeedOnOptionSave.php @@ -0,0 +1,54 @@ +indexerRegistry = $indexerRegistry; + } + + /** + * Execute reindex process on save commit callback + * + * @param Option $subject + * + * @return Option + */ + public function beforeAfterCommitCallback(Option $subject): Option + { + $indexer = $this->indexerRegistry->get(self::RATING_METADATA_FEED_INDEXER); + if (!$indexer->isScheduled()) { + $indexer->reindexRow($subject->getRatingId()); + } + + return $subject; + } +} diff --git a/app/code/Magento/ProductReviewDataExporter/etc/db_schema.xml b/app/code/Magento/ProductReviewDataExporter/etc/db_schema.xml index 156405619..b1602fa5c 100644 --- a/app/code/Magento/ProductReviewDataExporter/etc/db_schema.xml +++ b/app/code/Magento/ProductReviewDataExporter/etc/db_schema.xml @@ -42,13 +42,7 @@ resource="default" engine="innodb" comment="Product Rating Metadata Feed Storage"> - - + - + + ratingId ratingId storeViewCode - + @@ -107,9 +107,6 @@ Magento\ProductReviewDataExporter\Model\Indexer\RatingDataSerializer - - Magento\ProductReviewDataExporter\Model\Indexer\MarkRemovedRatingMetadata - @@ -134,4 +131,14 @@ + + + + + + + + From 161bbebef9bf588566db593b95a75af5da725ab9 Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Tue, 27 Oct 2020 03:57:01 +0200 Subject: [PATCH 11/24] Support for ratings & reviews in Storefront App - Reviews and ratings events --- .../Plugin/ReindexRatingMetadataFeed.php | 2 +- .../Plugin/ReindexReviewFeed.php | 80 +++++++++++++++++++ .../Plugin/ReindexReviewFeedOnVoteAdd.php | 60 ++++++++++++++ .../ProductReviewDataExporter/etc/di.xml | 8 ++ 4 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeed.php create mode 100644 app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeedOnVoteAdd.php diff --git a/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeed.php b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeed.php index 12b3813fb..2ba3318ed 100644 --- a/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeed.php +++ b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeed.php @@ -12,7 +12,7 @@ use Magento\Review\Model\Rating; /** - * Plugin for running rating metadata feed indexation during saving / deleting process + * Plugin for running rating metadata feed indexation during save / delete operation */ class ReindexRatingMetadataFeed { diff --git a/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeed.php b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeed.php new file mode 100644 index 000000000..30b147617 --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeed.php @@ -0,0 +1,80 @@ +indexerRegistry = $indexerRegistry; + } + + /** + * Execute reindex process on delete callback + * + * @param Review $subject + * + * @return Review + */ + public function beforeAfterDeleteCommit(Review $subject): Review + { + $this->reindex($subject); + + return $subject; + } + + /** + * Execute reindex process on save commit callback + * + * @param Review $subject + * + * @return Review + */ + public function beforeAfterCommitCallback(Review $subject): Review + { + $this->reindex($subject); + + return $subject; + } + + /** + * Re-indexation process of review feed + * + * @param Review $review + * + * @return void + */ + public function reindex(Review $review): void + { + $indexer = $this->indexerRegistry->get(self::REVIEW_FEED_INDEXER); + if (!$indexer->isScheduled()) { + $indexer->reindexRow($review->getId()); + } + } +} diff --git a/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeedOnVoteAdd.php b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeedOnVoteAdd.php new file mode 100644 index 000000000..7becd4536 --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeedOnVoteAdd.php @@ -0,0 +1,60 @@ +indexerRegistry = $indexerRegistry; + } + + /** + * Execute review reindex process on add vote operation + * + * @param RatingOptionResource $subject + * @param RatingOptionResource $result + * @param Option $option + * + * @return RatingOptionResource + */ + public function afterAddVote( + RatingOptionResource $subject, + RatingOptionResource $result, + Option $option + ): RatingOptionResource { + $indexer = $this->indexerRegistry->get(self::REVIEW_FEED_INDEXER); + if (!$indexer->isScheduled()) { + $indexer->reindexRow($option->getReviewId()); + } + + return $result; + } +} diff --git a/app/code/Magento/ProductReviewDataExporter/etc/di.xml b/app/code/Magento/ProductReviewDataExporter/etc/di.xml index 8436c18f6..b55d4de29 100644 --- a/app/code/Magento/ProductReviewDataExporter/etc/di.xml +++ b/app/code/Magento/ProductReviewDataExporter/etc/di.xml @@ -141,4 +141,12 @@ + + + + + + From 79d1543283112488a4d59401d3c60c3d99a0b3d5 Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Fri, 30 Oct 2020 00:21:35 +0200 Subject: [PATCH 12/24] Support for ratings & reviews in Storefront App - Export reviews w/o rating assigned --- .../Model/Provider/ProductReviews.php | 11 +++++++---- .../Model/Query/ProductReviewsQuery.php | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/ProductReviewDataExporter/Model/Provider/ProductReviews.php b/app/code/Magento/ProductReviewDataExporter/Model/Provider/ProductReviews.php index 149ca0e70..3e0e5f58d 100644 --- a/app/code/Magento/ProductReviewDataExporter/Model/Provider/ProductReviews.php +++ b/app/code/Magento/ProductReviewDataExporter/Model/Provider/ProductReviews.php @@ -72,10 +72,13 @@ public function get(array $values): array while ($row = $cursor->fetch()) { $key = $row['reviewId']; $output[$key] = $output[$key] ?? $this->formatReviewRow($row); - $output[$key]['ratings'][] = [ - 'ratingId' => \base64_encode($row['ratingId']), - 'value' => $row['ratingValue'], - ]; + + if (null !== $row['ratingId']) { + $output[$key]['ratings'][] = [ + 'ratingId' => \base64_encode($row['ratingId']), + 'value' => $row['ratingValue'], + ]; + } } } catch (\Throwable $exception) { $this->logger->error($exception->getMessage()); diff --git a/app/code/Magento/ProductReviewDataExporter/Model/Query/ProductReviewsQuery.php b/app/code/Magento/ProductReviewDataExporter/Model/Query/ProductReviewsQuery.php index fe6397fbf..ccc739efe 100644 --- a/app/code/Magento/ProductReviewDataExporter/Model/Query/ProductReviewsQuery.php +++ b/app/code/Magento/ProductReviewDataExporter/Model/Query/ProductReviewsQuery.php @@ -65,12 +65,12 @@ public function getQuery(array $reviewIds) : Select 'r.entity_id = re.entity_id', [] ) - ->join( + ->joinLeft( ['rov' => $this->resourceConnection->getTableName('rating_option_vote')], 'r.review_id = rov.review_id', [] ) - ->join( + ->joinLeft( ['ro' => $this->resourceConnection->getTableName('rating_option')], 'rov.option_id = ro.option_id', [] From 57f2980d5cb5f11bf84d71563112e149513d38b5 Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Mon, 2 Nov 2020 14:53:31 +0200 Subject: [PATCH 13/24] Support for ratings & reviews in Storefront App - Tests fix --- app/code/Magento/CatalogExport/Event/Data/Entity.php | 10 +++++----- .../Model/ChangedEntitiesMessageBuilder.php | 2 +- .../Api/RatingMetadataRepositoryInterface.php | 2 +- .../DataExporter/Model/Indexer/FeedIndexMetadata.php | 10 ++++++---- .../Plugin/ReindexReviewFeedOnVoteAdd.php | 2 ++ .../Magento/ProductReviewDataExporter/composer.json | 4 +++- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/CatalogExport/Event/Data/Entity.php b/app/code/Magento/CatalogExport/Event/Data/Entity.php index 6a82a09b8..0d27bd082 100644 --- a/app/code/Magento/CatalogExport/Event/Data/Entity.php +++ b/app/code/Magento/CatalogExport/Event/Data/Entity.php @@ -14,7 +14,7 @@ class Entity { /** - * @var string + * @var int */ private $entityId; @@ -26,9 +26,9 @@ class Entity /** * Get entity id. * - * @return string + * @return int */ - public function getEntityId(): string + public function getEntityId(): int { return $this->entityId; } @@ -36,11 +36,11 @@ public function getEntityId(): string /** * Set entity id. * - * @param string $entityId + * @param int $entityId * * @return void */ - public function setEntityId(string $entityId): void + public function setEntityId(int $entityId): void { $this->entityId = $entityId; } diff --git a/app/code/Magento/CatalogExport/Model/ChangedEntitiesMessageBuilder.php b/app/code/Magento/CatalogExport/Model/ChangedEntitiesMessageBuilder.php index 286330a04..fa0e8a39e 100644 --- a/app/code/Magento/CatalogExport/Model/ChangedEntitiesMessageBuilder.php +++ b/app/code/Magento/CatalogExport/Model/ChangedEntitiesMessageBuilder.php @@ -74,7 +74,7 @@ public function build(string $eventType, array $entities, string $scope = null): $entitiesArray = []; foreach ($entities as $entityData) { $entity = $this->entityFactory->create(); - $entity->setEntityId((string)$entityData['entity_id']); + $entity->setEntityId((int)$entityData['entity_id']); $entity->setAttributes($entityData['attributes'] ?? []); $entitiesArray[] = $entity; diff --git a/app/code/Magento/CatalogExportApi/Api/RatingMetadataRepositoryInterface.php b/app/code/Magento/CatalogExportApi/Api/RatingMetadataRepositoryInterface.php index 56f4e82f6..b62f8cb1d 100644 --- a/app/code/Magento/CatalogExportApi/Api/RatingMetadataRepositoryInterface.php +++ b/app/code/Magento/CatalogExportApi/Api/RatingMetadataRepositoryInterface.php @@ -7,7 +7,7 @@ namespace Magento\CatalogExportApi\Api; /** - * Rating metadata repository interface + * Rating metadata entity repository interface */ interface RatingMetadataRepositoryInterface { diff --git a/app/code/Magento/DataExporter/Model/Indexer/FeedIndexMetadata.php b/app/code/Magento/DataExporter/Model/Indexer/FeedIndexMetadata.php index d9d76a4b3..76e6219d8 100644 --- a/app/code/Magento/DataExporter/Model/Indexer/FeedIndexMetadata.php +++ b/app/code/Magento/DataExporter/Model/Indexer/FeedIndexMetadata.php @@ -71,14 +71,16 @@ class FeedIndexMetadata * @param string $feedName * @param string $sourceTableName * @param string $sourceTableField - * @param string $scopeTableName - * @param string $scopeTableField - * @param string $scopeCode * @param string $feedIdentity * @param string $feedTableName * @param string $feedTableField - * @param string[] $feedTableMutableColumns + * @param array $feedTableMutableColumns + * @param string $scopeTableName + * @param string $scopeTableField + * @param string $scopeCode * @param int $batchSize + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( string $feedName, diff --git a/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeedOnVoteAdd.php b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeedOnVoteAdd.php index 7becd4536..2337953f2 100644 --- a/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeedOnVoteAdd.php +++ b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeedOnVoteAdd.php @@ -44,6 +44,8 @@ public function __construct( * @param Option $option * * @return RatingOptionResource + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterAddVote( RatingOptionResource $subject, diff --git a/app/code/Magento/ProductReviewDataExporter/composer.json b/app/code/Magento/ProductReviewDataExporter/composer.json index b0cf953b2..f10d11c08 100644 --- a/app/code/Magento/ProductReviewDataExporter/composer.json +++ b/app/code/Magento/ProductReviewDataExporter/composer.json @@ -20,6 +20,8 @@ "require": { "php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0", "magento/framework": "*", - "magento/module-data-exporter": "*" + "magento/module-data-exporter": "*", + "magento/module-review": "*", + "magento/module-store": "*" } } From ad44ece5222d59a32cff089f104fc4196d2020eb Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Thu, 5 Nov 2020 14:28:29 +0200 Subject: [PATCH 14/24] Support for ratings & reviews in Storefront App - Mark removed reviews on product delete --- .../MarkRemovedReviewsOnProductDelete.php | 98 +++++++++++++++++++ .../etc/db_schema.xml | 7 ++ .../etc/db_schema_whitelist.json | 3 +- .../ProductReviewDataExporter/etc/di.xml | 13 +++ 4 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/ProductReviewDataExporter/Plugin/MarkRemovedReviewsOnProductDelete.php diff --git a/app/code/Magento/ProductReviewDataExporter/Plugin/MarkRemovedReviewsOnProductDelete.php b/app/code/Magento/ProductReviewDataExporter/Plugin/MarkRemovedReviewsOnProductDelete.php new file mode 100644 index 000000000..8a2eefb52 --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/Plugin/MarkRemovedReviewsOnProductDelete.php @@ -0,0 +1,98 @@ +indexerRegistry = $indexerRegistry; + $this->feedIndexMetadata = $feedIndexMetadata; + $this->resourceConnection = $resourceConnection; + } + + /** + * Execute marking removed reviews after product removal + * + * @param ReviewResource $subject + * @param ReviewResource $result + * @param int $productId + * + * @return ReviewResource + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterDeleteReviewsByProductId( + ReviewResource $subject, + ReviewResource $result, + int $productId + ): ReviewResource { + $indexer = $this->indexerRegistry->get(self::REVIEW_FEED_INDEXER); + if (!$indexer->isScheduled()) { + $indexer->reindexList($this->fetchReviewIdsByProductId($productId)); + } + + return $result; + } + + /** + * Fetch existing review ids from feed by product id + * + * @param int $productId + * + * @return array + */ + private function fetchReviewIdsByProductId(int $productId): array + { + $select = $this->resourceConnection->getConnection() + ->select() + ->from( + ['f' => $this->resourceConnection->getTableName($this->feedIndexMetadata->getFeedTableName())], + [$this->feedIndexMetadata->getFeedTableField()] + )->where('f.product_id = ?', $productId); + + return $this->resourceConnection->getConnection()->fetchCol($select); + } +} diff --git a/app/code/Magento/ProductReviewDataExporter/etc/db_schema.xml b/app/code/Magento/ProductReviewDataExporter/etc/db_schema.xml index b1602fa5c..bfcc0b38a 100644 --- a/app/code/Magento/ProductReviewDataExporter/etc/db_schema.xml +++ b/app/code/Magento/ProductReviewDataExporter/etc/db_schema.xml @@ -12,6 +12,13 @@ engine="innodb" comment="Product Reviews Feed Storage"> + reviewId + productId @@ -149,4 +150,16 @@ + + + + + + + + Magento\ProductReviewDataExporter\Model\Indexer\ProductReviewsFeedIndexMetadata + + + From b780b964043bad7864e522492a36f83c8b917e90 Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Mon, 9 Nov 2020 22:10:52 +0200 Subject: [PATCH 15/24] Support for ratings & reviews in Storefront App - Reindex on save --- .../CatalogExport/Event/Data/Entity.php | 10 ++-- .../Model/ChangedEntitiesMessageBuilder.php | 4 +- .../Model/Indexer/ReindexOnSaveAction.php | 58 +++++++++++++++++++ .../MarkRemovedReviewsOnProductDelete.php | 25 ++++---- .../Plugin/ReindexRatingMetadataFeed.php | 36 +++--------- .../ReindexRatingMetadataFeedOnOptionSave.php | 25 ++++---- .../Plugin/ReindexReviewFeed.php | 36 +++--------- .../Plugin/ReindexReviewFeedOnVoteAdd.php | 22 +++---- 8 files changed, 108 insertions(+), 108 deletions(-) create mode 100644 app/code/Magento/ProductReviewDataExporter/Model/Indexer/ReindexOnSaveAction.php diff --git a/app/code/Magento/CatalogExport/Event/Data/Entity.php b/app/code/Magento/CatalogExport/Event/Data/Entity.php index 0d27bd082..6a82a09b8 100644 --- a/app/code/Magento/CatalogExport/Event/Data/Entity.php +++ b/app/code/Magento/CatalogExport/Event/Data/Entity.php @@ -14,7 +14,7 @@ class Entity { /** - * @var int + * @var string */ private $entityId; @@ -26,9 +26,9 @@ class Entity /** * Get entity id. * - * @return int + * @return string */ - public function getEntityId(): int + public function getEntityId(): string { return $this->entityId; } @@ -36,11 +36,11 @@ public function getEntityId(): int /** * Set entity id. * - * @param int $entityId + * @param string $entityId * * @return void */ - public function setEntityId(int $entityId): void + public function setEntityId(string $entityId): void { $this->entityId = $entityId; } diff --git a/app/code/Magento/CatalogExport/Model/ChangedEntitiesMessageBuilder.php b/app/code/Magento/CatalogExport/Model/ChangedEntitiesMessageBuilder.php index fa0e8a39e..95d13e453 100644 --- a/app/code/Magento/CatalogExport/Model/ChangedEntitiesMessageBuilder.php +++ b/app/code/Magento/CatalogExport/Model/ChangedEntitiesMessageBuilder.php @@ -65,7 +65,7 @@ public function __construct( * * @return \Magento\CatalogExport\Event\Data\ChangedEntities */ - public function build(string $eventType, array $entities, string $scope = null): ChangedEntities + public function build(string $eventType, array $entities, ?string $scope): ChangedEntities { $meta = $this->metaFactory->create(); $meta->setScope($scope); @@ -74,7 +74,7 @@ public function build(string $eventType, array $entities, string $scope = null): $entitiesArray = []; foreach ($entities as $entityData) { $entity = $this->entityFactory->create(); - $entity->setEntityId((int)$entityData['entity_id']); + $entity->setEntityId((string)$entityData['entity_id']); $entity->setAttributes($entityData['attributes'] ?? []); $entitiesArray[] = $entity; diff --git a/app/code/Magento/ProductReviewDataExporter/Model/Indexer/ReindexOnSaveAction.php b/app/code/Magento/ProductReviewDataExporter/Model/Indexer/ReindexOnSaveAction.php new file mode 100644 index 000000000..c2e867c98 --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/Model/Indexer/ReindexOnSaveAction.php @@ -0,0 +1,58 @@ +indexerRegistry = $indexerRegistry; + } + + /** + * Execute re-indexation action + * + * @param string $feedIndexer + * @param int[] $ids + * + * @return void + */ + public function execute(string $feedIndexer, array $ids): void + { + $indexer = $this->indexerRegistry->get($feedIndexer); + + if (!$indexer->isScheduled()) { + $indexer->reindexList($ids); + } + } +} diff --git a/app/code/Magento/ProductReviewDataExporter/Plugin/MarkRemovedReviewsOnProductDelete.php b/app/code/Magento/ProductReviewDataExporter/Plugin/MarkRemovedReviewsOnProductDelete.php index 8a2eefb52..076f0a678 100644 --- a/app/code/Magento/ProductReviewDataExporter/Plugin/MarkRemovedReviewsOnProductDelete.php +++ b/app/code/Magento/ProductReviewDataExporter/Plugin/MarkRemovedReviewsOnProductDelete.php @@ -10,7 +10,7 @@ use Magento\DataExporter\Model\Indexer\FeedIndexMetadata; use Magento\Framework\App\ResourceConnection; -use Magento\Framework\Indexer\IndexerRegistry; +use Magento\ProductReviewDataExporter\Model\Indexer\ReindexOnSaveAction; use Magento\Review\Model\ResourceModel\Review as ReviewResource; /** @@ -19,14 +19,9 @@ class MarkRemovedReviewsOnProductDelete { /** - * Review feed indexer id + * @var ReindexOnSaveAction */ - private const REVIEW_FEED_INDEXER = 'catalog_data_exporter_product_reviews'; - - /** - * @var IndexerRegistry - */ - private $indexerRegistry; + private $reindexOnSaveAction; /** * @var FeedIndexMetadata @@ -39,16 +34,16 @@ class MarkRemovedReviewsOnProductDelete private $resourceConnection; /** - * @param IndexerRegistry $indexerRegistry + * @param ReindexOnSaveAction $reindexOnSaveAction * @param FeedIndexMetadata $feedIndexMetadata * @param ResourceConnection $resourceConnection */ public function __construct( - IndexerRegistry $indexerRegistry, + ReindexOnSaveAction $reindexOnSaveAction, FeedIndexMetadata $feedIndexMetadata, ResourceConnection $resourceConnection ) { - $this->indexerRegistry = $indexerRegistry; + $this->reindexOnSaveAction = $reindexOnSaveAction; $this->feedIndexMetadata = $feedIndexMetadata; $this->resourceConnection = $resourceConnection; } @@ -69,10 +64,10 @@ public function afterDeleteReviewsByProductId( ReviewResource $result, int $productId ): ReviewResource { - $indexer = $this->indexerRegistry->get(self::REVIEW_FEED_INDEXER); - if (!$indexer->isScheduled()) { - $indexer->reindexList($this->fetchReviewIdsByProductId($productId)); - } + $this->reindexOnSaveAction->execute( + ReindexOnSaveAction::REVIEW_FEED_INDEXER, + $this->fetchReviewIdsByProductId($productId) + ); return $result; } diff --git a/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeed.php b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeed.php index 2ba3318ed..e7d1851ef 100644 --- a/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeed.php +++ b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeed.php @@ -8,7 +8,7 @@ namespace Magento\ProductReviewDataExporter\Plugin; -use Magento\Framework\Indexer\IndexerRegistry; +use Magento\ProductReviewDataExporter\Model\Indexer\ReindexOnSaveAction; use Magento\Review\Model\Rating; /** @@ -17,22 +17,17 @@ class ReindexRatingMetadataFeed { /** - * Rating metadata feed indexer id + * @var ReindexOnSaveAction */ - private const RATING_METADATA_FEED_INDEXER = 'catalog_data_exporter_rating_metadata'; + private $reindexOnSaveAction; /** - * @var IndexerRegistry - */ - private $indexerRegistry; - - /** - * @param IndexerRegistry $indexerRegistry + * @param ReindexOnSaveAction $reindexOnSaveAction */ public function __construct( - IndexerRegistry $indexerRegistry + ReindexOnSaveAction $reindexOnSaveAction ) { - $this->indexerRegistry = $indexerRegistry; + $this->reindexOnSaveAction = $reindexOnSaveAction; } /** @@ -44,7 +39,7 @@ public function __construct( */ public function beforeAfterDeleteCommit(Rating $subject): Rating { - $this->reindex($subject); + $this->reindexOnSaveAction->execute(ReindexOnSaveAction::RATING_METADATA_FEED_INDEXER, [$subject->getId()]); return $subject; } @@ -58,23 +53,8 @@ public function beforeAfterDeleteCommit(Rating $subject): Rating */ public function beforeAfterCommitCallback(Rating $subject): Rating { - $this->reindex($subject); + $this->reindexOnSaveAction->execute(ReindexOnSaveAction::RATING_METADATA_FEED_INDEXER, [$subject->getId()]); return $subject; } - - /** - * Re-indexation process of rating metadata feed - * - * @param Rating $rating - * - * @return void - */ - public function reindex(Rating $rating): void - { - $indexer = $this->indexerRegistry->get(self::RATING_METADATA_FEED_INDEXER); - if (!$indexer->isScheduled()) { - $indexer->reindexRow($rating->getId()); - } - } } diff --git a/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeedOnOptionSave.php b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeedOnOptionSave.php index f7a82bcaf..129b51320 100644 --- a/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeedOnOptionSave.php +++ b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexRatingMetadataFeedOnOptionSave.php @@ -8,7 +8,7 @@ namespace Magento\ProductReviewDataExporter\Plugin; -use Magento\Framework\Indexer\IndexerRegistry; +use Magento\ProductReviewDataExporter\Model\Indexer\ReindexOnSaveAction; use Magento\Review\Model\Rating\Option; /** @@ -17,22 +17,17 @@ class ReindexRatingMetadataFeedOnOptionSave { /** - * Rating metadata feed indexer id + * @var ReindexOnSaveAction */ - private const RATING_METADATA_FEED_INDEXER = 'catalog_data_exporter_rating_metadata'; + private $reindexOnSaveAction; /** - * @var IndexerRegistry - */ - private $indexerRegistry; - - /** - * @param IndexerRegistry $indexerRegistry + * @param ReindexOnSaveAction $reindexOnSaveAction */ public function __construct( - IndexerRegistry $indexerRegistry + ReindexOnSaveAction $reindexOnSaveAction ) { - $this->indexerRegistry = $indexerRegistry; + $this->reindexOnSaveAction = $reindexOnSaveAction; } /** @@ -44,10 +39,10 @@ public function __construct( */ public function beforeAfterCommitCallback(Option $subject): Option { - $indexer = $this->indexerRegistry->get(self::RATING_METADATA_FEED_INDEXER); - if (!$indexer->isScheduled()) { - $indexer->reindexRow($subject->getRatingId()); - } + $this->reindexOnSaveAction->execute( + ReindexOnSaveAction::RATING_METADATA_FEED_INDEXER, + [$subject->getRatingId()] + ); return $subject; } diff --git a/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeed.php b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeed.php index 30b147617..34c483589 100644 --- a/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeed.php +++ b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeed.php @@ -8,7 +8,7 @@ namespace Magento\ProductReviewDataExporter\Plugin; -use Magento\Framework\Indexer\IndexerRegistry; +use Magento\ProductReviewDataExporter\Model\Indexer\ReindexOnSaveAction; use Magento\Review\Model\Review; /** @@ -17,22 +17,17 @@ class ReindexReviewFeed { /** - * Review feed indexer id + * @var ReindexOnSaveAction */ - private const REVIEW_FEED_INDEXER = 'catalog_data_exporter_product_reviews'; + private $reindexOnSaveAction; /** - * @var IndexerRegistry - */ - private $indexerRegistry; - - /** - * @param IndexerRegistry $indexerRegistry + * @param ReindexOnSaveAction $reindexOnSaveAction */ public function __construct( - IndexerRegistry $indexerRegistry + ReindexOnSaveAction $reindexOnSaveAction ) { - $this->indexerRegistry = $indexerRegistry; + $this->reindexOnSaveAction = $reindexOnSaveAction; } /** @@ -44,7 +39,7 @@ public function __construct( */ public function beforeAfterDeleteCommit(Review $subject): Review { - $this->reindex($subject); + $this->reindexOnSaveAction->execute(ReindexOnSaveAction::REVIEW_FEED_INDEXER, [$subject->getId()]); return $subject; } @@ -58,23 +53,8 @@ public function beforeAfterDeleteCommit(Review $subject): Review */ public function beforeAfterCommitCallback(Review $subject): Review { - $this->reindex($subject); + $this->reindexOnSaveAction->execute(ReindexOnSaveAction::REVIEW_FEED_INDEXER, [$subject->getId()]); return $subject; } - - /** - * Re-indexation process of review feed - * - * @param Review $review - * - * @return void - */ - public function reindex(Review $review): void - { - $indexer = $this->indexerRegistry->get(self::REVIEW_FEED_INDEXER); - if (!$indexer->isScheduled()) { - $indexer->reindexRow($review->getId()); - } - } } diff --git a/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeedOnVoteAdd.php b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeedOnVoteAdd.php index 2337953f2..6d44f6d7e 100644 --- a/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeedOnVoteAdd.php +++ b/app/code/Magento/ProductReviewDataExporter/Plugin/ReindexReviewFeedOnVoteAdd.php @@ -8,7 +8,7 @@ namespace Magento\ProductReviewDataExporter\Plugin; -use Magento\Framework\Indexer\IndexerRegistry; +use Magento\ProductReviewDataExporter\Model\Indexer\ReindexOnSaveAction; use Magento\Review\Model\Rating\Option; use Magento\Review\Model\ResourceModel\Rating\Option as RatingOptionResource; @@ -18,22 +18,17 @@ class ReindexReviewFeedOnVoteAdd { /** - * Review feed indexer id + * @var ReindexOnSaveAction */ - private const REVIEW_FEED_INDEXER = 'catalog_data_exporter_product_reviews'; + private $reindexOnSaveAction; /** - * @var IndexerRegistry - */ - private $indexerRegistry; - - /** - * @param IndexerRegistry $indexerRegistry + * @param ReindexOnSaveAction $reindexOnSaveAction */ public function __construct( - IndexerRegistry $indexerRegistry + ReindexOnSaveAction $reindexOnSaveAction ) { - $this->indexerRegistry = $indexerRegistry; + $this->reindexOnSaveAction = $reindexOnSaveAction; } /** @@ -52,10 +47,7 @@ public function afterAddVote( RatingOptionResource $result, Option $option ): RatingOptionResource { - $indexer = $this->indexerRegistry->get(self::REVIEW_FEED_INDEXER); - if (!$indexer->isScheduled()) { - $indexer->reindexRow($option->getReviewId()); - } + $this->reindexOnSaveAction->execute(ReindexOnSaveAction::REVIEW_FEED_INDEXER, [$option->getReviewId()]); return $result; } From 8a2ea40701561f6d976a2cfd2f7bc5a238686786 Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Thu, 12 Nov 2020 00:14:23 +0200 Subject: [PATCH 16/24] Support for ratings & reviews in Storefront App - Mark inactive entities --- .../Model/Indexer/MarkRemovedEntities.php | 45 ++++------- .../Model/Query/MarkRemovedEntitiesQuery.php | 75 +++++++++++++++++++ .../Plugin/MarkRemovedEntitiesQueryPlugin.php | 74 ++++++++++++++++++ .../ProductReviewDataExporter/etc/di.xml | 4 + 4 files changed, 167 insertions(+), 31 deletions(-) create mode 100644 app/code/Magento/DataExporter/Model/Query/MarkRemovedEntitiesQuery.php create mode 100644 app/code/Magento/ProductReviewDataExporter/Plugin/MarkRemovedEntitiesQueryPlugin.php diff --git a/app/code/Magento/DataExporter/Model/Indexer/MarkRemovedEntities.php b/app/code/Magento/DataExporter/Model/Indexer/MarkRemovedEntities.php index 78a4c42fc..6f7e26e34 100644 --- a/app/code/Magento/DataExporter/Model/Indexer/MarkRemovedEntities.php +++ b/app/code/Magento/DataExporter/Model/Indexer/MarkRemovedEntities.php @@ -7,6 +7,7 @@ namespace Magento\DataExporter\Model\Indexer; +use Magento\DataExporter\Model\Query\MarkRemovedEntitiesQuery; use Magento\Framework\App\ResourceConnection; /** @@ -19,12 +20,21 @@ class MarkRemovedEntities implements MarkRemovedEntitiesInterface */ private $resourceConnection; + /** + * @var MarkRemovedEntitiesQuery + */ + private $markRemovedEntitiesQuery; + /** * @param ResourceConnection $resourceConnection + * @param MarkRemovedEntitiesQuery $markRemovedEntitiesQuery */ - public function __construct(ResourceConnection $resourceConnection) - { + public function __construct( + ResourceConnection $resourceConnection, + MarkRemovedEntitiesQuery $markRemovedEntitiesQuery + ) { $this->resourceConnection = $resourceConnection; + $this->markRemovedEntitiesQuery = $markRemovedEntitiesQuery; } /** @@ -32,41 +42,14 @@ public function __construct(ResourceConnection $resourceConnection) */ public function execute(array $ids, FeedIndexMetadata $metadata): void { + $select = $this->markRemovedEntitiesQuery->getQuery($ids, $metadata); $connection = $this->resourceConnection->getConnection(); - $select = $connection->select() - ->joinLeft( - ['s' => $this->resourceConnection->getTableName($metadata->getSourceTableName())], - \sprintf('f.%s = s.%s', $metadata->getFeedTableField(), $metadata->getSourceTableField()), - ['is_deleted' => new \Zend_Db_Expr('1')] - ) - ->where(\sprintf('f.%s IN (?)', $metadata->getFeedTableField()), $ids); - - if ($metadata->getScopeTableName()) { - $select - ->join( - ['st' => $this->resourceConnection->getTableName('store')], - 'f.store_view_code = st.code', - [] - ) - ->joinLeft( - ['sc' => $this->resourceConnection->getTableName($metadata->getScopeTableName())], - \sprintf( - 'sc.%s = s.%s AND sc.%3$s = st.%3$s', - $metadata->getScopeTableField(), - $metadata->getSourceTableField(), - $metadata->getScopeCode(), - ), - [] - ) - ->where(\sprintf('sc.%s IS NULL', $metadata->getScopeTableField())); - } else { - $select->where(\sprintf('s.%s IS NULL', $metadata->getSourceTableField())); - } $update = $connection->updateFromSelect( $select, ['f' => $this->resourceConnection->getTableName($metadata->getFeedTableName())] ); + $connection->query($update); } } diff --git a/app/code/Magento/DataExporter/Model/Query/MarkRemovedEntitiesQuery.php b/app/code/Magento/DataExporter/Model/Query/MarkRemovedEntitiesQuery.php new file mode 100644 index 000000000..28d2d97ac --- /dev/null +++ b/app/code/Magento/DataExporter/Model/Query/MarkRemovedEntitiesQuery.php @@ -0,0 +1,75 @@ +resourceConnection = $resourceConnection; + } + + /** + * Get select query for marking removed entities + * + * @param array $ids + * @param FeedIndexMetadata $metadata + * + * @return Select + */ + public function getQuery(array $ids, FeedIndexMetadata $metadata): Select + { + $connection = $this->resourceConnection->getConnection(); + $select = $connection->select() + ->joinLeft( + ['s' => $this->resourceConnection->getTableName($metadata->getSourceTableName())], + \sprintf('f.%s = s.%s', $metadata->getFeedTableField(), $metadata->getSourceTableField()), + ['is_deleted' => new \Zend_Db_Expr('1')] + ) + ->where(\sprintf('f.%s IN (?)', $metadata->getFeedTableField()), $ids); + + if ($metadata->getScopeTableName()) { + $select + ->join( + ['st' => $this->resourceConnection->getTableName('store')], + 'f.store_view_code = st.code', + [] + ) + ->joinLeft( + ['sc' => $this->resourceConnection->getTableName($metadata->getScopeTableName())], + \sprintf( + 'sc.%s = s.%s AND sc.%3$s = st.%3$s', + $metadata->getScopeTableField(), + $metadata->getSourceTableField(), + $metadata->getScopeCode(), + ), + [] + ) + ->where(\sprintf('sc.%s IS NULL', $metadata->getScopeTableField())); + } else { + $select->where(\sprintf('s.%s IS NULL', $metadata->getSourceTableField())); + } + + return $select; + } +} \ No newline at end of file diff --git a/app/code/Magento/ProductReviewDataExporter/Plugin/MarkRemovedEntitiesQueryPlugin.php b/app/code/Magento/ProductReviewDataExporter/Plugin/MarkRemovedEntitiesQueryPlugin.php new file mode 100644 index 000000000..b7074425b --- /dev/null +++ b/app/code/Magento/ProductReviewDataExporter/Plugin/MarkRemovedEntitiesQueryPlugin.php @@ -0,0 +1,74 @@ + not approved review, inactive rating) + */ +class MarkRemovedEntitiesQueryPlugin +{ + /** + * Entities feed names + */ + private const FEED_NAME_REVIEWS = 'reviews'; + private const FEED_NAME_RATING_METADATA = 'ratingMetadata'; + + /** + * @var ResourceConnection + */ + private $resourceConnection; + + /** + * @param ResourceConnection $resourceConnection + */ + public function __construct(ResourceConnection $resourceConnection) + { + $this->resourceConnection = $resourceConnection; + } + + /** + * Add inactive entity condition for marking removed entities query + * + * @param MarkRemovedEntitiesQuery $subject + * @param Select $result + * @param array $ids + * @param FeedIndexMetadata $metadata + * + * @return Select + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterGetQuery( + MarkRemovedEntitiesQuery $subject, + Select $result, + array $ids, + FeedIndexMetadata $metadata + ): Select { + $connection = $this->resourceConnection->getConnection(); + $whereCondition = []; + + if ($metadata->getFeedName() === self::FEED_NAME_REVIEWS) { + $whereCondition[] = $connection->quoteInto('s.status_id != ?', Review::STATUS_APPROVED); + } elseif ($metadata->getFeedName() === self::FEED_NAME_RATING_METADATA) { + $whereCondition[] = $connection->quoteInto('s.is_active != ?', 1); + } + + if (!empty($whereCondition)) { + $whereCondition[] = $connection->quoteInto(\sprintf('f.%s IN (?)', $metadata->getFeedTableField()), $ids); + $result->orWhere(\implode(' AND ', $whereCondition)); + } + + return $result; + } +} diff --git a/app/code/Magento/ProductReviewDataExporter/etc/di.xml b/app/code/Magento/ProductReviewDataExporter/etc/di.xml index a115f4236..fe3a7d397 100644 --- a/app/code/Magento/ProductReviewDataExporter/etc/di.xml +++ b/app/code/Magento/ProductReviewDataExporter/etc/di.xml @@ -134,6 +134,10 @@ + + + From 84df965628ca3644d038504119abbb8cd7a04a15 Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Thu, 12 Nov 2020 00:16:23 +0200 Subject: [PATCH 17/24] Support for ratings & reviews in Storefront App - Mark inactive entities --- .../DataExporter/Model/Query/MarkRemovedEntitiesQuery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/DataExporter/Model/Query/MarkRemovedEntitiesQuery.php b/app/code/Magento/DataExporter/Model/Query/MarkRemovedEntitiesQuery.php index 28d2d97ac..90309112e 100644 --- a/app/code/Magento/DataExporter/Model/Query/MarkRemovedEntitiesQuery.php +++ b/app/code/Magento/DataExporter/Model/Query/MarkRemovedEntitiesQuery.php @@ -72,4 +72,4 @@ public function getQuery(array $ids, FeedIndexMetadata $metadata): Select return $select; } -} \ No newline at end of file +} From 97c3213d297d7541140af42fe12de7ac00211974 Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Tue, 17 Nov 2020 21:58:06 +0200 Subject: [PATCH 18/24] Support for ratings & reviews in Storefront App - Compatibility fix with variants --- .../Model/Indexer/ProductVariantFeedIndexMetadata.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/code/Magento/ProductVariantDataExporter/Model/Indexer/ProductVariantFeedIndexMetadata.php b/app/code/Magento/ProductVariantDataExporter/Model/Indexer/ProductVariantFeedIndexMetadata.php index 4eb7113fc..f37ec8662 100644 --- a/app/code/Magento/ProductVariantDataExporter/Model/Indexer/ProductVariantFeedIndexMetadata.php +++ b/app/code/Magento/ProductVariantDataExporter/Model/Indexer/ProductVariantFeedIndexMetadata.php @@ -27,8 +27,13 @@ class ProductVariantFeedIndexMetadata extends FeedIndexMetadata * @param string $feedTableName * @param string $feedTableField * @param array $feedTableMutableColumns + * @param string $scopeTableName + * @param string $scopeTableField + * @param string $scopeCode * @param int $batchSize * @param string|null $feedTableParentField + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( string $feedName, @@ -38,6 +43,9 @@ public function __construct( string $feedTableName, string $feedTableField, array $feedTableMutableColumns, + string $scopeTableName = '', + string $scopeTableField = '', + string $scopeCode = '', int $batchSize = 100, string $feedTableParentField = null ) { @@ -49,6 +57,9 @@ public function __construct( $feedTableName, $feedTableField, $feedTableMutableColumns, + $scopeTableName, + $scopeTableField, + $scopeCode, $batchSize ); $this->feedTableParentField = $feedTableParentField; From a9abe683bae3d3a1ae627fdbc0cf41e173c5e227 Mon Sep 17 00:00:00 2001 From: ruslankostiv Date: Wed, 18 Nov 2020 20:17:17 -0600 Subject: [PATCH 19/24] Web-API tests fix. --- .../CatalogExport/Model/ChangedEntitiesMessageBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogExport/Model/ChangedEntitiesMessageBuilder.php b/app/code/Magento/CatalogExport/Model/ChangedEntitiesMessageBuilder.php index 95d13e453..9afeee8ec 100644 --- a/app/code/Magento/CatalogExport/Model/ChangedEntitiesMessageBuilder.php +++ b/app/code/Magento/CatalogExport/Model/ChangedEntitiesMessageBuilder.php @@ -65,7 +65,7 @@ public function __construct( * * @return \Magento\CatalogExport\Event\Data\ChangedEntities */ - public function build(string $eventType, array $entities, ?string $scope): ChangedEntities + public function build(string $eventType, array $entities, ?string $scope = null): ChangedEntities { $meta = $this->metaFactory->create(); $meta->setScope($scope); From 44633ff2d23572d249eb614f76aff8c9d056e620 Mon Sep 17 00:00:00 2001 From: ruslankostiv Date: Wed, 18 Nov 2020 21:06:04 -0600 Subject: [PATCH 20/24] Web-API tests fix. --- app/code/Magento/ProductVariantDataExporter/etc/di.xml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/code/Magento/ProductVariantDataExporter/etc/di.xml b/app/code/Magento/ProductVariantDataExporter/etc/di.xml index 2371528b9..e251b33d9 100644 --- a/app/code/Magento/ProductVariantDataExporter/etc/di.xml +++ b/app/code/Magento/ProductVariantDataExporter/etc/di.xml @@ -31,17 +31,11 @@ - - - - Magento\ProductVariantDataExporter\Model\Indexer\ProductVariantFeedIndexMetadata Magento\ProductVariantDataExporter\Model\Indexer\ProductVariantDataSerializer - Magento\ProductVariantDataExporter\Model\Indexer\ProductVariantIndexerCallbackInterface + Magento\CatalogExport\Model\Indexer\ProductVariantIndexerCallback From d9451d815ac9fdee8fca7928ff728284a02d68e0 Mon Sep 17 00:00:00 2001 From: ruslankostiv Date: Thu, 19 Nov 2020 13:42:25 -0600 Subject: [PATCH 21/24] Web-API tests fixes. Extra code removed from di.xml/module.xml --- .../Magento/CatalogDataExporter/etc/di.xml | 34 ++++++++---- app/code/Magento/CatalogExport/etc/di.xml | 55 ------------------- app/code/Magento/CatalogExport/etc/module.xml | 8 +-- .../ProductReviewDataExporter/etc/di.xml | 30 ++++++---- .../ProductVariantDataExporter/etc/di.xml | 10 ++++ 5 files changed, 55 insertions(+), 82 deletions(-) diff --git a/app/code/Magento/CatalogDataExporter/etc/di.xml b/app/code/Magento/CatalogDataExporter/etc/di.xml index 845668419..2b9cc8674 100644 --- a/app/code/Magento/CatalogDataExporter/etc/di.xml +++ b/app/code/Magento/CatalogDataExporter/etc/di.xml @@ -270,15 +270,22 @@ - - + + + + Magento\CatalogDataExporter\Model\Indexer\ProductFeedIndexMetadata + catalog.export.product.data + products_updated + products_deleted + + + Magento\CatalogDataExporter\Model\Indexer\ProductFeedIndexMetadata Magento\CatalogDataExporter\Model\Indexer\ProductDataSerializer - Magento\CatalogDataExporter\Model\Indexer\ProductIndexerCallbackInterface + Magento\CatalogExport\Model\Indexer\ProductIndexerCallback storeViewCode storeCode @@ -415,15 +422,22 @@ - - + + + + Magento\CatalogDataExporter\Model\Indexer\CategoryFeedIndexMetadata + catalog.export.category.data + categories_updated + categories_deleted + + + Magento\CatalogDataExporter\Model\Indexer\CategoryFeedIndexMetadata Magento\CatalogDataExporter\Model\Indexer\CategoryDataSerializer - Magento\CatalogDataExporter\Model\Indexer\CategoryIndexerCallbackInterface + Magento\CatalogExport\Model\Indexer\CategoryIndexerCallback storeViewCode categoryId diff --git a/app/code/Magento/CatalogExport/etc/di.xml b/app/code/Magento/CatalogExport/etc/di.xml index 32d1824a9..0d7464eb6 100644 --- a/app/code/Magento/CatalogExport/etc/di.xml +++ b/app/code/Magento/CatalogExport/etc/di.xml @@ -12,42 +12,6 @@ - - - - - - - - - Magento\CatalogDataExporter\Model\Indexer\CategoryFeedIndexMetadata - catalog.export.category.data - categories_updated - categories_deleted - - - - - - Magento\CatalogDataExporter\Model\Indexer\ProductFeedIndexMetadata - catalog.export.product.data - products_updated - products_deleted - - - - - - Magento\ProductVariantDataExporter\Model\Indexer\ProductVariantFeedIndexMetadata - catalog.export.product.variants.data - product_variants_updated - product_variants_deleted - - - @@ -58,23 +22,4 @@ - - - Magento\ProductReviewDataExporter\Model\Indexer\ProductReviewsFeedIndexMetadata - export.product.reviews - reviews_updated - reviews_deleted - - - - - - Magento\ProductReviewDataExporter\Model\Indexer\RatingFeedIndexMetadata - export.rating.metadata - rating_metadata_updated - rating_metadata_deleted - - diff --git a/app/code/Magento/CatalogExport/etc/module.xml b/app/code/Magento/CatalogExport/etc/module.xml index d8aa004c0..60b912580 100644 --- a/app/code/Magento/CatalogExport/etc/module.xml +++ b/app/code/Magento/CatalogExport/etc/module.xml @@ -6,11 +6,5 @@ */ --> - - - - - - - + diff --git a/app/code/Magento/ProductReviewDataExporter/etc/di.xml b/app/code/Magento/ProductReviewDataExporter/etc/di.xml index fe3a7d397..4198e359f 100644 --- a/app/code/Magento/ProductReviewDataExporter/etc/di.xml +++ b/app/code/Magento/ProductReviewDataExporter/etc/di.xml @@ -33,10 +33,15 @@ - - + + + Magento\ProductReviewDataExporter\Model\Indexer\ProductReviewsFeedIndexMetadata + export.product.reviews + reviews_updated + reviews_deleted + + @@ -45,7 +50,7 @@ Magento\ProductReviewDataExporter\Model\Indexer\ProductReviewsFeedIndexMetadata - Magento\ProductReviewDataExporter\Model\Indexer\ReviewsIndexerCallbackInterface + Magento\CatalogExport\Model\Indexer\ReviewIndexerCallback Magento\ProductReviewDataExporter\Model\Indexer\ProductReviewsDataSerializer @@ -91,10 +96,15 @@ - - + + + Magento\ProductReviewDataExporter\Model\Indexer\RatingFeedIndexMetadata + export.rating.metadata + rating_metadata_updated + rating_metadata_deleted + + @@ -103,7 +113,7 @@ Magento\ProductReviewDataExporter\Model\Indexer\RatingFeedIndexMetadata - Magento\ProductReviewDataExporter\Model\Indexer\RatingMetadataIndexerCallbackInterface + Magento\CatalogExport\Model\Indexer\RatingMetadataIndexerCallback Magento\ProductReviewDataExporter\Model\Indexer\RatingDataSerializer diff --git a/app/code/Magento/ProductVariantDataExporter/etc/di.xml b/app/code/Magento/ProductVariantDataExporter/etc/di.xml index e251b33d9..096cbecec 100644 --- a/app/code/Magento/ProductVariantDataExporter/etc/di.xml +++ b/app/code/Magento/ProductVariantDataExporter/etc/di.xml @@ -31,6 +31,16 @@ + + + Magento\ProductVariantDataExporter\Model\Indexer\ProductVariantFeedIndexMetadata + catalog.export.product.variants.data + product_variants_updated + product_variants_deleted + + + Magento\ProductVariantDataExporter\Model\Indexer\ProductVariantFeedIndexMetadata From 4f6ddf2e976ac54fbcf0c5cb607fb51c1c88a777 Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Mon, 23 Nov 2020 14:41:18 +0200 Subject: [PATCH 22/24] Support for ratings & reviews in Storefront App - Tests fix --- .../Magento/CatalogDataExporter/composer.json | 3 +- .../Model/RatingMetadataRepository.php | 2 +- .../CatalogExport/Model/ReviewRepository.php | 2 +- .../Api/RatingMetadataRepositoryInterface.php | 2 +- .../Api/ReviewRepositoryInterface.php | 2 +- app/code/Magento/DataExporter/composer.json | 3 +- .../ProductReviewDataExporter/composer.json | 47 ++++++++++--------- .../ProductVariantDataExporter/composer.json | 3 +- 8 files changed, 34 insertions(+), 30 deletions(-) diff --git a/app/code/Magento/CatalogDataExporter/composer.json b/app/code/Magento/CatalogDataExporter/composer.json index 613bf1d0e..d8a113f59 100644 --- a/app/code/Magento/CatalogDataExporter/composer.json +++ b/app/code/Magento/CatalogDataExporter/composer.json @@ -27,6 +27,7 @@ "magento/module-data-exporter": "*", "magento/module-customer": "*", "magento/module-downloadable": "*", - "magento/module-indexer": "*" + "magento/module-indexer": "*", + "magento/module-catalog-export": "*" } } diff --git a/app/code/Magento/CatalogExport/Model/RatingMetadataRepository.php b/app/code/Magento/CatalogExport/Model/RatingMetadataRepository.php index cd9ee254f..a7e1d20e8 100644 --- a/app/code/Magento/CatalogExport/Model/RatingMetadataRepository.php +++ b/app/code/Magento/CatalogExport/Model/RatingMetadataRepository.php @@ -61,7 +61,7 @@ public function __construct( /** * @inheritdoc */ - public function get(EntityRequest $request) + public function get(EntityRequest $request): array { $storeViewCodes = $request->getStoreViewCodes(); $ids = \array_map(function (Item $item) { diff --git a/app/code/Magento/CatalogExport/Model/ReviewRepository.php b/app/code/Magento/CatalogExport/Model/ReviewRepository.php index 668767149..dd2a70149 100644 --- a/app/code/Magento/CatalogExport/Model/ReviewRepository.php +++ b/app/code/Magento/CatalogExport/Model/ReviewRepository.php @@ -61,7 +61,7 @@ public function __construct( /** * @inheritdoc */ - public function get(EntityRequest $request) + public function get(EntityRequest $request): array { $ids = \array_map(function (Item $item) { return $item->getEntityId(); diff --git a/app/code/Magento/CatalogExportApi/Api/RatingMetadataRepositoryInterface.php b/app/code/Magento/CatalogExportApi/Api/RatingMetadataRepositoryInterface.php index b62f8cb1d..b2f6311a1 100644 --- a/app/code/Magento/CatalogExportApi/Api/RatingMetadataRepositoryInterface.php +++ b/app/code/Magento/CatalogExportApi/Api/RatingMetadataRepositoryInterface.php @@ -20,5 +20,5 @@ interface RatingMetadataRepositoryInterface * * @throws \InvalidArgumentException */ - public function get(EntityRequest $request); + public function get(EntityRequest $request): array; } diff --git a/app/code/Magento/CatalogExportApi/Api/ReviewRepositoryInterface.php b/app/code/Magento/CatalogExportApi/Api/ReviewRepositoryInterface.php index e8a0b1290..9097f3be7 100644 --- a/app/code/Magento/CatalogExportApi/Api/ReviewRepositoryInterface.php +++ b/app/code/Magento/CatalogExportApi/Api/ReviewRepositoryInterface.php @@ -20,5 +20,5 @@ interface ReviewRepositoryInterface * * @throws \InvalidArgumentException */ - public function get(EntityRequest $request); + public function get(EntityRequest $request): array; } diff --git a/app/code/Magento/DataExporter/composer.json b/app/code/Magento/DataExporter/composer.json index c550fe606..5806de524 100644 --- a/app/code/Magento/DataExporter/composer.json +++ b/app/code/Magento/DataExporter/composer.json @@ -19,6 +19,7 @@ }, "require": { "php": "~7.2.0||~7.3.0||~7.4.0", - "magento/framework": "*" + "magento/framework": "*", + "magento/module-store": "*" } } diff --git a/app/code/Magento/ProductReviewDataExporter/composer.json b/app/code/Magento/ProductReviewDataExporter/composer.json index f10d11c08..c525203a6 100644 --- a/app/code/Magento/ProductReviewDataExporter/composer.json +++ b/app/code/Magento/ProductReviewDataExporter/composer.json @@ -1,27 +1,28 @@ { - "name": "magento/module-product-review-data-exporter", - "description": "Product review data exporter", - "config": { - "sort-packages": true - }, - "type": "magento2-module", - "license": [ - "OSL-3.0", - "AFL-3.0" + "name": "magento/module-product-review-data-exporter", + "description": "Product review data exporter", + "config": { + "sort-packages": true + }, + "type": "magento2-module", + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "autoload": { + "files": [ + "registration.php" ], - "autoload": { - "files": [ - "registration.php" - ], - "psr-4": { - "Magento\\ProductReviewDataExporter\\": "" - } - }, - "require": { - "php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0", - "magento/framework": "*", - "magento/module-data-exporter": "*", - "magento/module-review": "*", - "magento/module-store": "*" + "psr-4": { + "Magento\\ProductReviewDataExporter\\": "" } + }, + "require": { + "php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0", + "magento/framework": "*", + "magento/module-data-exporter": "*", + "magento/module-review": "*", + "magento/module-store": "*", + "magento/module-catalog-export": "*" + } } diff --git a/app/code/Magento/ProductVariantDataExporter/composer.json b/app/code/Magento/ProductVariantDataExporter/composer.json index db5517b00..237c874b8 100644 --- a/app/code/Magento/ProductVariantDataExporter/composer.json +++ b/app/code/Magento/ProductVariantDataExporter/composer.json @@ -22,6 +22,7 @@ "guzzlehttp/guzzle": "*", "guzzlehttp/psr7": "~1.0", "magento/framework": "*", - "magento/module-data-exporter": "*" + "magento/module-data-exporter": "*", + "magento/module-catalog-export": "*" } } From e024a01f6836df6c6dc185ac0ceb2d082a27856f Mon Sep 17 00:00:00 2001 From: Aleksejs Baranovs Date: Mon, 23 Nov 2020 17:32:01 +0200 Subject: [PATCH 23/24] Support for ratings & reviews in Storefront App - Tests fix --- app/code/Magento/CatalogExport/composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/CatalogExport/composer.json b/app/code/Magento/CatalogExport/composer.json index 790c6930a..5ec84f5f8 100644 --- a/app/code/Magento/CatalogExport/composer.json +++ b/app/code/Magento/CatalogExport/composer.json @@ -9,7 +9,6 @@ "magento/framework": "*", "magento/framework-message-queue": "*", "magento/module-catalog-export-api": "*", - "magento/module-product-variant-data-exporter": "*", "magento/module-data-exporter": "*" }, "type": "magento2-module", From 7dd9129b7dc96258c8b1f1a4476a5c17b54cf425 Mon Sep 17 00:00:00 2001 From: ruslankostiv Date: Wed, 9 Dec 2020 21:53:00 -0600 Subject: [PATCH 24/24] Rating and reviews. --- app/code/Magento/CatalogExport/etc/di.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/CatalogExport/etc/di.xml b/app/code/Magento/CatalogExport/etc/di.xml index 801382403..8ad1b158a 100644 --- a/app/code/Magento/CatalogExport/etc/di.xml +++ b/app/code/Magento/CatalogExport/etc/di.xml @@ -18,6 +18,8 @@ Product Category ProductVariant + Review + RatingMetadata