/** * Delete the given NGI and cascade delete all of the NGI's child entities. * These include Sites, Services, EndpointLocations, Downtimes that will be * orphaned, CertificationStatusLogs and Roles that previously linked to the * deleted owned entities. * * @param \NGI $ngi * @param \User $user - must be an admin user * @param boolean $logNgiSiteServiceInArchives Record the deletion of the ngi, * its child sites and services in the archive tables. * @throws \org\gocdb\services\Exception */ public function deleteNgi(\NGI $ngi, \User $user = null, $logNgiSiteServiceInArchives = true) { require_once __DIR__ . '/../DAOs/SiteDAO.php'; require_once __DIR__ . '/../DAOs/ServiceDAO.php'; require_once __DIR__ . '/../DAOs/NGIDAO.php'; require_once __DIR__ . '/ServiceService.php'; //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); $this->em->getConnection()->beginTransaction(); try { $ngiDAO = new \NGIDAO(); $ngiDAO->setEntityManager($this->em); $siteDAO = new \SiteDAO(); $siteDAO->setEntityManager($this->em); $serviceDAO = new \ServiceDAO(); $serviceDAO->setEntityManager($this->em); //Archive ngi if ($logNgiSiteServiceInArchives) { $ngiDAO->addNGIToArchive($ngi, $user); } //delete each child site foreach ($ngi->getSites() as $site) { //Archive site if ($logNgiSiteServiceInArchives) { $siteDAO->addSiteToArchive($site, $user); } //delete each child service foreach ($site->getServices() as $service) { //archive the srvice if ($logNgiSiteServiceInArchives) { $serviceDAO->addServiceToArchive($service, $user); } //remove the service (and any downtimes only associated with it) $serviceDAO->removeService($service); } //remove the site $siteDAO->removeSite($site); } //remove the NGI $ngiDAO->removeNGI($ngi); $this->em->flush(); $this->em->getConnection()->commit(); } catch (\Exception $e) { $this->em->getConnection()->rollback(); $this->em->close(); throw $e; } }
/** * Deletes a service * @param \Service $s To be deleted * @param \User $user Making the request * @param $isTest when unit testing this allows for true to be supplied and this method * will not attempt to archive the service which can easily cause errors for service objects without * a full set of information * @throws \Exception If user can't be authorized */ public function deleteService(\Service $s, \User $user = null, $isTest = false) { require_once __DIR__ . '/../DAOs/ServiceDAO.php'; //Check the portal is not in read only mode, throws exception if it is $this->checkPortalIsNotReadOnlyOrUserIsAdmin($user); //$this->editAuthorization($se, $user); if (count($this->authorizeAction(\Action::EDIT_OBJECT, $s, $user)) == 0) { throw new \Exception("You do not have permission to remove" . $s->getHostName()); } $this->em->getConnection()->beginTransaction(); try { $serviceDAO = new \ServiceDAO(); $serviceDAO->setEntityManager($this->em); //Archive site - if this is a test then don't archive if ($isTest == false) { //Create entry in audit table $serviceDAO->addServiceToArchive($s, $user); } //Break links with downtimes and remove downtimes only associated //with this service, then remove service $serviceDAO->removeService($s); $this->em->flush(); $this->em->getConnection()->commit(); } catch (\Exception $e) { $this->em->getConnection()->rollback(); $this->em->close(); throw $e; } }