Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function handleIndexClient(IndexClientInterface $client, $persist = false)
 {
     $this->links = [];
     $this->errors = [];
     while ($urls = $client->getNextIndexUrls()) {
         foreach ($urls as $url) {
             $link = new Link();
             $link->setUrl($url);
             $this->links[] = $link;
             if ($persist) {
                 $this->persistLink($link);
             }
         }
     }
     return $this->links;
 }
 /**
  *  Persist/sabe link to db
  * 
  * @param \Nz\CrawlerBundle\Model\LinkInterface $link Link entity
  */
 protected function persistLink(Link $link)
 {
     $em = $this->getEntityManager();
     if (null !== $link->getId()) {
         $em->merge($link);
     } else {
         $em->persist($link);
     }
     try {
         $em->flush();
         return true;
     } catch (UniqueConstraintViolationException $ex) {
         $this->errors[] = array_pop($this->links);
         $link->setNote('duplicate_link_url', sprintf('Duplicate link url: %s', $link->getUrl()));
         return false;
     }
 }