public function FeedClearHandler::clear in Feeds 8.3
Deletes all items from a feed.
Parameters
\Drupal\feeds\FeedInterface $feed: The feed entity from which to delete all items.
array $context: Status of the batch.
File
- src/
FeedClearHandler.php, line 42
Class
- FeedClearHandler
- Deletes the items of a feed.
Namespace
Drupal\feedsCode
public function clear(FeedInterface $feed, array &$context) {
try {
$this
->dispatchEvent(FeedsEvents::INIT_CLEAR, new InitEvent($feed));
$this
->dispatchEvent(FeedsEvents::CLEAR, new ClearEvent($feed));
} catch (\Exception $exception) {
// Do nothing yet.
}
// Clean up.
$context['finished'] = $feed
->progressClearing();
if (isset($exception)) {
$context['finished'] = StateInterface::BATCH_COMPLETE;
}
if ($context['finished'] === StateInterface::BATCH_COMPLETE) {
$feed
->finishClear();
$feed
->save();
$feed
->unlock();
}
else {
$feed
->saveStates();
}
if (isset($exception)) {
throw $exception;
}
}