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(); // @todo move to repository $queryBuilder = $em->createQueryBuilder() ->delete('SkobkinCopyPasteBundle:Copypaste c') ->where('c.dateExpire < :now') ->andWhere('c.dateExpire IS NOT NULL') ->setParameter('now', new \DateTime()); $queryBuilder->getQuery()->execute(); $output->writeln('Done.'); } }