Skip to content
Snippets Groups Projects
Commit 85be2e9a authored by Scott Euser's avatar Scott Euser
Browse files

Issue #3402695 by scott_euser: OpenAI Embeddings causes error deleting media files

parent 5022610c
No related branches found
No related tags found
1 merge request!65Only attempt deletion if the site builder has configured a vector plugin
...@@ -28,32 +28,33 @@ function openai_embeddings_entity_delete(EntityInterface $entity) { ...@@ -28,32 +28,33 @@ function openai_embeddings_entity_delete(EntityInterface $entity) {
$plugin_id = \Drupal::configFactory() $plugin_id = \Drupal::configFactory()
->get('openai_embeddings.settings') ->get('openai_embeddings.settings')
->get('vector_client_plugin'); ->get('vector_client_plugin');
$vector_client = \Drupal::service('plugin.manager.vector_client') if ($plugin_id) {
->createInstance($plugin_id); $vector_client = \Drupal::service('plugin.manager.vector_client')->createInstance($plugin_id);
try { try {
$records = \Drupal::database()->query('SELECT entity_id, entity_type, field_name FROM {openai_embeddings} WHERE entity_id = :entity_id AND entity_type = :entity_type', $records = \Drupal::database()->query('SELECT entity_id, entity_type, field_name FROM {openai_embeddings} WHERE entity_id = :entity_id AND entity_type = :entity_type',
[
':entity_id' => $entity->id(),
':entity_type' => $entity->getEntityTypeId(),
]
);
foreach ($records as $record) {
$vector_client->delete(
[],
FALSE,
$record->entity_type . ':' . $record->field_name,
[ [
'entity_id' => $entity->id(), ':entity_id' => $entity->id(),
'entity_type' => $entity->getEntityTypeId(), ':entity_type' => $entity->getEntityTypeId(),
'bundle' => $entity->bundle(),
] ]
); );
foreach ($records as $record) {
$vector_client->delete(
[],
FALSE,
$record->entity_type . ':' . $record->field_name,
[
'entity_id' => $entity->id(),
'entity_type' => $entity->getEntityTypeId(),
'bundle' => $entity->bundle(),
]
);
}
}
catch (\Exception $e) {
\Drupal::logger('openai_embeddings')->error('Error trying to delete record(s) in the vector database.');
} }
}
catch (\Exception $e) {
\Drupal::logger('openai_embeddings')->error('Error trying to delete record(s) in the vector database.');
} }
\Drupal::database()->delete('openai_embeddings') \Drupal::database()->delete('openai_embeddings')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment