private function FilesExtractor::queueItem in Search API attachments 8
Same name and namespace in other branches
- 9.0.x src/Plugin/search_api/processor/FilesExtractor.php \Drupal\search_api_attachments\Plugin\search_api\processor\FilesExtractor::queueItem()
Queue a failed extraction for later processing.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity the file is attached to.
\Drupal\file\Entity\File $file: A file object.
Return value
bool Success of queueing process.
1 call to FilesExtractor::queueItem()
- FilesExtractor::extractOrGetFromCache in src/
Plugin/ search_api/ processor/ FilesExtractor.php - Extract non text file data or get it from cache if available and cache it.
File
- src/
Plugin/ search_api/ processor/ FilesExtractor.php, line 336
Class
- FilesExtractor
- Provides file fields processor.
Namespace
Drupal\search_api_attachments\Plugin\search_api\processorCode
private function queueItem(EntityInterface $entity, File $file) {
if (\Drupal::lock()
->acquire(static::FALLBACK_QUEUE_LOCK)) {
$queued_file_collection = $this->keyValue
->get(static::FALLBACK_QUEUE_KV);
$queued_files = $queued_file_collection
->get($file
->id());
$queued_files[$entity
->getEntityTypeId()][$entity
->id()] = TRUE;
$queued_file_collection
->set($file
->id(), $queued_files);
\Drupal::lock()
->release(static::FALLBACK_QUEUE_LOCK);
// Add file to queue.
$queue = \Drupal::queue('search_api_attachments');
$item = new \stdClass();
$item->fid = $file
->id();
$item->entity_id = $entity
->id();
$item->entity_type = $entity
->getEntityTypeId();
$item->extract_attempts = 1;
$queue
->createItem($item);
$this->logger
->log(LogLevel::INFO, 'File added to the queue for text extraction @file_id for @entity_type @entity_id.', [
'@file_id' => $file
->id(),
'@entity_id' => $entity
->id(),
'@entity_type' => $entity
->getEntityTypeId(),
]);
return TRUE;
}
return FALSE;
}