You are here

public function CommandHelper::enableIndexCommand in Search API 8

Enables one or more disabled search indexes.

Parameters

array $index_ids: (optional) An array of machine names of indexes to enable. If omitted all indexes will be enabled.

Throws

\Drupal\search_api\ConsoleException Thrown if no indexes could be loaded.

File

src/Utility/CommandHelper.php, line 209

Class

CommandHelper
Provides functionality to be used by CLI tools.

Namespace

Drupal\search_api\Utility

Code

public function enableIndexCommand(array $index_ids = NULL) {
  if (!$this
    ->getIndexCount()) {
    throw new ConsoleException($this
      ->t('There are no indexes defined. Please create an index before trying to enable it.'));
  }
  $indexes = $this
    ->loadIndexes($index_ids);
  if (!$indexes) {
    throw new ConsoleException($this
      ->t('You must specify at least one index to enable.'));
  }
  foreach ($indexes as $index) {
    if (!$index
      ->status()) {
      $this
        ->setIndexState($index);
    }
  }
}