public function ContentEntityTaskManager::processEvent in Search API 8
Processes a datasource tracking event.
Parameters
\Drupal\search_api\Task\TaskEvent $event: The task event.
string $event_name: The name of the event.
File
- src/
Plugin/ search_api/ datasource/ ContentEntityTaskManager.php, line 72
Class
- ContentEntityTaskManager
- Provides a service for managing pending tracking tasks for datasources.
Namespace
Drupal\search_api\Plugin\search_api\datasourceCode
public function processEvent(TaskEvent $event, $event_name) {
$event
->stopPropagation();
// The complete event name prefix in front of the method name is 45
// characters long: "search_api.task.search_api.entity_datasource.".
$method = substr($event_name, 45);
$task = $event
->getTask();
$index = $task
->getIndex();
$data = $task
->getData();
if (!$index
->hasValidTracker()) {
$args['%index'] = $index
->label();
$message = new FormattableMarkup('Index %index does not have a valid tracker set.', $args);
$event
->setException(new SearchApiException($message));
return;
}
$datasource_id = $data['datasource'];
$reschedule = FALSE;
if ($index
->isValidDatasource($datasource_id)) {
/** @var \Drupal\search_api\Plugin\search_api\datasource\ContentEntity $datasource */
$datasource = $index
->getDatasource($datasource_id);
$raw_ids = $datasource
->getPartialItemIds($data['page'], $data['bundles'], $data['languages']);
if ($raw_ids !== NULL) {
$reschedule = TRUE;
if ($raw_ids) {
$index
->startBatchTracking();
$index
->{$method}($datasource_id, $raw_ids);
$index
->stopBatchTracking();
}
}
}
if ($reschedule) {
++$data['page'];
$this->taskManager
->addTask($task
->getType(), NULL, $index, $data);
}
}