You are here

protected function Index::reactToServerSwitch in Search API 8

Checks whether the index switched server and reacts accordingly.

Used as a helper method in postSave(). Should only be called when the index was enabled before the change and remained so.

Parameters

\Drupal\search_api\IndexInterface $original: The previous version of the index.

1 call to Index::reactToServerSwitch()
Index::postSave in src/Entity/Index.php
Acts on a saved entity before the insert or update hook is invoked.

File

src/Entity/Index.php, line 1445

Class

Index
Defines the search index configuration entity.

Namespace

Drupal\search_api\Entity

Code

protected function reactToServerSwitch(IndexInterface $original) {

  // Asserts that the index was enabled before saving and will still be
  // enabled afterwards. Otherwise, this method should not be called.
  assert($this
    ->status() && $original
    ->status(), '::reactToServerSwitch should only be called when the index is enabled');
  if ($this
    ->getServerId() != $original
    ->getServerId()) {
    if ($original
      ->hasValidServer()) {
      $original
        ->getServerInstance()
        ->removeIndex($this);
    }
    if ($this
      ->hasValidServer()) {
      $this
        ->getServerInstance()
        ->addIndex($this);
    }

    // When the server changes we also need to trigger a reindex.
    $this
      ->reindex();
  }
  elseif ($this
    ->hasValidServer()) {

    // Tell the server the index configuration got updated.
    $this
      ->getServerInstance()
      ->updateIndex($this);
  }
}