/** * Check that if if the selected scope for this SE is EGI, the parent site * is also EGI * @param Site $site The SE's parent site * @param Scope $scope The SE's new scope * @return null */ private function scopeCheck(\Site $site, \Scope $scope) { // If the scope isn't EGI then don't raise an error if ($scope->getName() != 'EGI') { return; } if ($site->getScopes()->first()->getName() != "EGI") { throw new \Exception("For this service to be EGI scoped, {$site} must also be EGI scoped."); } }
/** * Edit an existing scope * @param \Scope $scope the scope to be changed * @param array $newValues array containing the name of the scope * @param \User $user user making the changes * @return \Scope $altered scope * @throws \Exception */ public function editScope(\Scope $scope, $newValues, \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); //Validate the values as per the GOCDB schema and check values are present and valid and check the name is unique, if it has changed. $this->validate($newValues, false, $scope->getName()); //Start transaction $this->em->getConnection()->beginTransaction(); // suspend auto-commit try { //set name $scope->setName($newValues['Name']); $scope->setDescription($newValues['Description']); $this->em->merge($scope); $this->em->flush(); $this->em->getConnection()->commit(); } catch (\Exception $e) { $this->em->getConnection()->rollback(); $this->em->close(); throw $e; } return $scope; }