Beispiel #1
0
 /**
  * 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;
     }
 }