/** * {@inheritdoc} */ public function batchDelete($class, ProxyQueryInterface $queryProxy) { $queryProxy->select('DISTINCT ' . $queryProxy->getRootAlias()); try { $entityManager = $this->getEntityManager($class); $i = 0; foreach ($queryProxy->getQuery()->iterate() as $pos => $object) { $entityManager->remove($object[0]); if (++$i % 20 == 0) { $entityManager->flush(); $entityManager->clear(); } } $entityManager->flush(); $entityManager->clear(); } catch (\PDOException $e) { throw new ModelManagerException('', 0, $e); } catch (DBALException $e) { throw new ModelManagerException('', 0, $e); } }