Skip to content

Commit bcb2e07

Browse files
committed
MAGE-1170: changes after review
1 parent 6a442b6 commit bcb2e07

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

Api/Data/IndexOptionsInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function getIndexSuffix(): ?string;
3131
*
3232
* @return bool
3333
*/
34-
public function isTmp(): bool;
34+
public function isTemporaryIndex(): bool;
3535

3636
/**
3737
* Get field: enforced_index_name

Model/IndexOptions.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,45 @@
77

88
class IndexOptions extends DataObject implements IndexOptionsInterface
99
{
10+
/**
11+
* Return the current store_id; if the method returns null, the Magento default store will be used
12+
*
13+
* @return int|null
14+
*/
1015
public function getStoreId(): ?int
1116
{
1217
return $this->hasData(IndexOptionsInterface::STORE_ID) ?
1318
(int) $this->getData(IndexOptionsInterface::STORE_ID) :
1419
null;
1520
}
1621

22+
/**
23+
* Suffix usually refers to the entity to index (_products, _categories, _pages, ...)
24+
*
25+
* @return string|null
26+
*/
1727
public function getIndexSuffix(): ?string
1828
{
1929
return $this->hasData(IndexOptionsInterface::INDEX_SUFFIX) ?
2030
(string) $this->getData(IndexOptionsInterface::INDEX_SUFFIX) :
2131
null;
2232
}
2333

24-
public function isTmp(): bool
34+
/**
35+
* Temporary indices can be used in case of full reindexing
36+
*
37+
* @return bool
38+
*/
39+
public function isTemporaryIndex(): bool
2540
{
26-
return $this->hasData(IndexOptionsInterface::IS_TMP) ?
27-
(string) $this->getData(IndexOptionsInterface::IS_TMP) :
28-
false;
41+
return $this->hasData(IndexOptionsInterface::IS_TMP) && $this->getData(IndexOptionsInterface::IS_TMP);
2942
}
3043

44+
/**
45+
* In case an enforced index name is used, this will override the index names fetched by the IndexNameFetcher service
46+
*
47+
* @return string|null
48+
*/
3149
public function getEnforcedIndexName(): ?string
3250
{
3351
return $this->hasData(IndexOptionsInterface::ENFORCED_INDEX_NAME) ?

Service/AlgoliaConnector.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ function ($id) {
308308
}
309309

310310
/**
311+
* Warning: This method can't be performed across two different applications
312+
*
311313
* @param IndexOptions $fromIndexOptions
312314
* @param IndexOptions $toIndexOptions
313315
* @return void
@@ -560,6 +562,8 @@ public function deleteRule(
560562
}
561563

562564
/**
565+
* Warning: This method can't be performed across two different applications
566+
*
563567
* @param IndexOptionsInterface $fromIndexOptions
564568
* @param IndexOptionsInterface $toIndexOptions
565569
* @return void
@@ -583,6 +587,8 @@ public function copySynonyms(IndexOptionsInterface $fromIndexOptions, IndexOptio
583587
}
584588

585589
/**
590+
* Warning: This method can't be performed across two different applications
591+
*
586592
* @param IndexOptionsInterface $fromIndexOptions
587593
* @param IndexOptionsInterface $toIndexOptions
588594
* @return void
@@ -1062,6 +1068,7 @@ protected function getAlgoliaFiltersArrayWithoutCurrentRefinement($filters, $nee
10621068
* @param IndexOptionsInterface $indexOptions
10631069
* @return string|null
10641070
* @throws NoSuchEntityException
1071+
* @throws AlgoliaException
10651072
*/
10661073
protected function getIndexName(IndexOptionsInterface $indexOptions): ?string
10671074
{
@@ -1070,13 +1077,13 @@ protected function getIndexName(IndexOptionsInterface $indexOptions): ?string
10701077
}
10711078

10721079
if (is_null($indexOptions->getIndexSuffix())) {
1073-
return null;
1080+
throw new AlgoliaException('Index suffix is mandatory in case no enforced index name is specified.');
10741081
}
10751082

10761083
return $this->indexNameFetcher->getIndexName(
10771084
$indexOptions->getIndexSuffix(),
10781085
$indexOptions->getStoreId(),
1079-
$indexOptions->isTmp()
1086+
$indexOptions->isTemporaryIndex()
10801087
);
10811088
}
10821089
}

0 commit comments

Comments
 (0)