You are here

public function CommandHelper::enableServerCommand in Search API 8

Enables a server.

Parameters

string $serverId: The server's ID.

Throws

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

\Drupal\Core\Entity\EntityStorageException Thrown if an internal error occurred when saving the server.

File

src/Utility/CommandHelper.php, line 551

Class

CommandHelper
Provides functionality to be used by CLI tools.

Namespace

Drupal\search_api\Utility

Code

public function enableServerCommand($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));
  $server
    ->setStatus(TRUE)
    ->save();
}