copypaste2/src/Command/DropExpiredPasteCommand.php

51 lines
1.2 KiB
PHP
Raw Normal View History

2015-03-02 22:24:09 +00:00
<?php
namespace App\Command;
2015-03-02 22:24:09 +00:00
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Paste;
use Symfony\Component\Console\Command\Command;
2015-03-02 22:24:09 +00:00
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Deleting expired copypastes by Cron
*
* @author Alexey Skobkin
*/
class DropExpiredPasteCommand extends Command
2015-03-02 22:24:09 +00:00
{
/** @var EntityManagerInterface */
private $em;
public function __construct(EntityManagerInterface $em)
{
parent::__construct();
$this->em = $em;
}
2015-03-02 22:24:09 +00:00
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...');
// @todo move to repository
$qb = $this->em->createQueryBuilder()
->delete(Paste::class, 'c')
2015-03-02 22:24:09 +00:00
->where('c.dateExpire < :now')
2015-03-16 01:06:24 +00:00
->andWhere('c.dateExpire IS NOT NULL')
2015-03-02 22:24:09 +00:00
->setParameter('now', new \DateTime());
$qb->getQuery()->execute();
2015-03-02 22:24:09 +00:00
$output->writeln('Done.');
}
}