Skip to content

Commit

Permalink
Attempt to more clearly use delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Erkelens committed Oct 19, 2023
1 parent 8203361 commit bcd9725
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/Indexes/ElasticIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public function deleteIndex(?HTTPRequest $request = null): bool
if ($this->shouldClear($request) && $this->indexExists()) {
$this->getLogger()->info(sprintf('Clearing index %s', $this->getIndexName()));
$deleteResult = $this->client
->getClient()
->indices()
->delete(['index' => $this->getIndexName()])
->asBool();
Expand Down
8 changes: 4 additions & 4 deletions src/Tasks/ElasticConfigureTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Firesphere\ElasticSearch\Indexes\ElasticIndex;
use Firesphere\ElasticSearch\Services\ElasticCoreService;
use Firesphere\SearchBackend\Helpers\FieldResolver;
use Firesphere\SearchBackend\Indexes\CoreIndex;
use Firesphere\SearchBackend\Traits\LoggerTrait;
use Psr\Container\NotFoundExceptionInterface;
use SilverStripe\Control\HTTPRequest;
Expand Down Expand Up @@ -95,8 +96,8 @@ public function run($request)
/** @var ElasticIndex $instance */
$instance = Injector::inst()->get($index, false);
// If delete in advance, do so
$index->deleteIndex($request);
$configResult = $this->configureIndex($instance, $request);
$instance->deleteIndex($request);
$configResult = $this->configureIndex($instance);
$result[] = $configResult->asBool();
} catch (Exception $error) {
// @codeCoverageIgnoreStart
Expand All @@ -119,14 +120,13 @@ public function run($request)
/**
* Update/create a single index.
* @param ElasticIndex $index
* @param HTTPRequest|null $request
* @return Elasticsearch
* @throws ClientResponseException
* @throws MissingParameterException
* @throws NotFoundExceptionInterface
* @throws ServerResponseException
*/
public function configureIndex($index, ?HTTPRequest $request = null): Elasticsearch
public function configureIndex(CoreIndex $index): Elasticsearch
{
$indexName = $index->getIndexName();

Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/ElasticIndexTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function run($request)
}
// If clearing, also configure
if ($index->deleteIndex($request)) {
(new ElasticConfigureTask())->configureIndex($index, $request);
(new ElasticConfigureTask())->configureIndex($index);

Check warning on line 135 in src/Tasks/ElasticIndexTask.php

View check run for this annotation

Codecov / codecov/patch

src/Tasks/ElasticIndexTask.php#L135

Added line #L135 was not covered by tests
}

// Get the groups
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Tasks/ElasticConfigureTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function testRun()
public function testConfigureIndex()
{
$index = new SearchIndex();

$task = new ElasticConfigureTask();
$result = $task->configureIndex($index);

$task->deleteIndex()
$this->assertTrue($result->asBool());
}
}

0 comments on commit bcd9725

Please sign in to comment.