/** * @dataProvider getModifiedItems */ public function testModifiedItems(\DateTime $sourceDate, \DateTime $itemDate = null) { $this->source->setDatetimeModified($sourceDate); $item = new FeedItemBag(new FeedMock(1234), '123abc'); $item->setDatetimeModified($itemDate); $filter = new ModifiedItemFilter($this->sourceManager); $filter->filter($item); }
/** * @inheritdoc */ public function process(SourceInterface $source) { if ($source->isBlocked()) { throw new SourceProcessException('Source is blocked and should not be processed'); } foreach ($this->processors as $processor) { if ($processor->supports($source) && $processor->isLinked($source)) { $processor->process($source); } } }
/** * Checks whether the given source is fresh, meaning it doesn't need revisiting right now. * * @param SourceInterface $source * * @return bool */ protected function isFresh(SourceInterface $source) { $lastVisitDate = $source->getDatetimeLastVisited(); // no previous visit date, consider it stale if (null === $lastVisitDate) { return false; } $revisitDate = clone $lastVisitDate; $revisitDate->modify(sprintf('+%d hours', $source->getScraper()->getRevisitFrequency())); return $revisitDate > new \DateTime(); }
/** * @inheritdoc * * @param SourceInterface $object */ public function getObjectPayload($object) { return [$object->getId()]; }
/** * @param SourceInterface $source */ public function removeSource(SourceInterface $source) { $this->sources->removeElement($source); }
/** * Adds source to the internal cache. * * @param SourceInterface $source */ protected function cache(SourceInterface $source = null) { if (null === $source) { return; } // mark as visited $source->setDatetimeLastVisited(new \DateTime()); // cache by id if ($source->getId()) { $this->sources[$source->getId()] = $source; } $hash = null; if (null !== ($feed = $source->getFeed())) { $hash = $this->getFeedHash($feed); } elseif (null !== ($scraper = $source->getScraper())) { $hash = $this->getScraperHash($scraper); } // must have hash and original id if (!$hash || !$source->getOriginalId()) { return; } $this->originSources[$hash][$source->getOriginalId()] = $source; }
/** * Sets message for a specific key, while preserving other keys. * * @param SourceInterface $source * @param string $key * @param string $message * @param string $level */ protected function setMessage(SourceInterface $source, $key, $message, $level = LogLevel::ERROR) { $messages = $source->getMessages(); $messages[$key][$level] = $message; $source->setMessages($messages); }
/** * @inheritdoc * * @param Source $source */ public function process(SourceInterface $source) { $this->setData($source->getEpisode(), $source->getData()); $this->doctrine->getManager()->flush($source->getEpisode()); }
/** * Sets the raw data on the resulting Source. * * @param SourceInterface $source */ protected function setRawData(SourceInterface $source) { $source->setRawData(trim($this->rawData)); $this->rawData = null; }