示例#1
0
 /**
  * {@inheritdoc}
  */
 public function handleEntityClient(EntityClientInterface $client, $persist = false)
 {
     $link = $client->getLink();
     $link->setProcessed(true);
     $this->links[] = $link;
     try {
         $entity = $client->crawlToEntity($this->getNewEntity());
         if (!$entity) {
             $link->setHasError(true);
             $link->setNote('error_crawling_entity', sprintf('entity with error: %s', $entity->getTitle()));
         } else {
             $link->setHasError(false);
             $link->setNote('crawled_entity', sprintf('crawled entity: %s', $entity->getTitle()));
         }
         if ($persist) {
             $this->persistEntity($entity);
             $link->setNote('created_entity', sprintf('created entity: %d', $entity->getId()));
             $this->persistLink($link);
             $client->afterEntityPersist($entity);
         }
         /* $client->setLink($link); */
         return $entity;
     } catch (UniqueConstraintViolationException $ex) {
         $link->setNote('duplicate_entity_ex', $ex->getMessage());
     } catch (\Doctrine\DBAL\Exception\NotNullConstraintViolationException $ex) {
         $link->setNote('not_null_exception', 'Entity with required field empty');
     } catch (EntityClientException $ex) {
         $link->setNote('entity_client_exeption', $ex->getMessage());
     } catch (\Buzz\Exception\RequestException $ex) {
         $link->setNote('error_requesting_remote', $ex->getMessage());
     } catch (\Exception $ex) {
         $link->setNote('exception', $ex->getMessage());
         $link->setSkip(true);
     }
     $link->setHasError(true);
     if ($persist) {
         $this->persistLink($link);
     }
     return false;
 }
示例#2
0
 /**
  * Add entity client to pool
  * 
  * @param \Nz\CrawlerBundle\Client\EntityClientInterface $client Entity Client class
  */
 public function addEntityClient(EntityClientInterface $client)
 {
     $this->entity_clients[$client->getClientHost()] = $client;
 }