public function FeedExpireHandler::startBatchExpire in Feeds 8.3
Starts a batch for expiring items.
Parameters
\Drupal\feeds\FeedInterface $feed: The feed for which to expire items.
File
- src/
FeedExpireHandler.php, line 21
Class
- FeedExpireHandler
- Expires the items of a feed.
Namespace
Drupal\feedsCode
public function startBatchExpire(FeedInterface $feed) {
try {
$feed
->lock();
} catch (LockException $e) {
$this
->messenger()
->addWarning($this
->t('The feed became locked before the expiring could begin.'));
return;
}
$feed
->clearStates();
$ids = $this
->getExpiredIds($feed);
if (!$ids) {
$feed
->unlock();
return;
}
$batch = [
'title' => $this
->t('Expiring: %title', [
'%title' => $feed
->label(),
]),
'init_message' => $this
->t('Expiring: %title', [
'%title' => $feed
->label(),
]),
'progress_message' => $this
->t('Expiring: %title', [
'%title' => $feed
->label(),
]),
'error_message' => $this
->t('An error occurred while expiring %title.', [
'%title' => $feed
->label(),
]),
];
foreach ($ids as $id) {
$batch['operations'][] = [
[
$this,
'expireItem',
],
[
$feed,
$id,
],
];
}
$batch['operations'][] = [
[
$this,
'postExpire',
],
[
$feed,
],
];
$this
->batchSet($batch);
}