Skip to content

Commit a57fa87

Browse files
authored
Merge pull request #1761 from algolia/feat/MAGE-1270-indexing-configuration
MAGE-1270: Move indexing configuration to the indexing manager
2 parents 0704c91 + 45e32c1 commit a57fa87

File tree

12 files changed

+156
-63
lines changed

12 files changed

+156
-63
lines changed

Helper/ConfigHelper.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
class ConfigHelper
2222
{
2323
public const ENABLE_FRONTEND = 'algoliasearch_credentials/credentials/enable_frontend';
24-
public const ENABLE_BACKEND = 'algoliasearch_credentials/credentials/enable_backend';
25-
public const ENABLE_QUERY_SUGGESTIONS_INDEX = 'algoliasearch_credentials/credentials/enable_query_suggestions_index';
26-
public const ENABLE_PAGES_INDEX = 'algoliasearch_credentials/credentials/enable_pages_index';
2724
public const LOGGING_ENABLED = 'algoliasearch_credentials/credentials/debug';
2825
public const APPLICATION_ID = 'algoliasearch_credentials/credentials/application_id';
2926
public const API_KEY = 'algoliasearch_credentials/credentials/api_key';
@@ -133,6 +130,9 @@ class ConfigHelper
133130
public const ARCHIVE_LOG_CLEAR_LIMIT = 'algoliasearch_advanced/queue/archive_clear_limit';
134131

135132
// Indexing Manager settings
133+
public const ENABLE_INDEXING = 'algoliasearch_indexing_manager/algolia_indexing/enable_indexing';
134+
public const ENABLE_QUERY_SUGGESTIONS_INDEX = 'algoliasearch_indexing_manager/algolia_indexing/enable_query_suggestions_index';
135+
public const ENABLE_PAGES_INDEX = 'algoliasearch_indexing_manager/algolia_indexing/enable_pages_index';
136136
public const ENABLE_INDEXER_PRODUCTS = 'algoliasearch_indexing_manager/full_indexing/products';
137137
public const ENABLE_INDEXER_CATEGORIES = 'algoliasearch_indexing_manager/full_indexing/categories';
138138
public const ENABLE_INDEXER_PAGES = 'algoliasearch_indexing_manager/full_indexing/pages';
@@ -247,9 +247,9 @@ public function isEnabledFrontEnd($storeId = null)
247247
* @param $storeId
248248
* @return bool
249249
*/
250-
public function isEnabledBackend($storeId = null)
250+
public function isIndexingEnabled($storeId = null)
251251
{
252-
return $this->configInterface->isSetFlag(self::ENABLE_BACKEND, ScopeInterface::SCOPE_STORE, $storeId);
252+
return $this->configInterface->isSetFlag(self::ENABLE_INDEXING, ScopeInterface::SCOPE_STORE, $storeId);
253253
}
254254

255255
/**
@@ -1715,6 +1715,15 @@ public function isQueueIndexerEnabled(): bool
17151715
*/
17161716
public const LEGACY_USE_VIRTUAL_REPLICA_ENABLED = 'algoliasearch_instant/instant/use_virtual_replica';
17171717

1718+
// --- Indexing Manager --- //
1719+
1720+
/**
1721+
* @deprecated This constant has been renamed to be more meaningful and to avoid confusion with "backend rendering" statements
1722+
* @see \Algolia\AlgoliaSearch\Helper\ConfigHelper::ENABLE_INDEXING
1723+
*/
1724+
public const ENABLE_BACKEND = self::ENABLE_INDEXING;
1725+
1726+
17181727
// --- Autocomplete --- //
17191728

17201729
/**
@@ -2035,4 +2044,17 @@ public function hidePaginationInInstantSearchPage($storeId = null)
20352044
{
20362045
return $this->instantSearchConfig->shouldHidePagination($storeId);
20372046
}
2047+
2048+
// --- Indexing Manager --- //
2049+
2050+
/**
2051+
* @param $storeId
2052+
* @return bool
2053+
* @deprecated This method has been renamed to be more meaningful and to avoid confusion with "backend rendering" statements
2054+
* @see \Algolia\AlgoliaSearch\Helper\ConfigHelper::isIndexingEnabled()
2055+
*/
2056+
public function isEnabledBackend($storeId = null)
2057+
{
2058+
return $this->isIndexingEnabled($storeId);
2059+
}
20382060
}

