/** * Remove given NGIs from a given project * @param \Project $project project from which ngis are to be removed * @param \Doctrine\Common\Collections\Collection $ngis ngis to be removed * @param \User $user user doing the removing (must be GOCDB admin) * @throws \Exception */ public function removeNgisFromProject(\Project $project, \Doctrine\Common\Collections\Collection $ngis, \User $user = null) { //Check the portal is not in read only mode, throws exception if it is $this->checkPortalIsNotReadOnlyOrUserIsAdmin($user); //Throws exception if user is not an administrator $this->checkUserIsAdmin($user); //Check the NGIs are all NGIs foreach ($ngis as $ngi) { if (!$ngi instanceof \NGI) { throw new \Exception("one or more objects being added to project is not of type NGI"); } } //Actually remove the NGIs $this->em->getConnection()->beginTransaction(); try { foreach ($ngis as $ngi) { $project->getNgis()->removeElement($ngi); $ngi->getProjects()->removeElement($project); $this->em->merge($ngi); } $this->em->merge($project); $this->em->flush(); $this->em->getConnection()->commit(); } catch (\Exception $e) { $this->em->getConnection()->rollback(); $this->em->close(); throw $e; } }