You are here

protected function Index::reactToProcessorChanges in Search API 8

Reacts to changes in processor configuration.

Parameters

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

1 call to Index::reactToProcessorChanges()
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 1530

Class

Index
Defines the search index configuration entity.

Namespace

Drupal\search_api\Entity

Code

protected function reactToProcessorChanges(IndexInterface $original) {
  $old_processors = $original
    ->getProcessors();
  $new_processors = $this
    ->getProcessors();
  $requires_reindex = FALSE;

  // Loop over all new settings and check if the processors were already set
  // in the original entity.
  foreach ($new_processors as $key => $processor) {

    // The processor is new, because it wasn't configured in the original
    // entity.
    if (!isset($old_processors[$key])) {
      if ($processor
        ->requiresReindexing(NULL, $processor
        ->getConfiguration())) {
        $requires_reindex = TRUE;
        break;
      }
    }
  }
  if (!$requires_reindex) {

    // Loop over all original settings and check if one of them has been
    // removed or changed.
    foreach ($old_processors as $key => $old_processor) {
      $new_processor = $new_processors[$key] ?? NULL;
      $old_config = $old_processor
        ->getConfiguration();
      $new_config = $new_processor ? $new_processor
        ->getConfiguration() : NULL;
      if (!$new_processor || $old_config != $new_config) {
        if ($old_processor
          ->requiresReindexing($old_config, $new_config)) {
          $requires_reindex = TRUE;
          break;
        }
      }
    }
  }
  if ($requires_reindex) {
    $this
      ->reindex();
  }
}