public function Server::removeIndex in Search API 8
Removes an index from this server.
This might mean that the index has been deleted, or reassigned to a different server. If you need to distinguish between these cases, inspect $index->getServerId().
If the index wasn't added to the server previously, the method call should be ignored.
Implementations of this method should also check whether $index->isReadOnly() and don't delete any indexed data if it is.
Parameters
\Drupal\search_api\IndexInterface|string $index: Either an object representing the index to remove, or its ID (if the index was completely deleted).
Throws
\Drupal\search_api\SearchApiException Thrown if an error occurred while removing the index.
Overrides BackendSpecificInterface::removeIndex
File
- src/
Entity/ Server.php, line 314
Class
- Server
- Defines the search server configuration entity.
Namespace
Drupal\search_api\EntityCode
public function removeIndex($index) {
$server_task_manager = \Drupal::getContainer()
->get('search_api.server_task_manager');
// When removing an index from a server, it doesn't make any sense anymore
// to delete items from it, or react to other changes.
$server_task_manager
->delete($this, $index);
try {
if ($server_task_manager
->execute($this)) {
$this
->getBackend()
->removeIndex($index);
return;
}
} catch (SearchApiException $e) {
$vars = [
'%server' => $this
->label(),
'%index' => is_object($index) ? $index
->label() : $index,
];
$this
->logException($e, '%type while removing index %index from server %server: @message in %function (line %line of %file).', $vars);
}
$task_manager = \Drupal::getContainer()
->get('search_api.task_manager');
$data = NULL;
if (!is_object($index)) {
$data = $index;
$index = NULL;
}
$task_manager
->addTask(__FUNCTION__, $this, $index, $data);
}