You are here

public function CommandHelper::clearIndexCommand in Search API 8

Deletes all items from one or more indexes.

Parameters

string[]|null $indexIds: (optional) An array of index IDs, or NULL if we should delete all items from all indexes.

Return value

bool TRUE when the clearing was successful, FALSE when no indexes were found.

Throws

\Drupal\search_api\SearchApiException Thrown if one of the affected indexes had an invalid tracker set, or some other internal error occurred.

File

src/Utility/CommandHelper.php, line 437

Class

CommandHelper
Provides functionality to be used by CLI tools.

Namespace

Drupal\search_api\Utility

Code

public function clearIndexCommand(array $indexIds = NULL) {
  $indexes = $this
    ->loadIndexes($indexIds);
  if (!$indexes) {
    return FALSE;
  }
  foreach ($indexes as $index) {
    if ($index
      ->status()) {
      $index
        ->clear();
      $this->logger
        ->info($this
        ->t('@index was successfully cleared.', [
        '@index' => $index
          ->label(),
      ]));
    }
  }
  return TRUE;
}