Exemplo n.º 1
0
 public function editEndpoint(\Service $service, \User $user, \EndpointLocation $endpoint, $newValues)
 {
     //Check the portal is not in read only mode, throws exception if it is
     $this->checkPortalIsNotReadOnlyOrUserIsAdmin($user);
     $name = $newValues['SERVICEENDPOINT']['NAME'];
     $url = $newValues['SERVICEENDPOINT']['URL'];
     if ($newValues['SERVICEENDPOINT']['INTERFACENAME'] != '') {
         $interfaceName = $newValues['SERVICEENDPOINT']['INTERFACENAME'];
     } else {
         $interfaceName = (string) $service->getServiceType();
     }
     $description = $newValues['SERVICEENDPOINT']['DESCRIPTION'];
     $this->validate($newValues['SERVICEENDPOINT'], 'endpoint');
     if (empty($name)) {
         throw new \Exception("An endpoint must have a name.");
     }
     if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
         throw new \Exception("An endpoint must have a valid url.");
     }
     // check endpoint's name is unique under the service
     foreach ($service->getEndpointLocations() as $endpointL) {
         // exclude itself
         if ($endpoint != $endpointL && $endpointL->getName() == $name) {
             throw new \Exception("Please provide a unique name for this endpoint.");
         }
     }
     $this->em->getConnection()->beginTransaction();
     try {
         // Set the endpoints new member variables
         $endpoint->setName($name);
         $endpoint->setUrl($url);
         $endpoint->setInterfaceName($interfaceName);
         $endpoint->setDescription($description);
         $this->em->merge($endpoint);
         $this->em->flush();
         $this->em->getConnection()->commit();
     } catch (\Exception $ex) {
         $this->em->getConnection()->rollback();
         $this->em->close();
         throw $ex;
     }
 }