diff --git a/src/Skobkin/Bundle/CopyPasteBundle/Command/DropExpiredCopypastesCommand.php b/src/Skobkin/Bundle/CopyPasteBundle/Command/DropExpiredCopypastesCommand.php new file mode 100644 index 0000000..f165b6a --- /dev/null +++ b/src/Skobkin/Bundle/CopyPasteBundle/Command/DropExpiredCopypastesCommand.php @@ -0,0 +1,41 @@ +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.'); + } +}