Skip to content

Commit e0a69de

Browse files
committed
MAGE-962 Handle missing credentials in data patch
1 parent 296c284 commit e0a69de

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Helper/AlgoliaHelper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ public function generateSearchSecuredApiKey(string $key, array $params = []): st
326326
*/
327327
public function getSettings(string $indexName): array
328328
{
329+
$this->checkClient(__FUNCTION__);
330+
329331
try {
330332
return $this->client->getSettings($indexName);
331333
} catch (\Exception $e) {

Setup/Patch/Data/RebuildReplicasPatch.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Algolia\AlgoliaSearch\Setup\Patch\Data;
44

5+
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
56
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
67
use Algolia\AlgoliaSearch\Registry\ReplicaState;
78
use Algolia\AlgoliaSearch\Service\Product\ReplicaManager;
@@ -12,6 +13,7 @@
1213
use Magento\Framework\Setup\Patch\DataPatchInterface;
1314
use Magento\Framework\Setup\Patch\PatchInterface;
1415
use Magento\Store\Model\StoreManagerInterface;
16+
use Psr\Log\LoggerInterface;
1517

1618
class RebuildReplicasPatch implements DataPatchInterface
1719
{
@@ -21,7 +23,9 @@ public function __construct(
2123
protected ReplicaManager $replicaManager,
2224
protected ProductHelper $productHelper,
2325
protected AppState $appState,
24-
protected ReplicaState $replicaState
26+
protected ReplicaState $replicaState,
27+
protected ConfigHelper $configHelper,
28+
protected LoggerInterface $logger
2529
)
2630
{}
2731

@@ -48,6 +52,11 @@ public function getAliases(): array
4852
*/
4953
public function apply(): PatchInterface
5054
{
55+
if (!$this->configHelper->credentialsAreConfigured()) {
56+
$this->logger->warning("Algolia credentials are not configured. Aborting replica rebuild patch. If you need to rebuild your replicas run `bin/magento algolia:replicas:rebuild`");
57+
return $this;
58+
}
59+
5160
$this->moduleDataSetup->getConnection()->startSetup();
5261
try {
5362
$this->appState->setAreaCode(Area::AREA_ADMINHTML);

0 commit comments

Comments
 (0)