From e9713f886d12737744f2e09efc384572395f345c Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Tue, 3 Mar 2015 01:24:09 +0300 Subject: [PATCH] Cron command for expired entities. --- .../Command/DropExpiredCopypastesCommand.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/Skobkin/Bundle/CopyPasteBundle/Command/DropExpiredCopypastesCommand.php 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.'); + } +}