2015-03-02 22:24:09 +00:00
|
|
|
<?php
|
|
|
|
|
2019-01-20 01:52:57 +00:00
|
|
|
namespace App\Command;
|
2015-03-02 22:24:09 +00:00
|
|
|
|
2019-01-20 01:52:57 +00:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use App\Entity\Copypaste;
|
|
|
|
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
|
|
|
|
*/
|
2019-01-20 01:52:57 +00:00
|
|
|
class DropExpiredPasteCommand extends Command
|
2015-03-02 22:24:09 +00:00
|
|
|
{
|
2019-01-20 01:52:57 +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...');
|
2016-12-19 00:23:45 +00:00
|
|
|
|
|
|
|
// @todo move to repository
|
2019-01-20 01:52:57 +00:00
|
|
|
$qb = $this->em->createQueryBuilder()
|
|
|
|
->delete(Copypaste::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());
|
2019-01-20 01:52:57 +00:00
|
|
|
$qb->getQuery()->execute();
|
2015-03-02 22:24:09 +00:00
|
|
|
|
|
|
|
$output->writeln('Done.');
|
|
|
|
}
|
|
|
|
}
|