public function flush() { $events = $this->getEvents(); try { $this->writeCsv($events); } catch (\Exception $e) { exit; } foreach ($events as $event) { $this->em->remove($event); } $this->em->flush(); }