class FeedImportHandler in Feeds 8.3
Runs the actual import on a feed.
Hierarchy
- class \Drupal\feeds\FeedHandlerBase implements EntityHandlerInterface uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait, EventDispatcherTrait
- class \Drupal\feeds\FeedImportHandler
Expanded class hierarchy of FeedImportHandler
1 file declares its use of FeedImportHandler
- FeedImportHandlerTest.php in tests/
src/ Unit/ FeedImportHandlerTest.php
File
- src/
FeedImportHandler.php, line 12
Namespace
Drupal\feedsView source
class FeedImportHandler extends FeedHandlerBase {
/**
* Imports the whole feed at once.
*
* @param \Drupal\feeds\FeedInterface $feed
* The feed to import for.
*
* @throws \Exception
* In case of an error.
*/
public function import(FeedInterface $feed) {
$this
->getExecutable(FeedsExecutable::class)
->processItem($feed, FeedsExecutable::BEGIN);
}
/**
* Starts importing a feed via the batch API.
*
* @param \Drupal\feeds\FeedInterface $feed
* The feed to import.
*
* @throws \Drupal\feeds\Exception\LockException
* Thrown if a feed is locked.
*/
public function startBatchImport(FeedInterface $feed) {
$this
->getExecutable(FeedsBatchExecutable::class)
->processItem($feed, FeedsBatchExecutable::BEGIN);
}
/**
* Starts importing a feed via cron.
*
* @param \Drupal\feeds\FeedInterface $feed
* The feed to queue.
*
* @throws \Drupal\feeds\Exception\LockException
* Thrown if a feed is locked.
*/
public function startCronImport(FeedInterface $feed) {
if ($feed
->isLocked()) {
$args = [
'@id' => $feed
->bundle(),
'@fid' => $feed
->id(),
];
throw new LockException($this
->t('The feed @id / @fid is locked.', $args));
}
$this
->getExecutable(FeedsQueueExecutable::class)
->processItem($feed, FeedsQueueExecutable::BEGIN);
// Add timestamp to avoid queueing item more than once.
$feed
->setQueuedTime($this
->getRequestTime());
$feed
->save();
}
/**
* Handles a push import.
*
* @param \Drupal\feeds\FeedInterface $feed
* The feed receiving the push.
* @param string $payload
* The feed contents.
* @param \Drupal\Core\File\FileSystemInterface $file_system
* (optional) The file system service.
*/
public function pushImport(FeedInterface $feed, $payload, FileSystemInterface $file_system = NULL) {
$feed
->lock();
$fetcher_result = new RawFetcherResult($payload, $file_system);
$this
->getExecutable(FeedsQueueExecutable::class)
->processItem($feed, FeedsQueueExecutable::PARSE, [
'fetcher_result' => $fetcher_result,
]);
}
/**
* Returns the timestamp for the current request.
*
* @return int
* A Unix timestamp.
*/
protected function getRequestTime() {
return \Drupal::time()
->getRequestTime();
}
/**
* Returns the executable.
*
* @param string $class
* The class to load.
*
* @return \Drupal\feeds\FeedsExecutableInterface
* A feeds executable.
*/
protected function getExecutable($class) {
return \Drupal::service('class_resolver')
->getInstanceFromDefinition($class);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EventDispatcherTrait:: |
private | property | The event dispatcher service. | |
EventDispatcherTrait:: |
protected | function | Dispatches an event. | |
EventDispatcherTrait:: |
protected | function | Returns the event dispatcher service. | |
EventDispatcherTrait:: |
public | function | Sets the event dispatcher service to use. | |
FeedHandlerBase:: |
protected | function | Adds a new batch. | |
FeedHandlerBase:: |
public static | function |
Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface:: |
|
FeedHandlerBase:: |
public | function | Constructs a new FeedHandlerBase object. | |
FeedImportHandler:: |
protected | function | Returns the executable. | |
FeedImportHandler:: |
protected | function | Returns the timestamp for the current request. | |
FeedImportHandler:: |
public | function | Imports the whole feed at once. | |
FeedImportHandler:: |
public | function | Handles a push import. | |
FeedImportHandler:: |
public | function | Starts importing a feed via the batch API. | |
FeedImportHandler:: |
public | function | Starts importing a feed via cron. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |