container = $container; $this->em = $em; } protected function configure() { $this ->setName('app:CleanRegistration') ->setDescription('Nettoyage des inscriptions obsolètes') ->setHelp('Nettoyage des inscriptions obsolètes') ; } protected function execute(InputInterface $input, OutputInterface $output) { $this->output = $output; $this->filesystem = new Filesystem(); $this->rootlog = $this->container->get('kernel')->getLogDir().'/'; $this->writelnred(''); $this->writelnred('== app:CleanRegistration'); $this->writelnred('=========================================================================================================='); $now = new \DateTime('now'); $datas = $this->em ->createQueryBuilder() ->select('table') ->from('App\Entity\Registration', 'table') ->where('table.keyexpire<:now') ->setParameter('now', $now->format('Y-m-d H:i:s')) ->getQuery() ->getResult(); foreach ($datas as $data) { $this->writeln('Inscription supprimée = '.$data->getkeyexpire()->format('Y-m-d H:i:s').' >> '.$data->getUsername()); $this->em->remove($data); $this->em->flush(); } $this->writeln(''); return Command::SUCCESS; } private function writelnred($string) { $this->output->writeln(''.$string.''); $this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n"); if ($this->byexec) { $this->filesystem->appendToFile($this->rootlog.'exec.log', $string."\n"); } } private function writeln($string) { $this->output->writeln($string); $this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n"); if ($this->byexec) { $this->filesystem->appendToFile($this->rootlog.'exec.log', $string."\n"); } } }