예제 #1
0
파일: NGI.php 프로젝트: Tom-Byrne/gocdb
 /**
  * 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;
     }
 }
예제 #2
0
 public function deleteEndpoint(\EndpointLocation $endpoint, \User $user)
 {
     require_once __DIR__ . '/../DAOs/ServiceDAO.php';
     //Check the portal is not in read only mode, throws exception if it is
     $this->checkPortalIsNotReadOnlyOrUserIsAdmin($user);
     $service = $endpoint->getService();
     // check user has permission to edit endpoint's service
     $this->validateAddEditDeleteActions($user, $service);
     $this->em->getConnection()->beginTransaction();
     try {
         $serviceDAO = new \ServiceDAO();
         $serviceDAO->setEntityManager($this->em);
         $serviceDAO->removeEndpoint($endpoint);
         $this->em->flush();
         $this->em->getConnection()->commit();
     } catch (\Exception $e) {
         $this->em->getConnection()->rollback();
         $this->em->close();
         throw $e;
     }
 }
예제 #3
0
 /**
  * Delete both Services but not the ngi  
  * @see testRolesCascadeDelete_OnOwnedEntityDeletion1
  */
 public function testRolesCascadeDelete_OnOwnedEntityDeletion2()
 {
     print __METHOD__ . "\n";
     include __DIR__ . '/resources/sampleFixtureData1.php';
     $siteDAO = new SiteDAO();
     $serviceDAO = new ServiceDAO();
     $ngiDAO = new NGIDAO();
     $siteDAO->setEntityManager($this->em);
     $serviceDAO->setEntityManager($this->em);
     $ngiDAO->setEntityManager($this->em);
     // ordering of removal is NOT significant here !
     $serviceDAO->removeService($service1);
     $serviceDAO->removeService($service2);
     $siteDAO->removeSite($site1);
     $siteDAO->removeSite($site2);
     //$ngiDAO->removeNGI($ngi); // don't remove NGI
     $this->em->flush();
     // Need to clear the identity map (all objects become detached) so that
     // when we re-fetch the user, it will be looked from db not served by entity map
     $this->em->clear();
     // Need to re-fetch the user from the DB again, if don't, then user already
     // has his eargerly fetched roles present in UserProxy object
     $userWithRoles = $this->em->find("User", $userId);
     // user should have 2 remaining roles still from ngi
     $this->assertEquals(2, count($userWithRoles->getRoles()));
     $testConn = $this->getConnection();
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Roles");
     $this->assertTrue($result->getRowCount() == 2);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM NGIs");
     $this->assertTrue($result->getRowCount() == 1);
 }
 /**
  * Test the <code>$serviceDAO->removeEndpoint($endpoint)</code> method.   
  */
 public function testServiceDAORemoveEndpoint()
 {
     print __METHOD__ . "\n";
     // create a linked entity graph as beow:
     //
     //      se -----|    (1 service)
     //     / | \    |
     //  el1 el2 el3 |    (3 endpoints)
     //  |  \ | /    |
     // dt0  dt1 ----|    (1 downtime)
     $dt1 = new Downtime();
     $dt1->setDescription('downtime description');
     $dt1->setSeverity("WARNING");
     $dt1->setClassification("UNSCHEDULED");
     $dt0 = new Downtime();
     $dt0->setDescription('downtime description');
     $dt0->setSeverity("WARNING");
     $dt0->setClassification("UNSCHEDULED");
     $se = TestUtil::createSampleService('service1');
     $el1 = TestUtil::createSampleEndpointLocation();
     $el2 = TestUtil::createSampleEndpointLocation();
     $el3 = TestUtil::createSampleEndpointLocation();
     $se->addEndpointLocationDoJoin($el1);
     $se->addEndpointLocationDoJoin($el2);
     $se->addEndpointLocationDoJoin($el3);
     //$se->_addDowntime($dt1); // we don't call this in client code !
     $dt1->addEndpointLocation($el1);
     $dt1->addEndpointLocation($el2);
     $dt1->addEndpointLocation($el3);
     $dt1->addService($se);
     $dt0->addEndpointLocation($el1);
     //$dt0->addService($se); // note we don't add this relationship for purposes of the test
     // persist and flush
     $this->em->persist($se);
     $this->em->persist($el1);
     $this->em->persist($el2);
     $this->em->persist($el3);
     $this->em->persist($dt1);
     $this->em->persist($dt0);
     $this->em->flush();
     // create DAO to test
     $serviceDao = new ServiceDAO();
     $serviceDao->setEntityManager($this->em);
     // remove first endpoint causing dt0 to be orphaned
     $serviceDao->removeEndpoint($el1);
     $this->em->flush();
     // Assert expected object graph
     //     se -----|   (1 service)
     //      | \    |
     //     el2 el3 |   (2 endpoints)
     //      | /    |
     // dt0 dt1-----|   (2 downtime)
     //
     $testConn = $this->getConnection();
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM EndpointLocations");
     $this->assertTrue($result->getRowCount() == 2);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes");
     $this->assertTrue($result->getRowCount() == 2);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes_EndpointLocations");
     $this->assertTrue($result->getRowCount() == 2);
     // Assert expected object graph in ORM Mem
     $this->assertEquals(1, count($el2->getDowntimes()));
     $this->assertEquals(1, count($el3->getDowntimes()));
     $this->assertEquals(2, count($se->getEndpointLocations()));
     $this->assertEquals(1, count($se->getDowntimes()));
     $this->assertEquals(2, count($dt1->getEndpointLocations()));
     $this->assertEquals(1, count($dt1->getServices()));
     // remove another el
     $serviceDao->removeEndpoint($el2);
     $this->em->flush();
     // Assert expected object graph in DB
     //     se -----| (1 service)
     //       \     |
     //        el3  | (1 endpoints)
     //        /    |
     // dt0 dt1-----| (2 downtime)
     //
     $testConn = $this->getConnection();
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM EndpointLocations");
     $this->assertTrue($result->getRowCount() == 1);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes");
     $this->assertTrue($result->getRowCount() == 2);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes_EndpointLocations");
     $this->assertTrue($result->getRowCount() == 1);
     // Assert expected object graph in ORM Mem
     $this->assertEquals(1, count($el3->getDowntimes()));
     $this->assertEquals(1, count($se->getEndpointLocations()));
     $this->assertEquals(1, count($se->getDowntimes()));
     $this->assertEquals(1, count($dt1->getEndpointLocations()));
     $this->assertEquals(1, count($dt1->getServices()));
     // remove another el
     $serviceDao->removeEndpoint($el3);
     $this->em->flush();
     // Assert expected object graph in DB
     //     se -----| (1 service)
     //             |
     //             | (1 endpoints)
     //             |
     // dt0 dt1-----| (2 downtime)
     //
     $testConn = $this->getConnection();
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM EndpointLocations");
     $this->assertTrue($result->getRowCount() == 0);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes");
     $this->assertTrue($result->getRowCount() == 2);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes_EndpointLocations");
     $this->assertTrue($result->getRowCount() == 0);
     // Assert expected object graph in ORM Mem
     $this->assertEquals(0, count($se->getEndpointLocations()));
     $this->assertEquals(1, count($se->getDowntimes()));
     $this->assertEquals(0, count($dt1->getEndpointLocations()));
     $this->assertEquals(1, count($dt1->getServices()));
 }
