Cron command for expired entities.

This commit is contained in:
Alexey Skobkin 2015-03-03 01:24:09 +03:00
parent c3c801ddec
commit e9713f886d
1 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,41 @@
<?php
namespace Skobkin\Bundle\CopyPasteBundle\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 Doctrine\ORM\EntityManager;
/**
* Deleting expired copypastes by Cron
*
* @author Alexey Skobkin
*/
class DropExpiredCopypastesCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('copypaste:cron:drop-expired')
->setDescription('Drop expired copypastes')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->write('Deleting expired entities...');
/* @var $em EntityManager */
$em = $this->getContainer()->get('doctrine')->getManager();
$queryBuilder = $em->createQueryBuilder()
->delete('SkobkinCopyPasteBundle:Copypaste c')
->where('c.dateExpire < :now')
->setParameter('now', new \DateTime());
$queryBuilder->getQuery()->execute();
$output->writeln('Done.');
}
}