You are here

public function CommandHelper::clearServerCommand in Search API 8

Clears all indexes on a server.

Parameters

string $serverId: The ID of the server to clear.

Throws

\Drupal\search_api\ConsoleException Thrown if the server couldn't be loaded.

\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 594

Class

CommandHelper
Provides functionality to be used by CLI tools.

Namespace

Drupal\search_api\Utility

Code

public function clearServerCommand($serverId) {
  $servers = $this
    ->loadServers([
    $serverId,
  ]);
  if (empty($servers)) {
    throw new ConsoleException($this
      ->t('The server could not be loaded.'));
  }

  /** @var \Drupal\search_api\ServerInterface $server */
  $server = $this
    ->reloadEntityOverrideFree(reset($servers));
  foreach ($server
    ->getIndexes() as $index) {
    $index
      ->clear();
  }
}