/** * @param AccountUser $accountUser * @param ShoppingList $shoppingList */ public function setCurrent(AccountUser $accountUser, ShoppingList $shoppingList) { $em = $this->managerRegistry->getManagerForClass('OroB2BShoppingListBundle:ShoppingList'); /** @var ShoppingListRepository $shoppingListRepository */ $shoppingListRepository = $em->getRepository('OroB2BShoppingListBundle:ShoppingList'); $currentList = $shoppingListRepository->findCurrentForAccountUser($accountUser); if ($currentList instanceof ShoppingList && $currentList->getId() !== $shoppingList->getId()) { $currentList->setCurrent(false); } $shoppingList->setCurrent(true); $em->persist($shoppingList); $em->flush(); }