コード例 #1
0
 /**
  * @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);
 }
コード例 #2
0
 /**
  * @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);
         }
     }
 }
コード例 #3
0
 /**
  * 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();
 }
コード例 #4
0
 /**
  * @inheritdoc
  *
  * @param SourceInterface $object
  */
 public function getObjectPayload($object)
 {
     return [$object->getId()];
 }
コード例 #5
0
ファイル: Scraper.php プロジェクト: treehouselabs/io-bundle
 /**
  * @param SourceInterface $source
  */
 public function removeSource(SourceInterface $source)
 {
     $this->sources->removeElement($source);
 }
コード例 #6
0
 /**
  * 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;
 }
コード例 #7
0
 /**
  * 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);
 }
コード例 #8
0
 /**
  * @inheritdoc
  *
  * @param Source $source
  */
 public function process(SourceInterface $source)
 {
     $this->setData($source->getEpisode(), $source->getData());
     $this->doctrine->getManager()->flush($source->getEpisode());
 }
コード例 #9
0
 /**
  * Sets the raw data on the resulting Source.
  *
  * @param SourceInterface $source
  */
 protected function setRawData(SourceInterface $source)
 {
     $source->setRawData(trim($this->rawData));
     $this->rawData = null;
 }