Skip to content
Snippets Groups Projects
Commit 58e47882 authored by Youri van Koppen's avatar Youri van Koppen
Browse files

Added clearQueueTasks() to Feed and FeedImportHandler and call that when calling Feed::unlock().

parent d4e64a5f
No related branches found
No related tags found
No related merge requests found
......@@ -303,6 +303,15 @@ class Feed extends ContentEntityBase implements FeedInterface {
->startBatchExpire($this);
}
/**
* {@inheritdoc}
*/
public function clearQueueTasks(): void {
$this->entityTypeManager()
->getHandler('feeds_feed', 'feed_import')
->clearQueueTasks($this);
}
/**
* {@inheritdoc}
*/
......@@ -330,10 +339,6 @@ class Feed extends ContentEntityBase implements FeedInterface {
// Allow other modules to react upon finishing importing.
$this->eventDispatcher()->dispatch(new ImportFinishedEvent($this), FeedsEvents::IMPORT_FINISHED);
// Cleanup.
$this->clearStates();
$this->setQueuedTime(0);
$this->set('imported', $time);
$interval = $this->getType()->getImportPeriod();
......@@ -495,6 +500,11 @@ class Feed extends ContentEntityBase implements FeedInterface {
public function unlock() {
\Drupal::service('lock.persistent')->release("feeds_feed_{$this->id()}");
Cache::invalidateTags(['feeds_feed_locked']);
// Clean up stuff.
$this->clearStates();
$this->setQueuedTime(0);
$this->clearQueueTasks();
}
/**
......
......@@ -82,6 +82,21 @@ class FeedImportHandler extends FeedHandlerBase {
]);
}
/**
* Removes all queue tasks for the given feed.
*
* @param \Drupal\feeds\FeedInterface $feed
* The feed for which to remove queue tasks.
*/
public function clearQueueTasks(FeedInterface $feed): void {
if (!$this->database->schema()->tableExists('queue')) {
return;
}
$this->database->delete('queue')
->condition('data', 'a:3:{i:0;i:' . $feed->id() . '%', 'LIKE')
->execute();
}
/**
* Returns the timestamp for the current request.
*
......
......@@ -165,6 +165,11 @@ interface FeedInterface extends ContentEntityInterface, EntityChangedInterface,
*/
public function startBatchExpire();
/**
* Removes all queue tasks for the current feed.
*/
public function clearQueueTasks(): void;
/**
* Dispatches an entity event.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment