Exemplo n.º 1
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();
 }
 /**
  * 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;
 }