Helper/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function getSearchResult(string $query, int $storeId, ?array $searchParam
189189
*/
190190
public function isIndexingEnabled($storeId = null): bool
191191
{
192-
if ($this->configHelper->isEnabledBackend($storeId) === false) {
192+
if ($this->configHelper->isIndexingEnabled($storeId) === false) {
193193
$this->logger->log('INDEXING IS DISABLED FOR ' . $this->logger->getStoreName($storeId));
194194
return false;
195195
}

Helper/Entity/PageHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function getStores($storeId = null)
105105
if ($storeId === null) {
106106
/** @var \Magento\Store\Model\Store $store */
107107
foreach ($this->storeManager->getStores() as $store) {
108-
if ($this->configHelper->isEnabledBackEnd($store->getId()) === false) {
108+
if ($this->configHelper->isIndexingEnabled($store->getId()) === false) {
109109
continue;
110110
}
111111

Service/AbstractIndexBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(
3030
*/
3131
protected function isIndexingEnabled($storeId = null): bool
3232
{
33-
if ($this->configHelper->isEnabledBackend($storeId) === false) {
33+
if ($this->configHelper->isIndexingEnabled($storeId) === false) {
3434
$this->logger->log('INDEXING IS DISABLED FOR ' . $this->logger->getStoreName($storeId));
3535
return false;
3636
}

Service/Product/ReplicaManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ function($replica) use ($replicas) {
494494
*/
495495
public function isReplicaSyncEnabled(int $storeId): bool
496496
{
497-
return $this->configHelper->isInstantEnabled($storeId) && $this->configHelper->isEnabledBackend($storeId);
497+
return $this->configHelper->isInstantEnabled($storeId) && $this->configHelper->isIndexingEnabled($storeId);
498498
}
499499

500500
/**
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Setup\Patch\Data;
4+
5+
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
6+
use Magento\Framework\Setup\ModuleDataSetupInterface;
7+
use Magento\Framework\Setup\Patch\DataPatchInterface;
8+
use Magento\Framework\Setup\Patch\PatchInterface;
9+
10+
class MigrateIndexingConfigPatch implements DataPatchInterface
11+
{
12+
public function __construct(
13+
protected ModuleDataSetupInterface $moduleDataSetup,
14+
) {}
15+
16+
/**
17+
* @inheritDoc
18+
*/
19+
public function apply(): PatchInterface
20+
{
21+
$this->moduleDataSetup->getConnection()->startSetup();
22+
23+
$this->moveIndexingSettings();
24+
25+
$this->moduleDataSetup->getConnection()->endSetup();
26+
27+
return $this;
28+
}
29+
30+
/**
31+
* Migrate old Indexing configurations
32+
* @return void
33+
*/
34+
protected function moveIndexingSettings(): void
35+
{
36+
$movedConfig = [
37+
'algoliasearch_credentials/credentials/enable_backend' => ConfigHelper::ENABLE_INDEXING,
38+
'algoliasearch_credentials/credentials/enable_query_suggestions_index' => ConfigHelper::ENABLE_QUERY_SUGGESTIONS_INDEX,
39+
'algoliasearch_credentials/credentials/enable_pages_index' => ConfigHelper::ENABLE_PAGES_INDEX,
40+
];
41+
42+
$connection = $this->moduleDataSetup->getConnection();
43+
foreach ($movedConfig as $from => $to) {
44+
$configDataTable = $this->moduleDataSetup->getTable('core_config_data');
45+
$whereConfigPath = $connection->quoteInto('path = ?', $from);
46+
$connection->update($configDataTable, ['path' => $to], $whereConfigPath);
47+
}
48+
}
49+
50+
/**
51+
* @inheritDoc
52+
*/
53+
public static function getDependencies(): array
54+
{
55+
return [];
56+
}
57+
58+
/**
59+
* @inheritDoc
60+
*/
61+
public function getAliases(): array
62+
{
63+
return [];
64+
}
65+
}

Setup/Patch/Schema/ConfigPatch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ConfigPatch implements SchemaPatchInterface
3030
* @var string[]
3131
*/
3232
protected $defaultConfigData = [
33-
'algoliasearch_credentials/credentials/enable_backend' => '1',
33+
'algoliasearch_indexing_manager/algolia_indexing/enable_indexing' => '1',
3434
'algoliasearch_credentials/credentials/enable_frontend' => '1',
3535
'algoliasearch_credentials/credentials/application_id' => '',
3636
'algoliasearch_credentials/credentials/search_only_api_key' => '',

Test/Integration/Indexing/Product/ReplicaIndexingTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function testReplicaSync(): void
192192
}
193193

194194
/**
195-
* @magentoConfigFixture current_store algoliasearch_credentials/credentials/enable_backend 0
195+
* @magentoConfigFixture current_store algoliasearch_indexing_manager/algolia_indexing/enable_indexing 0
196196
* @magentoConfigFixture current_store algoliasearch_instant/instant/is_instant_enabled 1
197197
* @throws AlgoliaException
198198
* @throws ExceededRetriesException
@@ -241,7 +241,7 @@ public function testReplicaDeleteUnreliable(): void
241241

242242
/**
243243
* Test the RebuildReplicasPatch with API failures
244-
* @magentoConfigFixture current_store algoliasearch_credentials/credentials/enable_backend 1
244+
* @magentoConfigFixture current_store algoliasearch_indexing_manager/algolia_indexing/enable_indexing 1
245245
* @magentoConfigFixture current_store algoliasearch_instant/instant/is_instant_enabled 1
246246
*/
247247
public function testReplicaRebuildPatch(): void

Test/Integration/_files/second_website_with_two_stores_and_products.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@
6767

6868
$configManager = $objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class);
6969
// Temporarily disable indexing during product assignment to stores
70-
$configManager->setValue('algoliasearch_credentials/credentials/enable_backend', 0, 'store', 'admin');
71-
$configManager->setValue('algoliasearch_credentials/credentials/enable_backend', 0, 'store', 'default');
72-
$configManager->setValue('algoliasearch_credentials/credentials/enable_backend', 0, 'store', 'fixture_second_store');
73-
$configManager->setValue('algoliasearch_credentials/credentials/enable_backend', 0, 'store', 'fixture_third_store');
70+
$configManager->setValue('algoliasearch_indexing_manager/algolia_indexing/enable_indexing', 0, 'store', 'admin');
71+
$configManager->setValue('algoliasearch_indexing_manager/algolia_indexing/enable_indexing', 0, 'store', 'default');
72+
$configManager->setValue('algoliasearch_indexing_manager/algolia_indexing/enable_indexing', 0, 'store', 'fixture_second_store');
73+
$configManager->setValue('algoliasearch_indexing_manager/algolia_indexing/enable_indexing', 0, 'store', 'fixture_third_store');
7474

7575
$productSkus = MultiStoreProductsTest::SKUS;
7676
$productRepository = Bootstrap::getObjectManager()
@@ -82,10 +82,10 @@
8282
$productRepository->save($product);
8383
}
8484

85-
$configManager->setValue('algoliasearch_credentials/credentials/enable_backend', 1, 'store', 'admin');
86-
$configManager->setValue('algoliasearch_credentials/credentials/enable_backend', 1, 'store', 'default');
87-
$configManager->setValue('algoliasearch_credentials/credentials/enable_backend', 1, 'store', 'fixture_second_store');
88-
$configManager->setValue('algoliasearch_credentials/credentials/enable_backend', 1, 'store', 'fixture_third_store');
85+
$configManager->setValue('algoliasearch_indexing_manager/algolia_indexing/enable_indexing', 1, 'store', 'admin');
86+
$configManager->setValue('algoliasearch_indexing_manager/algolia_indexing/enable_indexing', 1, 'store', 'default');
87+
$configManager->setValue('algoliasearch_indexing_manager/algolia_indexing/enable_indexing', 1, 'store', 'fixture_second_store');
88+
$configManager->setValue('algoliasearch_indexing_manager/algolia_indexing/enable_indexing', 1, 'store', 'fixture_third_store');
8989

9090
/* Refresh CatalogSearch index */
9191
/** @var IndexerRegistry $indexerRegistry */

etc/adminhtml/system.xml

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -53,43 +53,6 @@
5353
]]>
5454
</comment>
5555
</field>
56-
<field id="enable_backend" translate="label comment" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
57-
<label>Enable Indexing</label>
58-
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
59-
<comment>
60-
<![CDATA[
61-
Do you want the Algolia extension to push your data to Algolia?<br>
62-
The benefit here is that Algolia will manage to keep your data up to date.
63-
If you choose "No", you will need to push and manage your data in a different way.
64-
]]>
65-
</comment>
66-
</field>
67-
<field id="enable_query_suggestions_index" translate="label comment" type="select" sortOrder="41" showInDefault="1" showInWebsite="1" showInStore="1">
68-
<label>Enable Query Suggestions Index</label>
69-
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
70-
<comment>
71-
<![CDATA[
72-
Do you want the Algolia extension to push your search terms/suggestions to Algolia?<br>
73-
If you choose "No", _suggestion indexes will not be created.
74-
]]>
75-
</comment>
76-
<depends>
77-
<field id="enable_backend">1</field>
78-
</depends>
79-
</field>
80-
<field id="enable_pages_index" translate="label comment" type="select" sortOrder="41" showInDefault="1" showInWebsite="1" showInStore="1">
81-
<label>Enable Pages Index</label>
82-
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
83-
<comment>
84-
<![CDATA[
85-
Do you want the Algolia extension to push your CMS Pages to Algolia?<br>
86-
If you choose "No", _pages indexes will not be created.
87-
]]>
88-
</comment>
89-
<depends>
90-
<field id="enable_backend">1</field>
91-
</depends>
92-
</field>
9356
<field id="enable_frontend" translate="label comment" type="select" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
9457
<label>Enable Search</label>
9558
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
@@ -1085,6 +1048,47 @@
10851048
<label>Indexing Manager</label>
10861049
<tab>algolia</tab>
10871050
<resource>Algolia_AlgoliaSearch::algolia_algoliasearch</resource>
1051+
<group id="algolia_indexing" translate="label" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
1052+
<label>Enable Algolia indexing</label>
1053+
<attribute type="expanded">1</attribute>
1054+
<field id="enable_indexing" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
1055+
<label>Enable Indexing</label>
1056+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
1057+
<comment>
1058+
<![CDATA[
1059+
Do you want the Algolia extension to push your data to Algolia?<br>
1060+
The benefit here is that Algolia will manage to keep your data up to date.
1061+
If you choose "No", you will need to push and manage your data in a different way.
1062+
]]>
1063+
</comment>
1064+
</field>
1065+
<field id="enable_query_suggestions_index" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
1066+
<label>Enable Query Suggestions Index</label>
1067+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
1068+
<comment>
1069+
<![CDATA[
1070+
Do you want the Algolia extension to push your search terms/suggestions to Algolia?<br>
1071+
If you choose "No", _suggestion indexes will not be created.
1072+
]]>
1073+
</comment>
1074+
<depends>
1075+
<field id="algolia_indexing">1</field>
1076+
</depends>
1077+
</field>
1078+
<field id="enable_pages_index" translate="label comment" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
1079+
<label>Enable Pages Index</label>
1080+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
1081+
<comment>
1082+
<![CDATA[
1083+
Do you want the Algolia extension to push your CMS Pages to Algolia?<br>
1084+
If you choose "No", _pages indexes will not be created.
1085+
]]>
1086+
</comment>
1087+
<depends>
1088+
<field id="algolia_indexing">1</field>
1089+
</depends>
1090+
</field>
1091+
</group>
10881092
<group id="full_indexing" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
10891093
<label>Full indexing via Magento indexers</label>
10901094
<comment>

0 commit comments

Comments
 (0)