You are here

public function CommandHelper::indexListCommand in Search API 8

Lists all search indexes.

Return value

array An associative array, keyed by search index ID, each value an associative array with the following keys:

  • id: The ID of the search index.
  • name: The human readable name of the search index.
  • server: The ID of the server associated with the search index.
  • serverName: The human readable name of the server associated with the search index.
  • types: An array of entity type IDs that are tracked in the index.
  • typeNames: An array of human readable entity type labels that are tracked in the index.
  • status: Either "enabled" or "disabled".
  • limit: The number of items that are processed in a single cron run.

Throws

\Drupal\search_api\SearchApiException Thrown if an index has a server which couldn't be loaded.

File

src/Utility/CommandHelper.php, line 119

Class

CommandHelper
Provides functionality to be used by CLI tools.

Namespace

Drupal\search_api\Utility

Code

public function indexListCommand() {
  $indexes = $this
    ->loadIndexes();
  if (!$indexes) {
    return [];
  }
  $rows = [];
  $none = '(' . $this
    ->t('none') . ')';
  $enabled = $this
    ->t('enabled');
  $disabled = $this
    ->t('disabled');
  foreach ($indexes as $index) {
    $types = [];
    $type_names = [];
    foreach ($index
      ->getDatasources() as $datasource) {
      $types[] = $datasource
        ->getEntityTypeId();
      $type_names[] = (string) $datasource
        ->label();
    }
    $rows[$index
      ->id()] = [
      'id' => $index
        ->id(),
      'name' => $index
        ->label(),
      'server' => $index
        ->getServerId() ?: $none,
      'serverName' => $index
        ->getServerId() ? $index
        ->getServerInstance()
        ->label() : $none,
      'types' => $types,
      'typeNames' => $type_names,
      'status' => $index
        ->status() ? $enabled : $disabled,
      'limit' => (int) $index
        ->getOption('cron_limit'),
    ];
  }
  return $rows;
}