public function Database::preDelete in Search API 8
Notifies the backend that the server is about to be deleted.
This should execute any necessary cleanup operations.
Note that you shouldn't call the server's save() method, or any methods that might do that, from inside of this method as the server isn't present in the database anymore at this point.
Overrides BackendPluginBase::preDelete
File
- modules/
search_api_db/ src/ Plugin/ search_api/ backend/ Database.php, line 614
Class
- Database
- Indexes and searches items using the database.
Namespace
Drupal\search_api_db\Plugin\search_api\backendCode
public function preDelete() {
$schema = $this->database
->schema();
$key_value_store = $this
->getKeyValueStore();
foreach ($key_value_store
->getAll() as $index_id => $db_info) {
if ($db_info['server'] != $this->server
->id()) {
continue;
}
// Delete the regular field tables.
foreach ($db_info['field_tables'] as $field) {
if ($schema
->tableExists($field['table'])) {
$schema
->dropTable($field['table']);
}
}
// Delete the denormalized field tables.
if ($schema
->tableExists($db_info['index_table'])) {
$schema
->dropTable($db_info['index_table']);
}
$key_value_store
->delete($index_id);
}
}