diff --git a/lib/Doctrine/Repositories/OrderRepository.php b/lib/Doctrine/Repositories/OrderRepository.php index a4446ad9ad..df57a3f8b0 100644 --- a/lib/Doctrine/Repositories/OrderRepository.php +++ b/lib/Doctrine/Repositories/OrderRepository.php @@ -12,6 +12,18 @@ use Doctrine\ORM\EntityRepository; */ class OrderRepository extends EntityRepository { + /** + * Returns the orders initiated by a given user. + * + * @param \User_Adapter $user + * + * @return array + */ + public function findByUser(\User_Adapter $user) + { + return $this->findBy(array('usrId' => $user->get_id())); + } + /** * Returns an array of all the orders, starting at $offsetStart, limited to $perPage * diff --git a/lib/classes/User/Adapter.php b/lib/classes/User/Adapter.php index 0509f8a1a5..a874a0bfff 100644 --- a/lib/classes/User/Adapter.php +++ b/lib/classes/User/Adapter.php @@ -768,6 +768,11 @@ class User_Adapter implements User_Interface, cache_cacheableInterface $this->app['EM']->remove($export); } + $repo = $this->app['EM']->getRepository('Entities\Order'); + foreach ($repo->findByUser($this) as $order) { + $this->app['EM']->remove($order); + } + $this->app['EM']->flush(); $sql = 'UPDATE usr SET usr_login = :usr_login , usr_mail = null @@ -796,11 +801,6 @@ class User_Adapter implements User_Interface, cache_cacheableInterface $stmt->execute(array(':usr_id' => $this->get_id())); $stmt->closeCursor(); - $sql = 'DELETE FROM `order` WHERE usr_id = :usr_id'; - $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); - $stmt->execute(array(':usr_id' => $this->get_id())); - $stmt->closeCursor(); - $sql = 'DELETE FROM sselnew WHERE usr_id = :usr_id'; $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(array(':usr_id' => $this->get_id()));