Skip to content

Commit

Permalink
MAGE-962 Handle missing credentials in data patch
Browse files Browse the repository at this point in the history
  • Loading branch information
cammonro committed Aug 5, 2024
1 parent 296c284 commit e0a69de
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Helper/AlgoliaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ public function generateSearchSecuredApiKey(string $key, array $params = []): st
*/
public function getSettings(string $indexName): array
{
$this->checkClient(__FUNCTION__);

try {
return $this->client->getSettings($indexName);
} catch (\Exception $e) {
Expand Down
11 changes: 10 additions & 1 deletion Setup/Patch/Data/RebuildReplicasPatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Algolia\AlgoliaSearch\Setup\Patch\Data;

use Algolia\AlgoliaSearch\Helper\ConfigHelper;
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
use Algolia\AlgoliaSearch\Registry\ReplicaState;
use Algolia\AlgoliaSearch\Service\Product\ReplicaManager;
Expand All @@ -12,6 +13,7 @@
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchInterface;
use Magento\Store\Model\StoreManagerInterface;
use Psr\Log\LoggerInterface;

class RebuildReplicasPatch implements DataPatchInterface
{
Expand All @@ -21,7 +23,9 @@ public function __construct(
protected ReplicaManager $replicaManager,
protected ProductHelper $productHelper,
protected AppState $appState,
protected ReplicaState $replicaState
protected ReplicaState $replicaState,
protected ConfigHelper $configHelper,
protected LoggerInterface $logger
)
{}

Expand All @@ -48,6 +52,11 @@ public function getAliases(): array
*/
public function apply(): PatchInterface
{
if (!$this->configHelper->credentialsAreConfigured()) {
$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`");
return $this;
}

$this->moduleDataSetup->getConnection()->startSetup();
try {
$this->appState->setAreaCode(Area::AREA_ADMINHTML);
Expand Down

0 comments on commit e0a69de

Please sign in to comment.