public function CommandHelper::resetTrackerCommand in Search API 8
Resets the tracker for an index, optionally filtering on entity types.
Parameters
string[]|null $indexIds: (optional) An array of index IDs, or NULL if we should reset the trackers of all indexes.
string[] $entityTypes: (optional) An array of entity types for which to reset the tracker.
Return value
bool TRUE if any index was affected, FALSE otherwise.
Throws
\Drupal\search_api\SearchApiException Thrown if one of the affected indexes had an invalid tracker set, or some other internal error occurred.
File
- src/
Utility/ CommandHelper.php, line 359
Class
- CommandHelper
- Provides functionality to be used by CLI tools.
Namespace
Drupal\search_api\UtilityCode
public function resetTrackerCommand(array $indexIds = NULL, array $entityTypes = []) {
$indexes = $this
->loadIndexes($indexIds);
if (!$indexes) {
return FALSE;
}
foreach ($indexes as $index) {
if (!$index
->status()) {
continue;
}
if (!empty($entityTypes)) {
$datasources = $index
->getDatasources();
$reindexed_datasources = [];
foreach ($datasources as $datasource_id => $datasource) {
if (in_array($datasource
->getEntityTypeId(), $entityTypes)) {
$index
->getTrackerInstance()
->trackAllItemsUpdated($datasource_id);
$reindexed_datasources[] = $datasource
->label();
}
}
$description = 'This hook is deprecated in search_api:8.x-1.14 and is removed from search_api:2.0.0. Please use the "search_api.reindex_scheduled" event instead. See https://www.drupal.org/node/3059866';
$this->moduleHandler
->invokeAllDeprecated($description, 'search_api_index_reindex', [
$index,
FALSE,
]);
$event_name = SearchApiEvents::REINDEX_SCHEDULED;
$event = new ReindexScheduledEvent($index, FALSE);
$this->eventDispatcher
->dispatch($event_name, $event);
$arguments = [
'!index' => $index
->label(),
'!datasources' => implode(', ', $reindexed_datasources),
];
$this->logger
->info($this
->t('The following datasources of !index were successfully scheduled for reindexing: !datasources.', $arguments));
}
else {
$index
->reindex();
$this->logger
->info($this
->t('!index was successfully scheduled for reindexing.', [
'!index' => $index
->label(),
]));
}
}
return TRUE;
}