Skip to content
Snippets Groups Projects

Issue #3405424 by naveenvalecha: Delete the items only when cleared the index instead of resetting the database

Merged Issue #3405424 by naveenvalecha: Delete the items only when cleared the index instead of resetting the database
1 unresolved thread
1 unresolved thread
2 files
+ 35
9
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -335,13 +335,7 @@ class Recombee extends BackendPluginBase implements PluginFormInterface {
$site_id,
str_replace('/', '-', explode(':', $item_id)[1]),
]));
// Call API to delete the item.
try {
$this->send(new DeleteItem($item_id));
}
catch (\Exception $e) {
$this->getLogger()->warning($e->getMessage());
}
$this->deleteItemFromRecombee($item_id);
}
}
@@ -352,7 +346,39 @@ class Recombee extends BackendPluginBase implements PluginFormInterface {
$settings = $index->getThirdPartySettings('search_api_recombee');
// Call API to clear the whole database if allowed.
if (!empty($settings['schema'])) {
$this->send(new ResetDatabase());
$recombee_config = \Drupal::config('recombee.settings');
Please register or sign in to reply
$site_id = $recombee_config->get('site_id');
$datasources = $index->getDatasources();
foreach ($datasources as $datasource_id => $datasource) {
if ($datasource_id == 'entity:node') {
$entity_type = explode(':', $datasource_id)[1];
$item_ids = $datasource->getItemIds();
foreach ($item_ids as $item_id) {
// Convert Search API item ID to Recombee item ID.
$entity_item_id = $site_id . '-' . $entity_type . '-' . explode(':', $item_id)[0];
$this->deleteItemFromRecombee($entity_item_id);
}
}
}
}
}
/**
* Sends a request to delete an item in Recombee.
*
* @param string $item_id
* The item id to delete.
*
* @throws \Exception
* If the Recombee API error occurs.
*/
protected function deleteItemFromRecombee($item_id) {
// Call API to delete the item.
try {
$this->send(new DeleteItem($item_id));
}
catch (\Exception $e) {
$this->getLogger()->warning($e->getMessage());
}
}
Loading