/**
  * Command execution
  *
  * @throws \InvalidArgumentException
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $type = $input->getOption('type');
     /* @var \Hatimeria\NewsletterBundle\Mailing\MailingManagerInterface $manager */
     /* @var \Doctrine\ORM\EntityManager $em */
     $manager = $this->getContainer()->get('hatimeria_newsletter.manager');
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     foreach ($manager->getServices() as $service) {
         /* @var \Hatimeria\NewsletterBundle\Mailing\MailingInterface $service */
         if (!$service->supportsSchedule($type)) {
             continue;
         }
         foreach ($service->getRecipients($type) as $recipient) {
             if (is_object($recipient) && $recipient instanceof MailingRecipientInterface) {
                 /* @var \Hatimeria\NewsletterBundle\Recipient\MailingRecipientInterface $recipient */
                 $email = $recipient->getEmail();
             } elseif (is_string($recipient)) {
                 $email = $recipient;
             } else {
                 $msg = sprintf('Mailing services have to return recipients as string which is email address
                 or objects implementing MailingRecipientInterface (service: %s)', get_class($service));
                 throw new \InvalidArgumentException($msg);
             }
             $body = $service->getBody($recipient, $type);
             if (false === $body) {
                 continue;
             }
             if ($this->getContainer()->hasParameter("base_url")) {
                 $domain = $this->getContainer()->getParameter("base_url");
             } else {
                 $domain = '';
             }
             $body = UrlUtils::domenizeImages($body, $domain);
             $queue = new Queue();
             $queue->setEmail($email);
             $queue->setBody($body);
             $queue->setSubject($service->getSubject($recipient));
             $em->persist($queue);
         }
         $em->flush();
         $service->finalize();
     }
 }
 /**
  * Creates message from Queue object
  *
  * @param \Hatimeria\NewsletterBundle\Entity\Queue $queue
  * 
  * @return \Swift_Message
  */
 protected function createMessageFromQueue(Queue $queue)
 {
     $message = \Swift_Message::newInstance()->setSubject($queue->getSubject())->setFrom($this->sender)->setTo($queue->getEmail())->setBody($queue->getBody(), 'text/html');
     return $message;
 }