Skip to content

Instantly share code, notes, and snippets.

@dwaligora
Created April 19, 2013 09:14
Show Gist options
  • Save dwaligora/5419134 to your computer and use it in GitHub Desktop.
Save dwaligora/5419134 to your computer and use it in GitHub Desktop.
<?php
namespace Clearcode\TransparenBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Clearcode\TransparenBundle\Entity\UserSeeker;
use Clearcode\TransparenBundle\Entity\Report;
class OpenedReportsRemindCommand extends ContainerAwareCommand
{
protected $container;
protected function configure()
{
$this->setName('transparen:cron:report:remind')
->setDescription('Remind users about opened reports.')
;
}
protected function getEntityManager()
{
return $this->container->get('doctrine')->getEntityManager();
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->container = $this->getContainer();
$user_seekers = $this->getEntityManager()->getRepository('ClearcodeTransparenBundle:UserSeeker')
->findAllUserSeekersByReportStatus(Report::STATUS_OPEN);
foreach ($user_seekers as $us) {
/** @var $us UserSeeker */
$message = \Swift_Message::newInstance()
->setSubject('You have open reports!')
->setFrom('reminder@transparencv.com')
->setTo($us->getUsername())
->setBody($this->container->get('templating')->render('ClearcodeTransparenBundle:Mail:remindReports.html.twig', array('user' => $us)), 'text/html');
$this->container->get('mailer')->send($message);
}
$this->kernelTerminate();
}
protected function kernelTerminate()
{
$transport = $this->container->get('mailer')->getTransport();
if (!$transport instanceof \Swift_Transport_SpoolTransport) {
return;
}
$spool = $transport->getSpool();
if (!$spool instanceof \Swift_MemorySpool) {
return;
}
$spool->flushQueue($this->container->get('swiftmailer.transport.real'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment