Пример #1
0
 /**
  * Deletes a downtime
  * @param \Downtime $dt
  * @param \User $user
  */
 public function deleteDowntime(\Downtime $dt, \User $user = null)
 {
     //Check the portal is not in read only mode, throws exception if it is
     $this->checkPortalIsNotReadOnlyOrUserIsAdmin($user);
     $ses = $dt->getServices();
     $this->authorization($ses, $user);
     if ($dt->hasStarted()) {
         throw new \Exception("This downtime has already started.");
     }
     $this->em->getConnection()->beginTransaction();
     try {
         //For MEPS we need to delete from both service and enpoints
         foreach ($dt->getServices() as $se) {
             // Downtime is the owning side so remove elements from downtime.
             $dt->removeService($se);
             // unlinks on both sides
             //$dt->getServices()->removeElement($se); //unlinking
             //$se->getDowntimes()->removeElement($dt);
         }
         foreach ($dt->getEndpointLocations() as $ep) {
             // Downtime is the owning side so remove elements from downtime.
             $dt->getEndpointLocations()->removeElement($ep);
             //unlinking
             // Since Doctrine always only looks at the owning side of a
             // bidirectional association for updates, it is not necessary for
             // write operations that an inverse collection of a bidirectional
             // one-to-many or many-to-many association is updated. This
             // knowledge can often be used to improve performance by avoiding
             // the loading of the inverse collection.
             //$ep->getDowntimes()->removeElement($dt);
         }
         $this->em->remove($dt);
         $this->em->flush();
         $this->em->getConnection()->commit();
     } catch (\Exception $e) {
         $this->em->getConnection()->rollback();
         $this->em->close();
         throw $e;
     }
 }