public function SearchApiAlgoliaBackend::deleteItems in Search API Algolia 3.0.x
Same name and namespace in other branches
- 8 src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php \Drupal\search_api_algolia\Plugin\search_api\backend\SearchApiAlgoliaBackend::deleteItems()
- 2.0.x src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php \Drupal\search_api_algolia\Plugin\search_api\backend\SearchApiAlgoliaBackend::deleteItems()
File
- src/
Plugin/ search_api/ backend/ SearchApiAlgoliaBackend.php, line 390
Class
- SearchApiAlgoliaBackend
- Class SearchApiAlgoliaBackend.
Namespace
Drupal\search_api_algolia\Plugin\search_api\backendCode
public function deleteItems(IndexInterface $index, array $ids) {
// When using custom field for object id, we handle the deletion of
// objects in separate code.
if ($index
->getOption('object_id_field')) {
return;
}
// Deleting all items included in the $ids array.
foreach ($this
->getLanguages($index) as $key) {
// If algolia_index_batch_deletion enabled delete in batches
// with drush command.
if ($index
->getOption('algolia_index_batch_deletion')) {
$this->helper
->scheduleForDeletion($index, $ids, $key);
continue;
}
try {
// Connect to the Algolia index for specific language.
$this
->connect($index, '', $key);
} catch (\Exception $e) {
$this
->getLogger()
->error('Failed to connect to Algolia index while deleting indexed items, Error: @message', [
'@message' => $e
->getMessage(),
]);
continue;
}
$response = $this
->getAlgoliaIndex()
->deleteObjects($ids);
if ($this
->isDebugActive()) {
$this
->getLogger()
->notice('Deletion requested for IDs: @ids on Algolia for Index: @index, Response: @response.', [
'@response' => json_encode($response),
'@index' => $this
->getAlgoliaIndex()
->getIndexName(),
'@ids' => implode(',', $ids),
]);
}
// Wait for the deletion to be completed.
if ($this
->shouldWaitForDeleteToFinish()) {
$response
->wait();
}
}
}