Skip to content

Commit

Permalink
MAGE-941 Centralize page index name logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cammonro committed Jun 27, 2024
1 parent 01d1885 commit 2b1bd9b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 84 deletions.
20 changes: 10 additions & 10 deletions DataProvider/Analytics/IndexEntityDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,31 @@ public function __construct(
}

/**
* @param $storeId
*
* @return array
* @param int $storeId
* @return array<string, string>
* @throws NoSuchEntityException
*/
public function getEntityIndexes($storeId)
public function getEntityIndexes(int $storeId): array
{
if (empty($this->entityIndexes)) {
$this->entityIndexes = [
'products' => $this->productHelper->getIndexName($storeId),
'products' => $this->productHelper->getIndexName($storeId),
'categories' => $this->categoryHelper->getIndexName($storeId),
'pages' => $this->dataHelper->getIndexName($this->pageHelper->getIndexNameSuffix(), $storeId),
'pages' => $this->pageHelper->getIndexName($storeId)
];
}

return $this->entityIndexes;
}

/**
* @param $entity
* @param $storeId
* @param string $entity
* @param int $storeId
*
* @return mixed
* @return string
* @throws NoSuchEntityException
*/
public function getIndexNameByEntity($entity, $storeId)
public function getIndexNameByEntity(string $entity, int $storeId): string
{
$indexes = $this->getEntityIndexes($storeId);

Expand Down
5 changes: 3 additions & 2 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,9 @@ public function rebuildStoreAdditionalSectionsIndex($storeId)
* @param array|null $pageIds
* @return void
* @throws AlgoliaException
* @throws NoSuchEntityException
*/
public function rebuildStorePageIndex($storeId, array $pageIds = null)
public function rebuildStorePageIndex($storeId, array $pageIds = null): void
{
if ($this->isIndexingEnabled($storeId) === false) {
return;
Expand All @@ -281,7 +282,7 @@ public function rebuildStorePageIndex($storeId, array $pageIds = null)
return;
}

$indexName = $this->getIndexName($this->pageHelper->getIndexNameSuffix(), $storeId);
$indexName = $this->pageHelper->getIndexName($storeId);

$this->startEmulation($storeId);

Expand Down
23 changes: 12 additions & 11 deletions Helper/Entity/CategoryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@ class CategoryHelper extends AbstractEntityHelper
protected $categoryNames;

public function __construct(
protected ManagerInterface $eventManager,
protected StoreManagerInterface $storeManager,
protected ResourceConnection $resourceConnection,
protected Config $eavConfig,
protected ConfigHelper $configHelper,
protected ManagerInterface $eventManager,
protected StoreManagerInterface $storeManager,
protected ResourceConnection $resourceConnection,
protected Config $eavConfig,
protected ConfigHelper $configHelper,
protected CategoryCollectionFactory $categoryCollectionFactory,
protected Image $imageHelper,
protected CategoryResource $categoryResource,
protected CategoryRepository $categoryRepository,
protected Manager $moduleManager,
protected Data $baseHelper
) {
protected Image $imageHelper,
protected CategoryResource $categoryResource,
protected CategoryRepository $categoryRepository,
protected Manager $moduleManager,
protected Data $baseHelper
)
{
parent::__construct($baseHelper);
}

Expand Down
71 changes: 16 additions & 55 deletions Helper/Entity/PageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Algolia\AlgoliaSearch\Helper\AlgoliaHelper;
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
use Algolia\AlgoliaSearch\Helper\Data;
use Magento\Cms\Model\Page;
use Magento\Cms\Model\ResourceModel\Page\CollectionFactory as PageCollectionFactory;
use Magento\Cms\Model\Template\FilterProvider;
Expand All @@ -12,65 +13,25 @@
use Magento\Framework\UrlFactory;
use Magento\Store\Model\StoreManagerInterface;

class PageHelper
class PageHelper extends AbstractEntityHelper
{
/**
* @var ManagerInterface
*/
private $eventManager;

/**
* @var PageCollectionFactory
*/
private $pageCollectionFactory;

/**
* @var ConfigHelper
*/
private $configHelper;

/**
* @var FilterProvider
*/
private $filterProvider;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @var UrlFactory
*/
private $frontendUrlFactory;

/**
* PageHelper constructor.
*
* @param ManagerInterface $eventManager
* @param PageCollectionFactory $pageCollectionFactory
* @param ConfigHelper $configHelper
* @param FilterProvider $filterProvider
* @param StoreManagerInterface $storeManager
* @param UrlFactory $frontendUrlFactory
*/
public function __construct(
ManagerInterface $eventManager,
PageCollectionFactory $pageCollectionFactory,
ConfigHelper $configHelper,
FilterProvider $filterProvider,
StoreManagerInterface $storeManager,
UrlFactory $frontendUrlFactory
) {
$this->eventManager = $eventManager;
$this->pageCollectionFactory = $pageCollectionFactory;
$this->configHelper = $configHelper;
$this->filterProvider = $filterProvider;
$this->storeManager = $storeManager;
$this->frontendUrlFactory = $frontendUrlFactory;
protected ManagerInterface $eventManager,
protected PageCollectionFactory $pageCollectionFactory,
protected ConfigHelper $configHelper,
protected FilterProvider $filterProvider,
protected StoreManagerInterface $storeManager,
protected UrlFactory $frontendUrlFactory,
protected Data $baseHelper
)
{
parent::__construct($baseHelper);
}

public function getIndexNameSuffix()
/**
* @inheritDoc
*/
public function getIndexNameSuffix(): string
{
return '_pages';
}
Expand Down
13 changes: 7 additions & 6 deletions Model/IndicesConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct(
* @return void
* @throws AlgoliaException
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws NoSuchEntityException
*/
public function saveConfigurationToAlgolia(int $storeId, bool $useTmpIndex = false): void
{
Expand Down Expand Up @@ -126,7 +126,7 @@ public function saveConfigurationToAlgolia(int $storeId, bool $useTmpIndex = fal
/**
* @param int $storeId
*
* @throws AlgoliaException|\Magento\Framework\Exception\NoSuchEntityException
* @throws AlgoliaException|NoSuchEntityException
*/
protected function setCategoriesSettings(int $storeId): void
{
Expand All @@ -146,13 +146,14 @@ protected function setCategoriesSettings(int $storeId): void
* @param int $storeId
*
* @throws AlgoliaException
* @throws NoSuchEntityException
*/
protected function setPagesSettings($storeId)
protected function setPagesSettings(int $storeId): void
{
$this->logger->start('Pushing settings for CMS pages indices.');

$settings = $this->pageHelper->getIndexSettings($storeId);
$indexName = $this->baseHelper->getIndexName($this->pageHelper->getIndexNameSuffix(), $storeId);
$indexName = $this->pageHelper->getIndexName($storeId);

$this->algoliaHelper->setSettings($indexName, $settings, false, true);

Expand Down Expand Up @@ -216,7 +217,7 @@ protected function setAdditionalSectionsSettings($storeId)
* @return void
* @throws AlgoliaException
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws NoSuchEntityException
*/
protected function setProductsSettings(int $storeId, bool $useTmpIndex): void
{
Expand Down Expand Up @@ -249,7 +250,7 @@ protected function setExtraSettings(int $storeId, bool $saveToTmpIndicesToo): vo
$sections = [
'products' => $this->productHelper->getIndexName($storeId),
'categories' => $this->categoryHelper->getIndexName($storeId),
'pages' => $this->baseHelper->getIndexName($this->pageHelper->getIndexNameSuffix(), $storeId),
'pages' => $this->pageHelper->getIndexName($storeId),
'suggestions' => $this->baseHelper->getIndexName($this->suggestionHelper->getIndexNameSuffix(), $storeId),
'additional_sections' => $this->baseHelper->getIndexName($additionalSectionsSuffix, $storeId),
];
Expand Down

0 comments on commit 2b1bd9b

Please sign in to comment.