Skip to content

Commit

Permalink
fix: make indexing robust if config is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
wilr committed Jan 9, 2023
1 parent dca145d commit 5a8403b
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/ElasticaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,14 @@ public function getClient()
}

/**
* @return Index
* @return ?Index
*/
public function getIndex()
{
if (!$this->indexName) {
return null;
}

return $this->getClient()->getIndex($this->indexName);
}

Expand Down Expand Up @@ -209,9 +213,14 @@ public function index($record)
// Add document
return $this->runQuery(
function () use ($index, $document) {
$response = $index->addDocument($document);
$index->refresh();
return $response;
if ($index) {
$response = $index->addDocument($document);
$index->refresh();

return $response;
}

return null;
}
);
}
Expand Down Expand Up @@ -341,6 +350,11 @@ public function remove($record)

try {
$index = $this->getIndex();

if (!$index) {
return false;
}

$typeName = $record->getElasticaType();
$document = $record->getElasticaDocument();
// If batching
Expand Down

0 comments on commit 5a8403b

Please sign in to comment.