public function SearchApiDbService::deleteItems in Search API Database Search 7
Deletes indexed items from this server.
Might be either used to delete some items (given by their ids) from a specified index, or all items from that index, or all items from all indexes on this server.
Parameters
$ids: Either an array containing the ids of the items that should be deleted, or 'all' if all items should be deleted. Other formats might be recognized by implementing classes, but these are not standardized.
SearchApiIndex $index: The index from which items should be deleted, or NULL if all indexes on this server should be cleared (then, $ids has to be 'all').
Throws
SearchApiException If an error occurred while trying to delete the items.
Overrides SearchApiServiceInterface::deleteItems
1 call to SearchApiDbService::deleteItems()
File
- ./
service.inc, line 1139 - Contains SearchApiDbService.
Class
- SearchApiDbService
- Indexes and searches items using the database.
Code
public function deleteItems($ids = 'all', SearchApiIndex $index = NULL) {
try {
if (!$index) {
if (empty($this->options['indexes'])) {
return;
}
$truncated = array();
foreach ($this->options['indexes'] as $fields) {
foreach ($fields as $field) {
if (isset($field['table']) && !isset($truncated[$field['table']])) {
$this->connection
->truncate($field['table'])
->execute();
$truncated[$field['table']] = TRUE;
}
}
}
return;
}
if (empty($this->options['indexes'][$index->machine_name])) {
return;
}
foreach ($this->options['indexes'][$index->machine_name] as $field) {
if (is_array($ids)) {
$this->connection
->delete($field['table'])
->condition('item_id', $ids, 'IN')
->execute();
}
else {
$this->connection
->truncate($field['table'])
->execute();
}
}
} catch (Exception $e) {
throw new SearchApiException($e
->getMessage());
}
}