예제 #5
0
$type = null;
$id = null;
$site = null;
$facebookPage = null;
$plusPage = null;
$photo = null;
$price = null;
$placeId = null;
$placeApiId = null;
if (isset($_GET['servico'])) {
    $servico = $_GET['servico'];
}
ob_start();
include_once "ServiceDAO.php";
ob_end_clean();
$serviceDAO = new ServiceDAO();
// Insert Place
if (!strcmp($servico, "insertPlace")) {
    if (isset($_POST['name'])) {
        $name = $_POST['name'];
    }
    if (isset($_POST['description'])) {
        $description = $_POST['description'];
    }
    if (isset($_POST['address'])) {
        $address = $_POST['address'];
    }
    if (isset($_POST['lat'])) {
        $lat = $_POST['lat'];
    }
    if (isset($_POST['lng'])) {
예제 #6
0
 /**
  * Test the ServiceDAO->removeService(); 
  * Impt: A cascade=remove is configured between Service and EndpointLocation 
  * so that when a Service is removed, its associated ELs are also removed. 
  * <p>
  * Note, no cascade remove behaviour is configured between EndpointLocation and 
  * Downtime because we need to have fine-grained programmatic control over 
  * which downtimes are deleted when a service EL is deleted (i.e. we only 
  * want to delete those DTs that exclusively link to one EL only and which 
  * would subsequently be orphaned). We do this managed deletion of DTs in ServiceDAO->removeService();  
  */
 public function testServiceDAO_removeService()
 {
     print __METHOD__ . "\n";
     include __DIR__ . '/resources/sampleFixtureData1.php';
     // Impt: When deleting a service, we can't rely solely on the
     // 'onDelete=cascade' defined on the 'EndpointLocation->service'
     // to correctly cascade-delete the EL. This is because downtimes can also be linked
     // to the EL.  Therefore, if we don't invoke an $em->remove() on the EL
     // (either via cascade="remove" or manually invoking em->remove() on each EL),
     // Doctrine will not have flagged the EL as removed and so will not automatically delete the
     // relevant row(s) in 'DOWNTIMES_ENDPOINTLOCATIONS' join table.
     // This would cause a FK integrity/violation constraint exception
     // on the 'DOWNTIMES_ENDPOINTLOCATIONS.ENDPOINTLOCATION_ID' FK column.
     // This is why we need to do a managed delete using the ServiceDAO
     $serviceDao = new ServiceDAO();
     $serviceDao->setEntityManager($this->em);
     $serviceDao->removeService($service1);
     $this->em->flush();
     // use DB connection to check data has been deleted
     $con = $this->getConnection();
     $result = $con->createQueryTable('results_table', "SELECT * FROM EndpointLocations");
     $this->assertTrue($result->getRowCount() == 0);
     $result = $con->createQueryTable('results_table', "SELECT * FROM Downtimes");
     $this->assertTrue($result->getRowCount() == 0);
 }