Skip to content

Commit

Permalink
ContentLoader: Allow items_lifetime=0
Browse files Browse the repository at this point in the history
We documented it as supported in 41215a0
but it would in fact skip adding anything with “item […] older than 0 days”.
Let’s make it actually work.
  • Loading branch information
jtojnar committed Mar 29, 2023
1 parent b6a9d69 commit 82fb822
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/helpers/ContentLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,12 @@ public function fetch($source): void {
);

// current date
$minDate = new \DateTime();
$minDate->sub(new \DateInterval('P' . $this->configuration->itemsLifetime . 'D'));
$this->logger->debug('minimum date: ' . $minDate->format('Y-m-d H:i:s'));
$minDate = null;
if ($this->configuration->itemsLifetime !== 0) {
$minDate = new \DateTime();
$minDate->sub(new \DateInterval('P' . $this->configuration->itemsLifetime . 'D'));
$this->logger->debug('minimum date: ' . $minDate->format('Y-m-d H:i:s'));
}

// insert new items in database
$this->logger->debug('start item fetching');
Expand Down Expand Up @@ -180,7 +183,7 @@ public function fetch($source): void {
if ($itemDate === null) {
$itemDate = new \DateTimeImmutable();
}
if ($itemDate < $minDate) {
if ($minDate !== null && $itemDate < $minDate) {
$this->logger->debug('item "' . $titlePlainText . '" (' . $itemDate->format(\DateTime::ATOM) . ') older than ' . $this->configuration->itemsLifetime . ' days');
continue;
}
Expand Down

0 comments on commit 82fb822

Please # to comment.