/**
  * {@inheritdoc}
  */
 public function execute(AMQPMessage $msg)
 {
     /* @var $message Message */
     $message = $msg->getMessage();
     $serializer = $this->serializer;
     $content = $message->getValue('content');
     $xml = new \SimpleXMLElement($content);
     /** @var \Doctrine\Common\Persistence\ObjectRepository $repository */
     $repository = $this->objectManager->getRepository($this->atomEntryClass);
     try {
         /** @var \Bangpound\Bundle\PubsubBundle\CouchDocument\AtomFeed $feed */
         $feed = $serializer->deserialize($content, 'Bangpound\\Bundle\\PubsubBundle\\CouchDocument\\AtomFeed', 'xml');
         $source = new SourceType();
         $source->setAuthors($feed->getAuthors());
         $source->setBase($feed->getBase());
         $source->setCategories($feed->getCategories());
         $source->setContributors($feed->getContributors());
         $source->setGenerator($feed->getGenerator());
         $source->setIcon($feed->getIcon());
         $source->setLang($feed->getLang());
         $source->setLogo($feed->getLogo());
         $source->setLinks($feed->getLinks());
         $source->setRights($feed->getRights());
         $source->setSubtitle($feed->getSubtitle());
         $source->setTitle($feed->getTitle());
         $source->setUpdated($feed->getUpdated());
         $execute = FALSE;
         /** @var \Bangpound\Bundle\PubsubBundle\CouchDocument\AtomEntry $entry */
         foreach ($feed->getEntries() as $key => $entry) {
             $id = $entry->getId();
             $existing = $repository->findOneBy(['id' => $id]);
             if ($existing) {
                 $this->logger->info(sprintf('Duplicate notification sent for %s - %s', $id, $entry->getTitle()), ['existing' => $existing, 'new' => $entry]);
                 continue;
             }
             $execute = TRUE;
             if (!$entry->getSource()) {
                 $entry->setSource(clone $source);
             }
             $entry->setOriginalData($xml->entry[$key]->asXml(), 'text/xml');
             $this->objectManager->persist($entry);
         }
         if ($execute) {
             $this->objectManager->flush();
         }
         $this->objectManager->clear();
     } catch (RuntimeException $e) {
         throw $e;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function execute(AMQPMessage $msg)
 {
     $data = json_decode($msg->body, true, 512, $this->jsonOptions);
     $created_at = \DateTime::createFromFormat('D M j H:i:s P Y', $data['created_at']);
     $tweet_path = $data['user']['screen_name'] . '/status/' . $data['id_str'];
     $id = 'tag:twitter.com,' . $created_at->format('Y-m-d') . ':/' . $tweet_path;
     /** @var \Bangpound\Bundle\TwitterStreamingBundle\CouchDocument\AtomEntry $entry */
     $entry = new $this->atomEntryClass();
     $entry->setId($id);
     $entry->setOriginalData($msg->body, 'application/json');
     $title = new TextType();
     $title->setText($data['text']);
     $entry->setTitle($title);
     $content = new ContentType();
     $content->setContent($data['text']);
     $entry->setContent($content);
     $author = new PersonType();
     $author->setName($data['user']['name']);
     $author->setUri($data['user']['url']);
     $entry->addAuthor($author);
     $link = new LinkType();
     $link->setHref('https://twitter.com/intent/user?user_id=' . $data['user']['id_str']);
     $link->setRel('author');
     $entry->addLink($link);
     if (isset($data['entities']['hashtags'])) {
         foreach ($data['entities']['hashtags'] as $hashtag) {
             $category = new CategoryType();
             $category->setTerm($hashtag['text']);
             $entry->addCategory($category);
         }
     }
     if (isset($data['entities']['urls'])) {
         foreach ($data['entities']['urls'] as $url) {
             $link = new LinkType();
             $link->setHref($url['expanded_url']);
             if (substr_compare($url['expanded_url'], $url['display_url'], -strlen($url['display_url']), strlen($url['display_url'])) === 0) {
                 $link->setRel('shortlink');
             } else {
                 $link->setRel('nofollow');
             }
             $entry->addLink($link);
         }
     }
     if (isset($data['entities']['media'])) {
         foreach ($data['entities']['media'] as $media) {
             $link = new LinkType();
             $link->setHref($media['media_url']);
             $link->setRel('enclosure');
             if ($media['type'] == 'photo') {
                 $link->setType('image');
             }
             $link->setType('image');
             $entry->addLink($link);
         }
     }
     $link = new LinkType();
     $link->setHref('http://twitter.com/' . $tweet_path);
     $link->setRel('canonical');
     $entry->addLink($link);
     $link = new LinkType();
     $link->setHref(strtr($data['user']['profile_image_url'], ['_normal' => '']));
     $link->setRel('author thumbnail');
     $entry->addLink($link);
     $entry->setPublished($created_at);
     $source = new SourceType();
     $title = new TextType();
     $title->setText('Twitter');
     $source->setTitle($title);
     $entry->setSource($source);
     $entry->setLang($data['lang']);
     $entry->setExtra('filter_level', $data['filter_level']);
     $this->objectManager->persist($entry);
     return ConsumerInterface::MSG_ACK;
 }