Hi,
The expire checkox does not work. Below is the piece of code which delivers the id's which need to be expired.

   return $this->queryFactory->get($this->entityType())
      ->condition('feeds_item.target_id', $feed->id())
      // ->condition('feeds_item.imported', REQUEST_TIME -1, '<')
      ->execute();
  }

So actually there is no condition hence all node get deleted for the selected feed.
Also there should be a created field in schema and nodes should be expired based on created date of node not imported or we could add an option for both.

Thanks

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

saurabh.tripathi.cs created an issue. See original summary.

MadSciencePro’s picture

I've covered all the emotions this morning. I got my calendar RSS feed importing and I was elated. Then, I tried to expire after a year and discovered everything just gets deleted. Glad I found this post. Moment of panic over.

handkerchief’s picture

Are there any news about this? According to my tests it still doesn't work.

MegaChriz’s picture

Title: Expire functionality does not works » Expire feature deletes all imported items

I think that \Drupal\feeds\Feeds\Processor\NodeProcessor should override \Drupal\feeds\Feeds\Processor\EntityProcessorBase::getExpiredIds() and a condition on created date. This is similar to how this is solved in the D7 version of Feeds, where the node processor overrides the method expiryQuery().

Or perhaps the \Drupal\feeds\Feeds\Processor\EntityProcessorBase class should check if the target entity type has a property called "created" and only provide the "expire" option if it has? In this case the condition on created date could be added to this class instead of the class for the node processor.

Patches are welcome. I have no plans to work on this soon myself.

handkerchief’s picture

Status: Active » Needs review

I have changed this code and it works for me:

     return $this->queryFactory->get($this->entityType())
       ->condition('feeds_item.target_id', $feed->id())
-      // ->condition('feeds_item.imported', REQUEST_TIME -1, '<')
+      ->condition('feeds_item.imported', REQUEST_TIME - $time, '<')
       ->execute();
   }
cgmonroe’s picture

I needed this to work so I dug into it. I don't think that we need to do all the overrides and checks mentioned above. In the D8 version, there is an imported field on any entity imported. The delete after X time has passed is based on this.

FYI - I am using this with my own Non-node entity type processor with no problems.

One thing I noticed in creating the patch. The REQUEST_TIME variable has been deprecated. So I converted the REQUEST_TIME references in the Class to use:

\Drupal::service('datetime.time')->getRequestTime();

Debated on turning this into a plugin argument for injection purposes, but that seemed like overkill for this service.

Attached is the patch.

MegaChriz’s picture

Thanks for working on this, @cgmonroe. Perhaps with this, the automated tests could be updated. There are several placeholders in the tests for the expire feature:

  • Drupal\Tests\feeds\Kernel\Entity\FeedTest::testStartBatchExpire()
  • Drupal\Tests\feeds\Kernel\Feeds\Processor::testGetExpiredIds()
  • Drupal\Tests\feeds\Kernel\Feeds\Processor::testExpireItem()
  • Drupal\Tests\feeds\Unit\FeedExpireHandlerTest
MegaChriz’s picture

Removed markTestIncomplete() calls for expire related tests. Some tests may fail.

Status: Needs review » Needs work
MegaChriz’s picture

Fixed some errors in the test 'FeedExpireHandlerTest': The handler wasn't initiated in setUp() and the call to expireItem() missed the second parameter.

Status: Needs review » Needs work
MegaChriz’s picture

Worked on FeedExpireHandlerTest. Added missing docs.

MegaChriz’s picture

  • MegaChriz committed 79b4d37 on 8.x-3.x
    Issue #2803057 by MegaChriz, cgmonroe: Fixed expire feature deletes all...
MegaChriz’s picture

Status: Needs review » Fixed

Committed #13.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.