From d0cdd2b629b28dc952958e9d758127f939c6a857 Mon Sep 17 00:00:00 2001 From: Damien Couchez Date: Wed, 29 May 2024 14:40:50 +0200 Subject: [PATCH 01/10] fix(adminhtml): fetch current category in category edit page --- Block/Adminhtml/Category/Merchandising.php | 18 +++++---- Service/GetCurrentCategoryService.php | 47 ++++++++++++++++++++++ etc/adminhtml/events.xml | 3 -- 3 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 Service/GetCurrentCategoryService.php diff --git a/Block/Adminhtml/Category/Merchandising.php b/Block/Adminhtml/Category/Merchandising.php index 89357498e..2675d409f 100644 --- a/Block/Adminhtml/Category/Merchandising.php +++ b/Block/Adminhtml/Category/Merchandising.php @@ -6,15 +6,15 @@ use Algolia\AlgoliaSearch\Helper\Data; use Magento\Backend\Block\Template\Context; use Magento\Catalog\Model\Category; -use Algolia\AlgoliaSearch\Registry\CurrentCategory; +use Algolia\AlgoliaSearch\Service\GetCurrentCategoryService; class Merchandising extends \Magento\Backend\Block\Template { /** @var string */ protected $_template = 'catalog/category/edit/merchandising.phtml'; - /** @var CurrentCategory */ - protected $currentCategory; + /** @var GetCurrentCategoryService */ + protected $getCurrentCategoryService; /** @var ConfigHelper */ private $configHelper; @@ -27,19 +27,19 @@ class Merchandising extends \Magento\Backend\Block\Template /** * @param Context $context - * @param CurrentCategory $currentCategory + * @param GetCurrentCategoryService $getCurrentCategoryService * @param ConfigHelper $configHelper * @param Data $coreHelper * @param array $data */ public function __construct( Context $context, - CurrentCategory $currentCategory, + GetCurrentCategoryService $getCurrentCategoryService, ConfigHelper $configHelper, Data $coreHelper, array $data = [] ) { - $this->currentCategory = $currentCategory; + $this->getCurrentCategoryService = $getCurrentCategoryService; $this->configHelper = $configHelper; $this->coreHelper = $coreHelper; $this->storeManager = $context->getStoreManager(); @@ -50,7 +50,11 @@ public function __construct( /** @return Category | null */ public function getCategory() { - return $this->currentCategory->get(); + $categoryId = $this->getRequest()->getParam('id'); + if (!$categoryId) { + return null; + } + return $this->getCurrentCategoryService->getCategory($categoryId); } /** @return bool */ diff --git a/Service/GetCurrentCategoryService.php b/Service/GetCurrentCategoryService.php new file mode 100644 index 000000000..90f2ba0ff --- /dev/null +++ b/Service/GetCurrentCategoryService.php @@ -0,0 +1,47 @@ +categoryRepository = $categoryRepository; + } + + /** + * @param int $categoryId + * @return CategoryInterface|null + */ + public function getCategory(int $categoryId): ?CategoryInterface + { + if (!$this->currentCategory) { + try { + $this->currentCategory = $this->categoryRepository->get($categoryId); + } catch (NoSuchEntityException $e) { + return null; + } + } + return $this->currentCategory; + } +} diff --git a/etc/adminhtml/events.xml b/etc/adminhtml/events.xml index 273feaedf..cdb5f09df 100755 --- a/etc/adminhtml/events.xml +++ b/etc/adminhtml/events.xml @@ -65,7 +65,4 @@ - - - From df95cfedf1e553cf24f7a56ecf268fdd3579d2ae Mon Sep 17 00:00:00 2001 From: Damien Couchez Date: Wed, 29 May 2024 15:17:05 +0200 Subject: [PATCH 02/10] testing --- Helper/Entity/Product/PriceManager/ProductWithoutChildren.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php b/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php index fd4379f5a..b05c178e3 100755 --- a/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php +++ b/Helper/Entity/Product/PriceManager/ProductWithoutChildren.php @@ -380,7 +380,7 @@ protected function addTierPrices($tierPrice, $field, $currencyCode) $this->formatPrice($tierPrice[0], $currencyCode); } } - # TODO bookmarking getRulePrice function for a future refactor effort. + // TODO bookmarking getRulePrice function for a future refactor effort. /** * @param $groupId * @param $product From 4b32ad4a9dce1134d9a8eca5434959f7160ab81d Mon Sep 17 00:00:00 2001 From: Damien Couchez Date: Thu, 30 May 2024 11:25:09 +0200 Subject: [PATCH 03/10] switch from service to plugin --- Block/Adminhtml/Category/Merchandising.php | 18 +++----- Plugin/SetAdminCurrentCategory.php | 54 ++++++++++++++++++++++ Service/GetCurrentCategoryService.php | 47 ------------------- etc/adminhtml/di.xml | 3 ++ 4 files changed, 64 insertions(+), 58 deletions(-) create mode 100644 Plugin/SetAdminCurrentCategory.php delete mode 100644 Service/GetCurrentCategoryService.php diff --git a/Block/Adminhtml/Category/Merchandising.php b/Block/Adminhtml/Category/Merchandising.php index 2675d409f..89357498e 100644 --- a/Block/Adminhtml/Category/Merchandising.php +++ b/Block/Adminhtml/Category/Merchandising.php @@ -6,15 +6,15 @@ use Algolia\AlgoliaSearch\Helper\Data; use Magento\Backend\Block\Template\Context; use Magento\Catalog\Model\Category; -use Algolia\AlgoliaSearch\Service\GetCurrentCategoryService; +use Algolia\AlgoliaSearch\Registry\CurrentCategory; class Merchandising extends \Magento\Backend\Block\Template { /** @var string */ protected $_template = 'catalog/category/edit/merchandising.phtml'; - /** @var GetCurrentCategoryService */ - protected $getCurrentCategoryService; + /** @var CurrentCategory */ + protected $currentCategory; /** @var ConfigHelper */ private $configHelper; @@ -27,19 +27,19 @@ class Merchandising extends \Magento\Backend\Block\Template /** * @param Context $context - * @param GetCurrentCategoryService $getCurrentCategoryService + * @param CurrentCategory $currentCategory * @param ConfigHelper $configHelper * @param Data $coreHelper * @param array $data */ public function __construct( Context $context, - GetCurrentCategoryService $getCurrentCategoryService, + CurrentCategory $currentCategory, ConfigHelper $configHelper, Data $coreHelper, array $data = [] ) { - $this->getCurrentCategoryService = $getCurrentCategoryService; + $this->currentCategory = $currentCategory; $this->configHelper = $configHelper; $this->coreHelper = $coreHelper; $this->storeManager = $context->getStoreManager(); @@ -50,11 +50,7 @@ public function __construct( /** @return Category | null */ public function getCategory() { - $categoryId = $this->getRequest()->getParam('id'); - if (!$categoryId) { - return null; - } - return $this->getCurrentCategoryService->getCategory($categoryId); + return $this->currentCategory->get(); } /** @return bool */ diff --git a/Plugin/SetAdminCurrentCategory.php b/Plugin/SetAdminCurrentCategory.php new file mode 100644 index 000000000..53a2374c1 --- /dev/null +++ b/Plugin/SetAdminCurrentCategory.php @@ -0,0 +1,54 @@ +currentCategory = $currentCategory; + $this->categoryRepository = $categoryRepository; + } + + /** + * Set the current category in adminhtml area in the Algolia registry without using Magento registry + * (which is deprecated) + * + * @param EditController $subject + * @param Page $result + * + * @return Page + */ + public function afterExecute(EditController $subject, $result) + { + $categoryId = $subject->getRequest()->getParam('id'); + try { + $currentCategory = $this->categoryRepository->get($categoryId); + $this->currentCategory->set($currentCategory); + } catch (NoSuchEntityException $e) { + return null; + } + + return $result; + } +} diff --git a/Service/GetCurrentCategoryService.php b/Service/GetCurrentCategoryService.php deleted file mode 100644 index 90f2ba0ff..000000000 --- a/Service/GetCurrentCategoryService.php +++ /dev/null @@ -1,47 +0,0 @@ -categoryRepository = $categoryRepository; - } - - /** - * @param int $categoryId - * @return CategoryInterface|null - */ - public function getCategory(int $categoryId): ?CategoryInterface - { - if (!$this->currentCategory) { - try { - $this->currentCategory = $this->categoryRepository->get($categoryId); - } catch (NoSuchEntityException $e) { - return null; - } - } - return $this->currentCategory; - } -} diff --git a/etc/adminhtml/di.xml b/etc/adminhtml/di.xml index cabd4ec50..60e6a16a8 100755 --- a/etc/adminhtml/di.xml +++ b/etc/adminhtml/di.xml @@ -5,6 +5,9 @@ + + + Magento\Framework\Url From f21740a99dc354f5b9c237b8155548c7515e983f Mon Sep 17 00:00:00 2001 From: Eric Wright Date: Fri, 31 May 2024 17:13:52 -0400 Subject: [PATCH 04/10] MAGE-932: Refactor client side encoding for front end XSS protection on IS search box --- view/frontend/web/instantsearch.js | 11 ++++--- view/frontend/web/internals/common.js | 41 +++++++++++++++------------ 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/view/frontend/web/instantsearch.js b/view/frontend/web/instantsearch.js index e8430286d..5d357bc52 100644 --- a/view/frontend/web/instantsearch.js +++ b/view/frontend/web/instantsearch.js @@ -352,11 +352,14 @@ define( container: instant_selector, placeholder: algoliaConfig.translations.searchFor, showSubmit: false, - queryHook: function (inputValue, search) { - if (algoliaConfig.isSearchPage && algoliaConfig.request.categoryId.length <= 0 && algoliaConfig.request.landingPageId.length <= 0) { - $(".page-title-wrapper span.base").html(algoliaConfig.translations.searchTitle + ": '" + algolia.htmlspecialcharsDecode(inputValue) + "'"); + queryHook: (inputValue, search) => { + const encodedHtml = algolia.htmlspecialcharsEncode(inputValue); + if (algoliaConfig.isSearchPage + && !algoliaConfig.request.categoryId + && !algoliaConfig.request.landingPageId.length) { + $(".page-title-wrapper span.base").html(algoliaConfig.translations.searchTitle + ": '" + encodedHtml + "'"); } - return search(inputValue); + return search(inputValue); } } } diff --git a/view/frontend/web/internals/common.js b/view/frontend/web/internals/common.js index da5138844..2e130bc8b 100755 --- a/view/frontend/web/internals/common.js +++ b/view/frontend/web/internals/common.js @@ -1,6 +1,20 @@ define(['jquery', 'algoliaBundle'], function ($, algoliaBundle) { + // Character maps supplied for more performant Regex ops + const SPECIAL_CHAR_ENCODE_MAP = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''' + }; + + /// Reverse key / value pair + const SPECIAL_CHAR_DECODE_MAP = Object.entries(SPECIAL_CHAR_ENCODE_MAP).reduce((acc, [key, value]) => { + acc[value] = key; + return acc; + }, {}); - window.algolia = { + window.algolia = { deprecatedHooks: [ 'beforeAutocompleteProductSourceOptions', 'beforeAutocompleteSources' @@ -64,23 +78,14 @@ define(['jquery', 'algoliaBundle'], function ($, algoliaBundle) { return data; }, - htmlspecialcharsDecode: function(string) { - var unescapedString = string, - specialchars = [ - [ '"', '"' ], - [ '>', '>' ], - [ '<', '<' ], - [ '&', '&' ], - [ "'", ''' ] - ]; - - var len = specialchars.length; - for (var i=0; i { + const regex = new RegExp(Object.keys(SPECIAL_CHAR_DECODE_MAP).join('|'), 'g'); + return string.replace(regex, m => SPECIAL_CHAR_DECODE_MAP[m]); + }, + htmlspecialcharsEncode: string => { + const regex = new RegExp(`[${Object.keys(SPECIAL_CHAR_ENCODE_MAP).join('')}]`, 'g'); + return string.replace(regex, (m) => SPECIAL_CHAR_ENCODE_MAP[m]); + } }; window.isMobile = function () { From 27a936e07aff3af76879c6cbd91331780eabbb90 Mon Sep 17 00:00:00 2001 From: Eric Wright Date: Mon, 10 Jun 2024 09:46:23 -0400 Subject: [PATCH 05/10] Fix language in admin --- etc/adminhtml/system.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index a1ecb8e71..3f5db5e42 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -1163,7 +1163,7 @@ partialUpdateObjects instead of addObjects?
- You should enable this option if you want to update only some attributes of your records from an external source without avoiding overriding Magento data. + You should enable this option if you want to update only some attributes of your records from an external source without overriding Magento data. ]]>
From c7f9510f0bb754d414ff239f66d0f5168be7721e Mon Sep 17 00:00:00 2001 From: Damien Couchez Date: Wed, 12 Jun 2024 16:23:46 +0200 Subject: [PATCH 06/10] MAGE-870 Integration tests (#1528) * try to re-add integration tests to circleci * update tests config * update tests config * update tests config * test with another image * test with another image * test with another image * revert changes on circleci * improve QueueTests * MAGE-870: remove comments --- Setup/Patch/Schema/ConfigPatch.php | 4 +- .../{Magento_2_3.php => Magento23.php} | 2 +- .../{Magento244.php => Magento24.php} | 10 +-- .../Integration/AssertValues/Magento_2_01.php | 15 ---- Test/Integration/AssertValues/Magento_2_2.php | 15 ---- Test/Integration/PagesIndexingTest.php | 2 +- Test/Integration/QueueTest.php | 84 +++++++++++++------ Test/Integration/TestCase.php | 22 ++--- dev/tests/install-config-mysql.php | 7 ++ 9 files changed, 79 insertions(+), 82 deletions(-) rename Test/Integration/AssertValues/{Magento_2_3.php => Magento23.php} (95%) rename Test/Integration/AssertValues/{Magento244.php => Magento24.php} (60%) delete mode 100644 Test/Integration/AssertValues/Magento_2_01.php delete mode 100644 Test/Integration/AssertValues/Magento_2_2.php diff --git a/Setup/Patch/Schema/ConfigPatch.php b/Setup/Patch/Schema/ConfigPatch.php index 2ffea1d29..a28b9681d 100644 --- a/Setup/Patch/Schema/ConfigPatch.php +++ b/Setup/Patch/Schema/ConfigPatch.php @@ -81,7 +81,7 @@ class ConfigPatch implements SchemaPatchInterface 'algoliasearch_synonyms/synonyms_group/enable_synonyms' => '0', - 'algoliasearch_advanced/advanced/number_of_element_by_page' => '300', + 'algoliasearch_advanced/queue/number_of_element_by_page' => '300', 'algoliasearch_advanced/advanced/remove_words_if_no_result' => 'allOptional', 'algoliasearch_advanced/advanced/partial_update' => '0', 'algoliasearch_advanced/advanced/customer_groups_enable' => '0', @@ -92,7 +92,7 @@ class ConfigPatch implements SchemaPatchInterface 'algoliasearch_advanced/advanced/prevent_backend_rendering' => '0', 'algoliasearch_advanced/advanced/prevent_backend_rendering_display_mode' => 'all', 'algoliasearch_advanced/advanced/backend_rendering_allowed_user_agents' => "Googlebot\nBingbot", - 'algoliasearch_advanced/advanced/archive_clear_limit' => '30', + 'algoliasearch_advanced/queue/archive_clear_limit' => '30', ]; /** diff --git a/Test/Integration/AssertValues/Magento_2_3.php b/Test/Integration/AssertValues/Magento23.php similarity index 95% rename from Test/Integration/AssertValues/Magento_2_3.php rename to Test/Integration/AssertValues/Magento23.php index 133b6316f..1f262575f 100644 --- a/Test/Integration/AssertValues/Magento_2_3.php +++ b/Test/Integration/AssertValues/Magento23.php @@ -2,7 +2,7 @@ namespace Algolia\AlgoliaSearch\Test\Integration\AssertValues; -class Magento_2_3 +class Magento23 { public $productsOnStockCount = 186; public $productsOutOfStockCount = 187; diff --git a/Test/Integration/AssertValues/Magento244.php b/Test/Integration/AssertValues/Magento24.php similarity index 60% rename from Test/Integration/AssertValues/Magento244.php rename to Test/Integration/AssertValues/Magento24.php index d3441314f..264e0d70b 100644 --- a/Test/Integration/AssertValues/Magento244.php +++ b/Test/Integration/AssertValues/Magento24.php @@ -2,14 +2,14 @@ namespace Algolia\AlgoliaSearch\Test\Integration\AssertValues; -class Magento244 +class Magento24 { public $productsOnStockCount = 180; - public $productsOutOfStockCount = 183; + public $productsOutOfStockCount = 181; public $lastJobDataSize = 13; - public $expectedCategory = 17; + public $expectedCategory = 16; public $attributesForFaceting = 5; public $automaticalSetOfCategoryAttributesForFaceting = 4; - public $expectedPages = 9; - public $expectedExcludePages = 7; + public $expectedPages = 6; + public $expectedExcludePages = 4; } diff --git a/Test/Integration/AssertValues/Magento_2_01.php b/Test/Integration/AssertValues/Magento_2_01.php deleted file mode 100644 index d28774027..000000000 --- a/Test/Integration/AssertValues/Magento_2_01.php +++ /dev/null @@ -1,15 +0,0 @@ -setConfig( 'algoliasearch_autocomplete/autocomplete/excluded_pages', diff --git a/Test/Integration/QueueTest.php b/Test/Integration/QueueTest.php index d8da95c8f..abeaf9f5a 100644 --- a/Test/Integration/QueueTest.php +++ b/Test/Integration/QueueTest.php @@ -13,28 +13,35 @@ class QueueTest extends TestCase { + private const INCOMPLETE_REASON = "Must revisit transaction handling across connections."; + /** @var JobsCollectionFactory */ private $jobsCollectionFactory; /** @var AdapterInterface */ private $connection; + /** @var Queue */ + private $queue; + public function setUp(): void { parent::setUp(); $this->jobsCollectionFactory = $this->getObjectManager()->create(JobsCollectionFactory::class); - /** @var ResourceConnection $resouce */ - $resouce = $this->getObjectManager()->create(ResourceConnection::class); - $this->connection = $resouce->getConnection(); + /** @var ResourceConnection $resource */ + $resource = $this->getObjectManager()->create(ResourceConnection::class); + $this->connection = $resource->getConnection(); + + $this->queue = $this->getObjectManager()->create(Queue::class); } public function testFill() { $this->resetConfigs([ 'algoliasearch_queue/queue/number_of_job_to_run', - 'algoliasearch_advanced/advanced/number_of_element_by_page', + 'algoliasearch_advanced/queue/number_of_element_by_page', ]); $this->setConfig('algoliasearch_queue/queue/active', '1'); @@ -72,9 +79,14 @@ public function testFill() } } - /** @depends testFill */ + /** + * @depends testFill + * @magentoDbIsolation disabled + */ public function testExecute() { + $this->markTestIncomplete(self::INCOMPLETE_REASON); + $this->setConfig('algoliasearch_queue/queue/active', '1'); /** @var Queue $queue */ @@ -123,11 +135,14 @@ public function testExecute() $this->assertEquals(0, count($rows)); */ } + /** + * @magentoDbIsolation disabled + */ public function testSettings() { $this->resetConfigs([ 'algoliasearch_queue/queue/number_of_job_to_run', - 'algoliasearch_advanced/advanced/number_of_element_by_page', + 'algoliasearch_advanced/queue/number_of_element_by_page', 'algoliasearch_instant/instant/facets', 'algoliasearch_products/products/product_additional_attributes', ]); @@ -163,11 +178,14 @@ public function testSettings() $this->assertFalse(empty($settings['searchableAttributes']), 'SearchableAttributes should be set, but they are not.'); } + /** + * @magentoDbIsolation disabled + */ public function testMergeSettings() { $this->setConfig('algoliasearch_queue/queue/active', '1'); $this->setConfig('algoliasearch_queue/queue/number_of_job_to_run', 1); - $this->setConfig('algoliasearch_advanced/advanced/number_of_element_by_page', 300); + $this->setConfig('algoliasearch_advanced/queue/number_of_element_by_page', 300); $this->connection->query('DELETE FROM algoliasearch_queue'); @@ -202,6 +220,9 @@ public function testMergeSettings() $this->assertEquals(['sku'], $settings['disableTypoToleranceOnAttributes']); } + /** + * @magentoDbIsolation disabled + */ public function testMerging() { $this->connection->query('DELETE FROM algoliasearch_queue'); @@ -376,6 +397,7 @@ public function testMerging() ], ], 'locked_at' => null, + 'debug' => null, ]; /** @var Job $categoryJob */ @@ -404,6 +426,7 @@ public function testMerging() ], ], 'locked_at' => null, + 'debug' => null, ]; /** @var Job $productJob */ @@ -411,6 +434,9 @@ public function testMerging() $this->assertEquals($expectedProductJob, $productJob->toArray()); } + /** + * @magentoDbIsolation disabled + */ public function testMergingWithStaticMethods() { $this->connection->query('TRUNCATE TABLE algoliasearch_queue'); @@ -539,15 +565,12 @@ public function testMergingWithStaticMethods() ], ]; - /** @var Queue $queue */ - $queue = $this->getObjectManager()->create(Queue::class); - $this->connection->insertMultiple('algoliasearch_queue', $data); /** @var Job[] $jobs */ $jobs = $this->jobsCollectionFactory->create()->getItems(); - $jobs = array_values($this->invokeMethod($queue, 'mergeJobs', [$jobs])); + $jobs = array_values($this->invokeMethod($this->queue, 'mergeJobs', [$jobs])); $this->assertEquals(12, count($jobs)); $this->assertEquals('rebuildStoreCategoryIndex', $jobs[0]->getMethod()); @@ -564,8 +587,13 @@ public function testMergingWithStaticMethods() $this->assertEquals('rebuildStoreProductIndex', $jobs[11]->getMethod()); } + /** + * @magentoDbIsolation disabled + */ public function testGetJobs() { + $this->markTestIncomplete(self::INCOMPLETE_REASON); + $this->connection->query('TRUNCATE TABLE algoliasearch_queue'); $data = [ @@ -706,11 +734,8 @@ public function testGetJobs() $this->connection->insertMultiple('algoliasearch_queue', $data); - /** @var Queue $queue */ - $queue = $this->getObjectManager()->create(Queue::class); - $pid = getmypid(); - $jobs = $this->invokeMethod($queue, 'getJobs', ['maxJobs' => 10]); + $jobs = $this->invokeMethod($this->queue, 'getJobs', ['maxJobs' => 10]); $this->assertEquals(6, count($jobs)); $expectedFirstJob = [ @@ -736,6 +761,7 @@ public function testGetJobs() ], ], 'locked_at' => null, + 'debug' => null, ]; $expectedLastJob = [ @@ -760,6 +786,7 @@ public function testGetJobs() ], ], 'locked_at' => null, + 'debug' => null, ]; /** @var Job $firstJob */ @@ -780,11 +807,14 @@ public function testGetJobs() } } + /** + * @magentoDbIsolation disabled + */ public function testHugeJob() { // Default value - maxBatchSize = 1000 $this->setConfig('algoliasearch_queue/queue/number_of_job_to_run', 10); - $this->setConfig('algoliasearch_advanced/advanced/number_of_element_by_page', 100); + $this->setConfig('algoliasearch_advanced/queue/number_of_element_by_page', 100); $productIds = range(1, 5000); $jsonProductIds = json_encode($productIds); @@ -794,12 +824,9 @@ public function testHugeJob() (1, NULL, \'class\', \'rebuildStoreProductIndex\', \'{"store_id":"1","product_ids":' . $jsonProductIds . '}\', 3, 0, \'\', 5000), (2, NULL, \'class\', \'rebuildStoreProductIndex\', \'{"store_id":"2","product_ids":["9","22"]}\', 3, 0, \'\', 2);'); - /** @var Queue $queue */ - $queue = $this->getObjectManager()->create(Queue::class); - $pid = getmypid(); /** @var Job[] $jobs */ - $jobs = $this->invokeMethod($queue, 'getJobs', ['maxJobs' => 10]); + $jobs = $this->invokeMethod($this->queue, 'getJobs', ['maxJobs' => 10]); $this->assertEquals(1, count($jobs)); @@ -818,11 +845,14 @@ public function testHugeJob() $this->assertNull($lastJob['pid']); } + /** + * @magentoDbIsolation disabled + */ public function testMaxSingleJobSize() { // Default value - maxBatchSize = 1000 $this->setConfig('algoliasearch_queue/queue/number_of_job_to_run', 10); - $this->setConfig('algoliasearch_advanced/advanced/number_of_element_by_page', 100); + $this->setConfig('algoliasearch_advanced/queue/number_of_element_by_page', 100); $productIds = range(1, 99); $jsonProductIds = json_encode($productIds); @@ -832,13 +862,10 @@ public function testMaxSingleJobSize() (1, NULL, \'class\', \'rebuildStoreProductIndex\', \'{"store_id":"1","product_ids":' . $jsonProductIds . '}\', 3, 0, \'\', 99), (2, NULL, \'class\', \'rebuildStoreProductIndex\', \'{"store_id":"2","product_ids":["9","22"]}\', 3, 0, \'\', 2);'); - /** @var Queue $queue */ - $queue = $this->getObjectManager()->create(Queue::class); - $pid = getmypid(); /** @var Job[] $jobs */ - $jobs = $this->invokeMethod($queue, 'getJobs', ['maxJobs' => 10]); + $jobs = $this->invokeMethod($this->queue, 'getJobs', ['maxJobs' => 10]); $this->assertEquals(2, count($jobs)); @@ -862,17 +889,20 @@ public function testMaxSingleJobSize() $this->assertEquals($pid, $lastJob['pid']); } + /** + * @magentoDbIsolation disabled + */ public function testMaxSingleJobsSizeOnProductReindex() { $this->resetConfigs([ 'algoliasearch_queue/queue/number_of_job_to_run', - 'algoliasearch_advanced/advanced/number_of_element_by_page', + 'algoliasearch_advanced/queue/number_of_element_by_page', ]); $this->setConfig('algoliasearch_queue/queue/active', '1'); $this->setConfig('algoliasearch_queue/queue/number_of_job_to_run', 10); - $this->setConfig('algoliasearch_advanced/advanced/number_of_element_by_page', 100); + $this->setConfig('algoliasearch_advanced/queue/number_of_element_by_page', 100); $this->connection->query('TRUNCATE TABLE algoliasearch_queue'); diff --git a/Test/Integration/TestCase.php b/Test/Integration/TestCase.php index 16dfc6df4..b5e7ed631 100644 --- a/Test/Integration/TestCase.php +++ b/Test/Integration/TestCase.php @@ -6,10 +6,8 @@ use Algolia\AlgoliaSearch\Helper\AlgoliaHelper; use Algolia\AlgoliaSearch\Helper\ConfigHelper; use Algolia\AlgoliaSearch\Setup\Patch\Schema\ConfigPatch; -use Algolia\AlgoliaSearch\Test\Integration\AssertValues\Magento244; -use Algolia\AlgoliaSearch\Test\Integration\AssertValues\Magento_2_01; -use Algolia\AlgoliaSearch\Test\Integration\AssertValues\Magento_2_2; -use Algolia\AlgoliaSearch\Test\Integration\AssertValues\Magento_2_3; +use Algolia\AlgoliaSearch\Test\Integration\AssertValues\Magento23; +use Algolia\AlgoliaSearch\Test\Integration\AssertValues\Magento24; use Magento\Framework\App\ProductMetadataInterface; use Magento\Store\Model\ScopeInterface; use Magento\TestFramework\Helper\Bootstrap; @@ -20,10 +18,6 @@ class_alias('PHPUnit\Framework\TestCase', '\TC'); class_alias('\PHPUnit_Framework_TestCase', '\TC'); } -if (class_exists('\Algolia\AlgoliaSearch\Test\Integration\AssertValues_2_01')) { - class_alias('\Algolia\AlgoliaSearch\Test\Integration\AssertValues_2_01', 'AssertValues'); -} - abstract class TestCase extends \TC { /** @var bool */ @@ -38,7 +32,7 @@ abstract class TestCase extends \TC /** @var ConfigHelper */ protected $configHelper; - /** @var Magento_2_01|Magento_2_2 */ + /** @var Magento23|Magento24 */ protected $assertValues; public function setUp(): void @@ -102,14 +96,10 @@ private function bootstrap() return; } - if (version_compare($this->getMagentoVersion(), '2.2.0', '<')) { - $this->assertValues = new Magento_2_01(); - } elseif (version_compare($this->getMagentoVersion(), '2.3.0', '<')) { - $this->assertValues = new Magento_2_2(); - } elseif (version_compare($this->getMagentoVersion(), '2.4.3', '<=')) { - $this->assertValues = new Magento_2_3(); + if (version_compare($this->getMagentoVersion(), '2.4.0', '<')) { + $this->assertValues = new Magento23(); } else { - $this->assertValues = new Magento244(); + $this->assertValues = new Magento24(); } $this->algoliaHelper = $this->getObjectManager()->create(AlgoliaHelper::class); diff --git a/dev/tests/install-config-mysql.php b/dev/tests/install-config-mysql.php index c0f3a10d3..37647c7cc 100644 --- a/dev/tests/install-config-mysql.php +++ b/dev/tests/install-config-mysql.php @@ -7,10 +7,17 @@ 'db-name' => 'magento2', 'db-prefix' => '', 'backend-frontname' => 'backend', + 'search-engine' => 'opensearch', + 'opensearch-host' => 'opensearch', 'admin-user' => \Magento\TestFramework\Bootstrap::ADMIN_NAME, 'admin-password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD, 'admin-email' => \Magento\TestFramework\Bootstrap::ADMIN_EMAIL, 'admin-firstname' => \Magento\TestFramework\Bootstrap::ADMIN_FIRSTNAME, 'admin-lastname' => \Magento\TestFramework\Bootstrap::ADMIN_LASTNAME, 'disable-modules' => 'Magento_WebapiSecurity,Magento_Amqp,Magento_MysqlMq,Magento_MessageQueue', + 'amqp-host' => 'rabbitmq', + 'amqp-port' => '5672', + 'amqp-user' => 'magento', + 'amqp-password' => 'magento', + 'consumers-wait-for-messages' => '0', ]; From e775afd20227e4e3c1271b7cc56aee92fa95f5b1 Mon Sep 17 00:00:00 2001 From: Damien Couchez Date: Wed, 19 Jun 2024 11:37:41 +0200 Subject: [PATCH 07/10] MAGE-851: use securedRenderer for inline scripts (#1541) --- .../templates/internals/configuration.phtml | 22 +++++++++---------- view/frontend/templates/layer/view.phtml | 22 ++++++++++++------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/view/frontend/templates/internals/configuration.phtml b/view/frontend/templates/internals/configuration.phtml index 7986b6711..47621ce1c 100755 --- a/view/frontend/templates/internals/configuration.phtml +++ b/view/frontend/templates/internals/configuration.phtml @@ -1,20 +1,18 @@ getConfiguration(); ?> - +renderTag('style', [], $configuration['instant']['selector'] . ' {display:none}', false); + /* @noEscape */ echo $secureRenderer->renderTag('script', [], 'document.write(\'' . $css . '\');' , false); +} +?> + +renderTag('script', [], "window.algoliaConfig = " . json_encode($configuration) . ';' , false); ?> + diff --git a/view/frontend/templates/layer/view.phtml b/view/frontend/templates/layer/view.phtml index 0649850d0..f444d6318 100644 --- a/view/frontend/templates/layer/view.phtml +++ b/view/frontend/templates/layer/view.phtml @@ -1,3 +1,7 @@ + + canShowBlock()) : ?>
getLayer()->getState()->getFilters()) ?> @@ -30,14 +34,16 @@
- + + renderTag('script', [], $scriptString, false); ?> - \ No newline at end of file + From 14f491b94b64fb0a776be00c863063c525e713ae Mon Sep 17 00:00:00 2001 From: Damien Couchez Date: Wed, 19 Jun 2024 15:42:55 +0200 Subject: [PATCH 08/10] MAGE-937: Fixes for Queue (#1543) * Update view.phtml (#1538) * The index in Algolia after full reindex has less records than expected (#1539) * Load last full reindex jobs after initial full reindex jobs without breaks * calculate last job id when it's required * Fixed case when no full reindex jobs * Reuse jobs count variable --------- Co-authored-by: pikulsky --- Model/Queue.php | 7 ++++++- view/adminhtml/templates/job/view.phtml | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Model/Queue.php b/Model/Queue.php index eeafde94e..42e2b26d8 100644 --- a/Model/Queue.php +++ b/Model/Queue.php @@ -401,7 +401,12 @@ protected function getJobs($maxJobs) if ($jobsCount > 0 && $jobsCount < $maxJobs) { $restLimit = $maxJobs - $jobsCount; - $lastFullReindexJobId = max($this->getJobsIdsFromMergedJobs($jobs)); + + if ($fullReindexJobsCount > 0) { + $lastFullReindexJobId = max($this->getJobsIdsFromMergedJobs($fullReindexJobs)); + } else { + $lastFullReindexJobId = max($this->getJobsIdsFromMergedJobs($jobs)); + } $restFullReindexJobs = $this->fetchJobs($restLimit, true, $lastFullReindexJobId); diff --git a/view/adminhtml/templates/job/view.phtml b/view/adminhtml/templates/job/view.phtml index dbebdb408..792a0b6de 100644 --- a/view/adminhtml/templates/job/view.phtml +++ b/view/adminhtml/templates/job/view.phtml @@ -85,7 +85,7 @@ $job = $block->getCurrentJob();
- +
escapeHtml($job->getDataSize()); ?> From 8a1cec0a1859cf4b8df07b9383691e908f418033 Mon Sep 17 00:00:00 2001 From: Mohammad Rahman Date: Tue, 25 Jun 2024 10:52:45 -0400 Subject: [PATCH 09/10] MAGE-934: release 3.13.4 version upgrade commit --- CHANGELOG.md | 9 +++++++++ README.md | 2 +- composer.json | 2 +- etc/module.xml | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f28ebc83b..b0495cd06 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # CHANGE LOG +## 3.13.4 + +### Bug Fixes +- Fixed XSS vulnerability issue in InstantSearch search box +- Fixed Algolia merchandising product listing issue +- Fixed lock timeout issue on indexing queue integration test +- Community fix added - job queue dropping jobs from sandwiched full reindexes + + ## 3.13.3 ### Updates diff --git a/README.md b/README.md index 625037641..ecfcbd4d2 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Algolia Search & Discovery extension for Magento 2 ================================================== -![Latest version](https://img.shields.io/badge/latest-3.13.3-green) +![Latest version](https://img.shields.io/badge/latest-3.13.4-green) ![Magento 2](https://img.shields.io/badge/Magento-2.4.x-orange) ![PHP](https://img.shields.io/badge/PHP-8.2%2C8.1%2C7.4-blue) diff --git a/composer.json b/composer.json index 87cb10d46..c22b268a7 100755 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Algolia Search & Discovery extension for Magento 2", "type": "magento2-module", "license": ["MIT"], - "version": "3.13.3", + "version": "3.13.4", "require": { "magento/framework": "~102.0|~103.0", "algolia/algoliasearch-client-php": "3.3.2", diff --git a/etc/module.xml b/etc/module.xml index b515de603..3b5633cc7 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - + From 519b73593884ff24f6a4c204085e9e54f4f1d935 Mon Sep 17 00:00:00 2001 From: Mohammad Rahman Date: Tue, 25 Jun 2024 11:18:40 -0400 Subject: [PATCH 10/10] MAGE-934: change log updated as per discussion --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0495cd06..9325a4491 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - Fixed XSS vulnerability issue in InstantSearch search box - Fixed Algolia merchandising product listing issue - Fixed lock timeout issue on indexing queue integration test -- Community fix added - job queue dropping jobs from sandwiched full reindexes +- Community fix added - job queue dropping jobs from sandwiched full reindexes - thank you @pikulsky ## 3.13.3