You are here

public function CommandHelper::disableIndexCommand in Search API 8

Disables one or more enabled search indexes.

Parameters

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

Throws

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

File

src/Utility/CommandHelper.php, line 237

Class

CommandHelper
Provides functionality to be used by CLI tools.

Namespace

Drupal\search_api\Utility

Code

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