/** * Edit a service type * @param \ServiceType $serviceType service type to be altered * @param array $newValues new values to be applied to the service type * @param \User $user user making the changes * @return \ServiceType the altered service type * @throws \Exception */ public function editServiceType(\ServiceType $serviceType, $newValues, \User $user = null) { //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. $this->validate($newValues); //check the name is unique, if it has changed if ($newValues['Name'] != $serviceType->getName()) { if (!$this->serviceTypeNameIsUnique($newValues['Name'])) { throw new \Exception("Service type names must be unique, '" . $newValues['Name'] . "' is already in use"); } } //Start transaction $this->em->getConnection()->beginTransaction(); // suspend auto-commit try { //set name $serviceType->setName($newValues['Name']); //set description $serviceType->setDescription($newValues['Description']); $this->em->merge($serviceType); $this->em->flush(); $this->em->getConnection()->commit(); } catch (\Exception $e) { $this->em->getConnection()->rollback(); $this->em->close(); throw $e; } return $serviceType; }
<?php require_once __DIR__ . "/../bootstrap.php"; require_once __DIR__ . "/AddUtils.php"; /* Loads a list of service types from an XML file and inserts them into * the doctrine prototype. * XML format is the PROM GOCDB PI output for get_service_type */ $stFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/ServiceTypes.xml"; $sts = simplexml_load_file($stFileName); foreach ($sts as $st) { $doctrineSt = new ServiceType(); $name = ""; $desc = ""; foreach ($st as $key => $value) { if ($key == "SERVICE_TYPE_NAME") { $name = (string) $value; } if ($key == "SERVICE_TYPE_DESC") { $desc = (string) $value; } } $doctrineSt->setName($name); $doctrineSt->setDescription($desc); $entityManager->persist($doctrineSt); } $entityManager->flush();