You are here

protected function Index::reactToTrackerSwitch in Search API 8

Checks whether the index switched tracker plugin 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::reactToTrackerSwitch()
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 1507

Class

Index
Defines the search index configuration entity.

Namespace

Drupal\search_api\Entity

Code

protected function reactToTrackerSwitch(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(), '::reactToTrackerSwitch should only be called when the index is enabled');
  if ($this
    ->getTrackerId() != $original
    ->getTrackerId()) {
    $index_task_manager = \Drupal::getContainer()
      ->get('search_api.index_task_manager');
    if ($original
      ->hasValidTracker()) {
      $index_task_manager
        ->stopTracking($original);
    }
    if ($this
      ->hasValidTracker()) {
      $index_task_manager
        ->startTracking($this);
    }
  }
}